DeRe Atari

Download as pdf or txt
Download as pdf or txt
You are on page 1of 246

anno 18omb,« .

TO EFFECTIVE PROGRAMM.ING

Distributed By

The ATARI Program Exchange P.O. Box 3705

Santa Clara. CA 95055

To request an APX Product Catalog, write to the address above. or call toll-free: 800/538-1862 (outside California)

800/672-1850 (within California)

Or call our Sales number. 408/727-5603

Trademarks of Atari

The following are trademarks of Atari, Inc.

ATARI®

ATARI 400T. Home Computer ATARI 8ooT• Home Computer ATARI 410" Program Recorder ATARI 810" Disk Drive

ATARI 820T·40-Column Printer ATARI 822" Thermal Printer ATARI 825" 80-Column Printer ATARI 830" Acoustic Modem ATARI 850" Interface Module

Printed in U.S.A.

© 1982 Atari, Inc.

PREFACE

1

2

3

4

5

6

CONTENTS

SYSTEM OVERVIEW

ANTIC AND THE DISPLAY LIST

Television Displays

Computers and Televisions ANTIC, a Video Microprocessor Building Display Lists

Writing to a Custom Display List Screen Applications of Display Lists

GRAPHICS INDIRECTION (COLOR REGISTERS AND CHARACTER SETS)

Color Registers Character Sets

Applications of Character Sets

PLAYER-MISSILE GRAPHICS

Difficulties with High-Speed Animation Player-Missile Fundamentals

Vertical Motion

Horizontal Motion

Other Player-Missile Features Missiles

Player and P1ayfield Priorities Hardware Collision Detection Applications of Player-Missile Graphics Special Characters

DISPLAY LIST INTERRUPTS

Theory of Operation DLI Timing

DLI Example

Attract Mode

Detailed Timing Considerations Multiple DLls

Kernels

Applications of Display List Interrupts

SCROLLING

Horizontal Scrolling

Fine Scrolling Applications of scrolling

2-1 2-2 2-3 2-6 2-8 2-9

3-1 3-4 3-5

4-1 4-3 4-3 4-4 4-4 4-5 4-6 4-6 4-9 4-11

5-1 5-2 5-3 5-4 5-4 5-6 5-7 5-8

6-2 6-5 6-8

7

SOUND

Definition of Terms and Conventions Sound Hardware

AUDFl-4

AUDCl-4

Volume

Distortion

AUDCTL

16-Bit Frequency Options High-Pass filters

9-Bit Polynomial Conversion

7-1 7-2 7-2 7-3 7-3 7-3 7-9 7-10 7-12 7-13

SOUND GENERATION SOFTWARE TECHNIQUES

7-14

Static Sound Dynamic Sound BASIC Sound 60-Hz Interrupt

Machine-Code Sound Generation Volume Only Sound

7-14 7-16 7-16 7-18 7-19 7-21

8

OPERATING SYSTEM

Introduction

The Monitor Memory Management

Interrupt Processing Structure System Vectors

The Centralized Input/Output Subsystem Real-Time Programming

Floating Point Package

8-1 8-3 8-8 8-12 8-20 8-22 8-38 8-45

9

THE DISK OPERATING SYSTEM

The Resident Disk Handler File Management System Disk Utility Package Random Access

FMS Disk Utilization AUTORUN. SYS Fi le

9-1 9-3 9-6 9-11 9-13 9-17

10

APPENDICES

A

B

C

D

E

GLOSSARY

ATARI BASIC OVERVIEW

What Is ATARI BASIC?

How ATARI BASIC Works The Tokenizing Process The Token File Structure

The Program Execution Process System Interaction

Improving Program Performance Advanced Programming Techniques

10-1 10-2 10-3 10-8 10-11 10-13 10-15 10-18

MEMORY UTILIZATION

HUMAN ENGINEERING

ATARI CASSETTE OVERVIEW

TELEVISION ARTIFACTS

GTIA

1-1

1-2

2-1

3-1

3-2

3-3

3-4

3-5

4-1

4-2

4-3

4-4

5-1

6-1

6-2

7-1

7-2

7-3

7-4

7-5

7-6

7-7

7-8

ILLUSTRATIONS

Coarse Memory Map for ATARI 400/800

ATARI 400/800 Hardware Layout

ANTIC Mode Line Requirements

Color Register Labels and Addresses

Character Encoding

Color Register Selection for Characters

TM

ENERGY CZAR Bar Charts

Terrain Map With Character Set Graphics

Non contiguous RAM Images

Player-Missile RAM Area Layout

Masking a Player for More Resolution

Using a Player as a Special Character

Examples of Vertical Screen Architecture

Arranging Screen RAM

Linking the Scroll to Coarse Scroll

Diagram of Bit flow of a Shift Register

Divide by Four Diagram

AUDCI-4 Bit Assignment

Five-Bit Poly-Counter

Selection Type Function Used to Mix 1n Distortion

Available Poly-Counter Combinations

AUDCI-4 Block Diagram

Sounds Produced by Distortion Combinations at Several Frequencies

7-9 AUDCTL Bit Assignment

Illustration (Cont')

7-10

7-11

7-12

7-13

7-14

7-15

8-1

8-2

8-3

8-4

8-5

8-6

8-7

8-8

8-9

8-10

8-11

8-12

8-13

8-14

8-15

8-16

8-17

8-18

8-19

The Effect of a High-Pass Filter Inserted in Channell and Clocked by Channel 3

Two Sine Waves at Different Frequencies and Their Sum

Music Notes Played on a Standard Music Routine

Graphed Table of Frequencies That possible Duplicate a Piano Key

Example of the Three Notes of Fig. 10-10 Played With a Piano Envelope

Graphed Sine Wave Data for Volume Only Program

I/O Subsystem

OS and BASIC Pointers (DOS Present)

RESET MEMLO

Protecting Programs from User Input Error

Vertical Blank Interrupt Execution

ROM Jump Vectors

RAM Vectors

I/O Subsystem

Input/Output Control Block (IOCB)

Device Control Block (DCB)

CIO Routine

Handler Address Table (HATABS)

Printer Handler Entry Point Table

Null Handler

SIO Call to Dump Line to Printer

BASIC Direct CIO Call

Real-Time Clock

BASIC Language Metronome Clock

Assembly Language Metronome Routine

Illustration (Cont')

8-20

Floating Point Routines

9-1

Auxiliary Byte Layout for the OPEN Command

9-2

Note and Point Values

9-3

Note and Point Example

10-1

Example Line of Tokenized Input

10-2

OS and BASIC Pointers (No DOS Present)

C-1

Daisychained Peripheral Equipment

C-2

E-l Bit Pattern In PRIOR Selects GTIA

E-2 Background Color Register ORed With Pixel Data to Give Data Color

E-3 Background Color REgister ORed With Pixel To Give Final Color

E-4

Color Register Numbers and Location and COLOR Command Reference

)

PREFACE

This manual is about the ATARI Home Computer. It covers both the ATARI

400'" and the ATARI 800'" Computers. These two computers are electrically i dent i ca I, differ i ng on I yin mechan i ca I features such as the keyboards and cartridge slots. The purpose of this manual is to explain in detai I how to use a II the features of the ATAR I Computer. Because th is is a comp I ex and powerful machine, the explanations are accordingly rather long. Furthermore, they demand some expert I se on the part of the reader. Th i s book is not intended for the beginning programmer. The reader should be thoroughly fami I iar with the BASIC Reference Manual, which is provided with the computer. Fami I iarity with assembly language is also essential. A glossary in the back def i nes and exp I a ins some of the I ess common I y encountered jargon. However, this glossary does not include terms that every serious personal computer programmer should already know.

Written as a training manual for professional programmers who use the ATARI Home Computer, this book may be modified for general use at some later date. It does not supplant the technical reference manual (ATARI part number C016555), wh i ch is a reference for programmers who a I ready understand the system. Th i s book is i nten ded to be a tutor i a I that exp I a ins ideas and possibi I ities rather than defining registers and control codes.

') The title, DE RE ATARI, is pronounced "Day Ray Atar l ", It is an obscure " I iterary reference. Some Latin manuscripts in Roman and medieval times were entitled "De Re This" or "De Re That". Thus, "De Re Rustica" was a poem on farming and "De Re Metailica" described metallurgy. Loosely translated, "De Re" means "AI I About".

Most of the word process i ng for the book was carr i ed out with Atar i computers. A source file ed I tor was used for text ed It i ng, and a mod i f i ed version of FORMS (aval lable from the Atari Program Exchange) was used to format and print the text. A letter-qual ity printer was used for output. Some sections were developed with a conventional word processor.

The Software Development Support Group wrote this book. Chris Crawford wrote Sections 1 through 6 and Appendices A and B. Lane Winner wrote Section 10 and Appendix 0 with assistance from Jim Cox. Amy Chen wrote Appendix C. Jim Dunion wrote Sections 8 and 9. Kathleen Pitta wrote Appendix E. Bob Fraser wrote Section 7. Gus Makreas prepared the Glossary. The final result has many flaws, but we are proud of it.

1

SYSTEM OVERVIEW

The ATARI Home Computer is a second-generation personal computer. First and foremost, it is a consumer computer. The thrust of the design is to make the consumer comfortable with the computer. This consumer orientation manifests itself in many ways. First, the machine is proofed against consumer mistakes by such things as polarized connectors that will not go in the wrong way, a power interlock on the I id to the internal electronics, and a pa i r of pi ast i c sh ie I ds protect i ng the SYSTEM RESET key. Second, the machine has a great deal of graphics power; people respond to pictures much more readi Iy than to text. Third, the machine has strong sound capabi I ities. Again, people respond to direct sensory input better than to indirect textual messages. F i na I I y, the computer has joyst i cks and padd I es for more direct tact i lei nput than is poss i b lew i th keyboards. The po i nt here is not that the computer has lots of features but rather that the features are al I part of a consistent design phi losophy aimed directly at the consumer. The designer who does not appreciate this fundamental fact will find himself working against the grain of the system.

The internal layout of the ATARI 400/800'" Computer is very different from other systems. It of course has a microprocessor (a 6502), RA~1, ROM, and a (PIA). However, it also has three special-purpose (LSI) chips known as ANTIC, CTIA, and POKEY. These chips were designed by Atari engineers primari Iy to take much of the burden of housekeeping off of the 6502, thereby freeing the 6502 to concentrate on computations. Whi Ie they were at it, they des i gned a great dea I of power into these ch ips. Each of these ch ips is a I most as big (i n terms of s iii con area) as a 6502, so the three of them together prov i de a tremendous amount of power. Master i ng the ATAR I 400/800 Computers is primari Iy a matter of mastering these three chips.

)

/

ANTIC is a microprocessor dedicated to the television display. It is a

true microprocessor; it has an instruction set, a program (cal led the display I t s+ ) , and data. The display I ist and the display data are written into RAM

by the 6502. ANTIC retrieves this information from RAM using direct memory

access (DMA). It processes the higher level instructions in the display list

and translates these instructions into a real-time stream of simpl€ instructions to CTIA.

.

CTIA is a television interface chip. ANTIC directly controls most of

CTIA's operations, but the 6502 can be programmed to intercede and control some or all of CTIA's functions. CTIA converts the digital commands from ANTIC (or the 6502) into the signal that goes to the television. CTIA also adds some factors of its own, such as color values, player-missile graphics, and col I ision detection.

POKEY is a digital input/output (I/O) chip. It handles such disparate

tasks as the serial I/O bus, audio generation, keyboard scan, and random number generation. It also digitizes the resistive paddle inputs and controls maskable interrupt (IRQ) requests from peripherals.

AI I four of these LSI chips function simultaneously. Careful separation of their functions in the design phase has minimized confl icts between the

1-1

SYSTEM OVERVIEW

chips. The only hardware level confl ict between any two chips in the system occurs when ANTI C needs to use the address and data buses to fetch its display information. To do this, it halts the 6502 and takes control of the buses.

As with al I 6502 systems, the I/O is memory-mapped. Figure 1-1 presents

the coarse memory map for the computer. Figure 1-2 shows the hardware

arrangement.

With no DOS With DOS 2.0S
operating System RAM 0000 operating System RAM
-
1000
DOS 2.0S
2000
3000
Free 4000 Free
RAM RAM
Space 5000 Space
6000
7000
8000
9000
AOOO

BASIC or other BOOO BASIC or other
8K cartridge 8K cartridge
COOO
unallocated unallocated
0000
hardware 1/0 hardware 1/0
EOOO
operating System FOOO operating System
ROM ROM
FFFF 1-2

SJaIlOJIUO~ PJeoq~a)l

SYSTEM OVERVIEW

> W :.::: o 11.

S8LjOIlMS 810SUO~

o ~ Z e(

1-'

::1:1-

"a: _e(

a:O

1-"': u..a:

We( ...10

III :I .c

~

III II)

e

11.

1-3

(I):::E 00 a:

o o CO

-

o

o III:t

a:

~

)

2

ANTIC AND THE DISPLAY LIST

TELEVISION DISPLAYS

To understand the graphics capabilities of the ATARI Home Computer, one must first understand the rudiments of how a television set works. Television sets use what is cal led a raster scan display system. An electron beam I s generated at the rear of the te I ev I s Ion tube and shot toward the te I ev i s Ion screen. A long the way, I t passes between sets of hor I zonta I and vert i ca I co II s wh I ch , If energ I zed, can def I ect the beam. In th I s way the beam can be made to str i ke any po i nt on the screen. The electron I cs Ins ide the television set cause the beam to sweep across the television screen in a regular fashion. The beam's Intensity can also be controlled. If you make the beam more intense, the spot I n the screen that it str I kes w II I g low brightly; If you make it less intense, the spot will glow dimly or not at a I I •

The beam starts at the top-I eft corner of the screen and traces hor I zonta I I Y across the screen. As I t sweeps across the screen, I ts changes in intensity paint an image on the screen. When it reaches the right edge of the screen, it Is turned off and brought back to the left side of the screen. At the same time it Is moved down just a notch. It then turns back on and sweeps across the screen again. This process Is repeated for a total of 262 sweeps across the screen. (There are actua I I Y 525 sweeps across the screen in an alternating system known as "interlace." We will Ignore Interlace and act as if the television has only 262 lines.) These 262 lines fill the screen from top to bottom. At the bottom of the screen (after the 262nd line I s drawn), the electron beam I s turned off and returned to the upper I eft corner of the screen. Then It starts the cycle al lover again. This entire cycle happens 60 times every second.

Now for some jargon: a single trace of the beam across the screen is called a "horizontal scan I l ne ;" A horizontal scan line Is the fundamental unit of measurement of vertical distance on the screen. You state the height of an image by specifying the number of horizontal scan I Ines It spans. The period during which the beam returns from the right edge to the left edge Is called the "horizontal blank." The period during which the beam returns to the top of the screen is cal led the "vertical blank." The entire process of drawing a screen takes 16,684 microseconds. The vertical blank period Is about 1400 microseconds. The hor I zonta I blank takes 14 microseconds. A single horizontal line takes 64 microseconds.

Most television sets are designed with "overscan"; that means they spread the Image out so the picture edges are off the edge of the television tube. This guarantees that you have no unsightly borders In your television picture. It Is very bad for computers, though, because screen Information that I s off the edge of the picture does you no good. For th I s reason the picture that the computer puts out must be somewhat smaller than the te lev i s Ion can theoret i ca I I Y d I sp I ay. Therefore, on I y 192 hor I zonta I scan lines are normally used by the ATARI display. Thus, the normal limit of resolution of a television set used with this computer Is 192 pixels vert I ca I I Y •

2-1

ANTIC AND THE DISPLAY LIST

The standard unit of horizontal distance is the "color clock." You

specify the width of an image by stating how many color clocks wide it is. There are 228 color clocks in a single horizontal scan line, of which a maximum of 176 are actually visible. Thus, the ultimate I imit for full-color horizontal resolution with a standard color television is 176 pixels. It Is possible with the ATARI Home Computer System to go even finer and control individual half-clocks. This gives a horizontal resolution of 352 pixels. However, use of this feature wi I I produce interesting color effects known as color artifacts. Color artifacts can be a nuisance if they are not desired; they can be a boon to the programmer who desires additional color and is not fazed by their restrictions.

COMPUTERS AND TELEVISIONS

The fundamental problem any microcomputer has in using a raster scan television for display purposes is that the television display is a dynamic process; because of this, the television does not remember the image. Consequently, the computer must remember the screen image and constantly send a signa I to the te I ev lsi on te I ling I t what to d i sp I ay. Th i s process of sending Information to the television is a continuous process and it requires ful I-time attention. For this reason most microcomputers have special hardware circuits that handle the television. The basic arrangement is the same on virtually al I systems:

mlcroprocessor--->screen RAM--->video hardware--->TV screen

The microprocessor wr i tes in format Ion to the screen RAM area that ho I ds the screen data. The v I deo hardware is constant I y d i pp i ng into th is RAM area, gett i ng screen data that it converts into te I ev lsi on signa Is. These signa Is go to the te I ev lsi on wh i ch then d i sp I ays the in format ion. The screen memory is mapped onto the screen in the same order that it fol lows in RAM. That is, the first byte in the screen memory maps to the top-I eft corner of the screen, the second byte maps one pos it i on to the right, then the th i rd, the fourth, and so on to the last byte which is mapped to the lower right corner of the screen.

The qual ity of the image that gets to the screen depends on'two factors: the qua I I ty of the video hardware, and the quant i ty of screen RAM used for the display. The simplest arrangement is that used by TRS-80 and PET. CTRS-80 is a trademark of Rad i 0 Shack Co; PET is a trademark of Commodore Business Machines.) Both of these machines al locate a specific 1K of RAM as screen memory. The video hardware c i rcu its simp I y pu I I data out of th is area, interpret it as characters (using a character set in ROM), and put the resu I ti ng characters onto the screen. Each byte represents one character, al lowing a choice of 256 different characters in the character set. With 1K of screen RAM, one thousand characters can be displayed on the screen. There i sn t+ much that can be done with th is arrangement. The App I e uses more advanced video hardware. (Apple is a trademark of Apple Compu+er s , ) Three graph i cs modes are prov i ded: text, I o-reso I ut i on graph i cs, and hi -reso I ut ion graphics. The text graphics mode operates in much the same way that the PET and TRS-80 displays operate. In the low-resolution graphics mode, the video

2-2

ANTIC AND THE DISPLAY LIST

')

j

hardware reaches into screen memory and interprets it different I y. Instead of interpreting each byte as a character, each byte is interpreted as a pair of color nybbles. The value of each nybble specifies the color of a single pixel. In the high-resolution graphics mode each bit in screen memory is mapped to a single pixel. If the bit is on, the pixel gets color in it; if the bit is off, the pixel stays dark. The situation is compl icated by a variety of design nuances in the Apple, but that is the basic idea. The important idea is that the Apple has three display modes; three completely d i f ferent ways of interpret i ng the data in screen memory. The App I e video hardware is smart enough to interpret a screen memory byte as either an 8-bit character (text mode), two 4-bit color nybbles (Io-resolution mode), or 7 individual bits for a bit map (hi-resolution mode).

ANTIC, A VIDEO MICROPROCESSOR

The ATARI 400/800 display I ist system represents a general ization of these systems. Where PET and TRS-80 have one mode and Apple has three modes, the ATAR I 400/800 has 14 modes. The second important d I f ferencei s that display modes can be mixed on the screen. That is, the user is not restricted to a choice between a screenful of text or a screenful of graphics. Any collection of the 14 graphics modes can be displayed on the screen. The th i rd important d i f ference is that the screen RAM can be located anywhere in the address space of the computer and moved around wh i I e the program is running, whi Ie the other machines use fixed-screeri RAM areas.

AI I of this general ity is made possible by a video microprocessor cal led ANTIC. Where the earl ier systems used rather simple video circuitry, Atari designed a full-scale microprocessor just to handle the intricacies of the television display. ANTIC is a true microprocessor; it has an instruction set, a program, and data. The program for ANTI Cis ca I I ed the d I sp I ay list. The display I ist specifies three things: where the screen data may be found, what display modes to use to interpret the screen data, and what special display options (1f any) should be implemented. When using the display list, it is important to shed the old view of a screen as a homogeneous image in a sing I e mode and see it instead as a stack of "mode lines." A mode line is a co I I ect i on of hor i zonta I scan lines. It streches hor i zonta I I Y ; a I I the way across the screen. A Graphics 2 mode I ine is 16 horizontal scan I ines high, whi Ie a Graphics 7 mode I ine is only two scan I ines high. ~1any graphics modes avai lable from BASIC are homogeneous; an entire screen of a single mode is set up. Do not I imit your imagination to this pattern; with the display list you can create any sequence of mode lines down the screen. The d i sp I ay I ist is a collection of code bytes that specify that sequence.

ANTIC'S instruction set is rather simple. There are four classes of

instructions: map mode, character mode, blank line, and jump. Map mode instructions cause ANTIC to display a mode line with simple colored pixels (no characters). Character mode instructions cause ANTIC to display a mode I ine with characters in it. Blank I ine instructions cause ANTIC to display a

number of horizontal scan I ines with sol id background color. Jump instructions are analogous to a 6502 JMP instruction; they reload ANTIC's program counter.

2-3

ANTIC AND THE DISPLAY LIST

There are also four special options that can sometimes be specified by setting a designated bit In the ANTIC Instruction. These options are: display list Interrupt <DLI), load memory scan (LMS), vertical scroll, and horizontal scrol I •

Map mode I nstruct Ions cause ANTI C to d I sp I ay a mode I I ne conta in i ng pixels with solid color in them. The color displayed comes from a color register. The choice of color register is specified by the value of the screen data. In four-color map modes (BASIC modes 3, 5, and 7, and ANTIC modes 8, A, D, and E), a pair of bits Is required to specify a color:

Value of Bit Pair

Color Register Used

00 0 01 1 10 2 11 3

COLBAK COLPFO COLPF1 COLPF2

Since only two bits are needed to specify one pixel, 4 pixels are encoded in each screen data byte. For examp Ie, a byte of screen data conta In i ng the value $1B would display 4 pixels; the first would be the background, the second wou I d be co I or reg I ster 0, the th I rd wou I d be co I or reg i ster 1, and the fourth would be color register 2:

$1 B = 00011011 = 00 01 10 11

In two-color map modes (BASIC modes 4, 6, and 8, and ANTIC modes 9, B, C, and F) each bit specifies one of two color registers. A bit value of 0 selects backgtound color for the pixel and a bit value of 1 selects color register 0 for the pixel. Eight pixels can be stored In one screen data byte.

There are eight different map display modes. They differ in the number of colors they display (2 vs 4), the vertical size one mode I ine occupies (1 scan line, 2, 4, or 8), and the number of pixels that fit horJzontally into one mode I I ne (40, 80, 160, or 320). Thus, some map modes give better resolution; these will of course require more screen RAM. Figure 2-1 presents this Information for al I modes.

2-4

ANTIC AND THE DISPLAY LIST

ANTIC BASIC No. Scan Lines/ Pixels/ Bytes/ Bytes/
Mode Mode Colors Mode LI ne ~40de Line Line Screen
2 0 2 8 40 40 960
3 none 2 10 40 40 760
4 none 4 8 40 40 960
5 none 4 16 40 40 480
6 1 5 8 20 20 480
7 2 5 16 20 20 240
8 3 4 8 40 10 240
9 4 2 4 80 10 480
A 5 4 4 80 20 960
B 6 2 2 160 20 1920
C none 2 1 160 20 3840
D 7 4 2 160 40 3840
E none 4 1 160 40 7680
F 8 2 1 320 40 7680
Figure 2-1 ANTIC Mode Line Requirements Character mode instructions cause ANTIC to display a mode line with characters In it. Each byte I n screen RAM spec I f I es one character. There are six character display modes. Character displays are discussed ln Section 3.

Blank line instructions produce blank I ines with solid background color.

There are eight blank line Instructions; they specify skipping one through eight blank lines.

There are two jump instructions. The first (JMP) is a direct jump; It reloads ANTIC's program counter with a new address that follows the J~1P instruction as an operand. Its only function is to provide a solution to a tricky problem: ANTIC's program counter has only 10 bits of counter and six bits of latch and so the display I ist cannot cross a 1K boundary. If the display I ist must cross a 1K boundary then it must use a JMP instruction to hop over the boundary. Note that this means that display I ists are not fully relocatable.

The second jump instruction (JVB) is more commonly used. It reloads the

program counter with the value in the operand and waits for the television to perform a vert i ca I blank. Th is instruct i on is norma II y used to term i nate a display I ist by jumping back up to the top of the display I ist. Jumping up to the top of the display I ist turns it into an infinite loop; waiting for vert I ca I blank ensu res that the in fin i te loop is synchron i zed to the d i sp I ay cycle of the television. Both JMP and JVB are 3-byte instructions; the first byte is the opcode, the second and th i rd bytes are the address to jump to ( low then hi g h) •

The four spec i a I opt ions ment i oned prev i ous I Y wi I I be discussed in

2-5

ANTIC AND THE DISPLAY LIST

Sectlons 5 and 6. The load memory scan CLMS) option must have a prel iminary explanation. This option is selected by setting bit 6 of a map mode or a character mode instruction byte. When ANTIC encounters such an Instruction, It w I I I load I ts memory scan counter with the fo I low i ng 2 bytes. Th is memory scan counter te I I sANTI C where the screen RAM is. It wi I I beg i n fetch i ng display data from this area. The LMS Instruction is a 3-byte instruction: 1 byte opcode followed by 2 bytes of operand. In simple display lists the LMS instruction Is used only once, at the beginning of the display I ist. It may sometimes be necessary to use a second LMS instruction. The need arises when the screen RAM area crosses a 4K boundary. The memory scan counter has only 12 bits of counter and 4 bits of latch; thus, the display data cannot cross a 4K boundary. In this case an LMS instruction must be used to jump the memory scan counter over the boundary. Note that th is means that d i sp I ay data is not fully relocatable. LMS instructions have wider uses which will be discussed later.

BUILDING DISPLAY LISTS

Every display list should start off with three "blank 8 lines" instructions. This Is to defeat vertical overscan by bringing the beginning of the display 24 scan I ines down. After this is done, the first display line should be specified. Simultaneously, the LMS should be used to tell ANTIC where It wi II find the screen RAM. Then follows the display list proper, wh i ch I I sts the d I sp I ay bytes for the mode I I nes on the screen. The total number of horizontal scan lines produced by the display I ist should always be 192 or less; ANTIC does not maintain the screen timing requirements of the television. If you give ANTIC too many scan lines to display it will do so, but the television screen will probably roll. Displaying fewer than 192 scan I I nes wi I I cause no prob I ems; indeed, it wi I I decrease 6502 execution time by reducing the number of cycles stolen by ANTIC. The programmer must ca I cu I ate the sum of the hor I zonta I scan lines produced, by the display list and verify it. The display list terminates with a JVB Instruction. Here Is a typical display I ist for a standard BASIC Graphics mode 0 display Cal I values are in hexadecimal):

2-6

ANTIC AND THE DISPLAY LIST

70 Blank 8 lines 70 Blank 8 lines 70 Blank 8 lines

42 Display ANTIC mode 2 (BASIC mode 0) 20 Also, screen memory starts at 7C20 7C

02 Display ANTIC mode 2 02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

02

41 Jump and wait for vertical blank

EO to display I ist which starts at 7B $7BEO

As you can see, th is d i sp I ay list is short---on I y 32 bytes. display I ists are less than 100 bytes long. Furthermore, they are simple In structure and easy to set up.

Most quite

To implement your own display I ist, you must first design the display format. This is best done on paper. Layout the screen image and translate it into a sequence of mode I ines. Keep track of the scan I ine count of your d i sp I ay by look i ng up the scan line requ i rements of the var i ous modes in Figure 2-1. Translate the sequence of mode I ines into a sequence of ANTIC mode bytes. Put three "b lank 8 lines" bytes ($70) at the top of the list. Set bit 6 of the first display byte (that is, make the upper nybble a 4). Th I s makes a load memory scan command. Fo I low with 2 bytes wh i ch spec i fy the address of the screen RAM (low then high). Then fol low with the rest of the display bytes. At the end of your display I ist put in the JVB instruction ($41) and the address of the top of the display I ist. Now store a I I of these bytes into RAtvl. They can be anywhere you want; just make sure they don 't over I ay someth i ng else and your JVB po i nts to the top of the

2-7

ANTIC AND THE DISPLAY LIST

display I ist. The display I ist must not cross a lK address boundary. If you absolutely must have it cross such a boundary, insert aJMP instruction just in front of the boundary. The JMP instruction's operand is the address of the first byte on the other side of the boundary. Next you must turn off ANTIC for a fraction of a second whi Ie you rewrite its display I ist pointer. Do this by writing a 0 into SDMCTL at location $22F. Then store the address of the new display list into $230 and $231 (low then high). Lastly, turn ANTIC back on with a $22 into SDMCTL. During the vertical blank, whi Ie ANTIC is quiet, the operating system (aS) wil I reload ANTIC's program counter with these values.

\'/R I T I NG TO A CUSTOM D I SPLAY LIST SCRE EN

Screen memory can be p I aced anywhere in the address space of the computer. Norma II y the d i sp I ay list spec if i es the beg I nn i ng of the screen memory with the first display instruction---the initial LMS instruction. However, ANTIC can execute a new LMS instruction with each display I ine of the display I ist if this is desired. In this way information from .al lover the address space of the computer can be displayed on a single screen. This can be of value in setting up independent text windows.

There are several restrictions in your placement of the screen memory.

First, screen memory cannot cross a 4K address boundary. I f you cannot avoid crossing a 4K boundary (as would be the case in BASIC mode 8, which uses 8K of RAr~) you must re load the memory scan counter with a new LMS instruction. Second, if you wish to use any of the operating system screen routines you must abide by the conventions the as uses. This can be particularly difficult when using a modified display I ist in a BASIC program. If you alter a standard display I ist from a BASIC program and then attempt to PR I NT or PLOT to the screen, the as wi I I do so under the assumption that the display list is unchanged. This will probably result in a garbled display.

There are three ways the d I sp I ay can fa i I when you attemptth is.

First, BAS I C may refuse to carry out a screen operat i on because it is impossible to do in the graphics mode that the as thinks it is in. The as stores the va I ue of the graph i cs mode that it th inks is on the screen in address $57. You can fool the as into cooperating by poking a different value there. Poke the BASIC mode number, not the ANTIC mode number.

The second fa i I ure you might get ar i ses when you mix mode lines with different screen memory byte requirements. Some mode I ines require 40 bytes per I ine, some require 20 bytes per I ine, and some require only 10 bytes per line. Let's say that you insert one 20-byte mode line into a d i sp I ay list with 40 byte mode lines. Then you PR I NT text to the d i sp I ay. Everyth i ng above the interloper I ine is fine, but below it the characters are shifted 20 spaces to the right. This is because the as assumed that each I ine would require 40 bytes and positioned the characters accordingly. But ANTIC, when it encountered the interloper I ine, took only 20 bytes of what the as thought shou I d be a 40-byte line. ANTI C interpreted the other 20 bytes as belonging to the next I ine, and displayed them there. This resulted in the

2-8

ANTIC AND THE DISPLAY LIST

next line and al I later lines being shifted 20 spaces to the right.

The only absolute way around this problem Is to refrain from using BAS I C PR I NTs and PLOTs to output to a custom d I sp I ay I I st screen. The qulck-and-dlrty solution is to organize the screen into I ine groups that contain integer multiples of the standard byte requirement. That is, do not Insert a 20-byte mode line into a 40-byte display; instead insert two 20-byte lines or one 20-byte I I ne and two 10-byte I I nes. I So long as you retain the proper Integer multiples, the horizontal shift wi I I be avoided.

This solution accentuates the third problem with mixed display lists and BAS I C: vert i ca I sh I fts. The OS pos it Ions screen mater I a I vert i ca II y by ca I cu I at i ng the number of bytes to sk I p down from the top of the screen. In a standard 40-byte I I ne d I sp I ay, BAS I C wou I d pos I t I on the characters onto the tenth I I ne by sk I pp i ng 360 bytes from the beg I nn I ng. I f you have inserted four 10-byte I I nes, BAS I C wi I I end up three lines further down the screen than you would otherwise expect. Furthermore, different mode lines consume different numbers of scan I ines, so the position on the screen wil I not be qu i te what you expected I f you do not take scan line costs into account.

As you can see, m I xed mode d i sp I ays can be d iff i cu I t to use in conjunct I on with the OS. Often you must foo I the OS to make such d i sp lays work. To PRINT or PLOT to a mode window, POKE the BASIC mode number of that window to address $57, then POKE the address of the top left pixel of the mode window into locations $58 and $59 (low then high). In character modes, execute a POSITION 0,0 to home the cursor to the top-left corner of the mode window. In map modes, all PLOTs and DRAWTOs wi II be made using the top-left corner of the mode window as the origin of the coordinate system.

The d I sp I ay list system can be used to produce appea ling screen displays. Its most obvious use is for mixing text and graphics. For example, you could prepare a screen with a bold BASIC mode 2 title, a medium size BASIC mode 1 subtitle, and small BASIC mode 0 fine print. You could then throw in a BASIC mode 8 picture in the middle with some more text at the bottom. A good example of this technique is provided by the display in the ATARI States and Capitals program.

The aforementioned problems wil I discourage the extensive use of such techniques from BASIC. With assembly language routines, modified display I ists are best used by organizing the screen into a series of windows, each window having its own LMS instruction and its own independent RAM area.

APPLICATIONS OF DISPLAY LISTS

One simple appl ication of display I ist modifications is to vertically space I ines on the screen by inserting blank I ine bytes. This wil I add some vertical spacing which will highlight critical messages and enhance the readabi I ity of some displays.

Another important use of display I ist manipulations is in providing

2-9

ANTIC AND THE DISPLAY LIST

access to features not available from BASIC. There are three text modes supported by ANTIC that BASIC does not support. Only display list man i pu I at ions ga in the user access to these modes. There are a I so d i sp I ay I ist interrupt and fine scrol ling capabi I ities that are only avai lable after the display I ist is modified. These features are the subjects of Sections 5 and 6.

Manipulations with the LMS instruction and its operand offer many possibll l t l es to the creative programmer. For example, by changing the LMS during vertical blank, the programmer can alternate screen images. This can be done at slow speed to change between predrawn displays without having to redraw each one. Each display would continue to reside in (and consume) RAM even whi Ie it is not in use, but it would be avai lable almost instantly. This technique can also be used for animation. By fl ipping through a sequence of displays, cycl ic animation can be achieved. The program to do this would manipulate only 2 address bytes to display many thousands of bytes of RAM.

It is also possible to superimpose images by fl ipping screens. at high speed. The human eye has a time resolution of about 1/16 of a second, so a program can cycle between four images, one every 1/60 of a second, so that each repeats every 1/15 of a second. In this way, up to four images can appear to res i de s i mu I taneous I y on the screen. Of cou rse, there are some drawbacks to this method. First, four separate displays may wei I cost a lot of RAM. Second, each display image wil I be washed out because it only shows up one quarter of the time. This means that the background of al I displays must be black, and each image must be bright. Furthermore, there wi II be some unpleasant screen fl icker when this technique is used. A conservative programmer might consider cycl ing between only three or even only two images. This technique can also be used to extend the color and luminosity resolution of the computer. By cycl ing between four versions of the same image, each version stressing one color or luminosity range, a wider range of colors and luminosities is available. For example, suppose you wish to display a bar.of many different luminances. First set your four color registers to the values:

)

Background: 00 Playfield 1: 02 Playfield 2: OA Play fie I d 3: OC

2-10

ANTIC AND THE DISPLAY LIST

Now put the following images into each of the screen RAM areas:

Pixel Contents (by Playfield Color Register)
First frame 2 3 2 3 2 3 2 3
Second frame B B B 2 3 2 3 2 3
Third frame B B B B B B 2 3 2 3
Fourth frame B B B B B B B B B 2 3
Effective luminance x4 2 4 6 8 10 12 20 24 30 36 40 48
Perceived I umi nance
In this way, much finer luminance reso I ution is possible. A final suggestion concerns a subject that is laden with opportunities but I ittle understood as yet: the dynamic display I ist. This is a display

I ist which the 6502 changes during vertical blank periods. It should be

possible to produce interesting effects with such I ists. For example, a

text editing program dynamically inserts blank I ines above and below the screen I ine being edited set it apart from the other I ines of text. As the cursor is moved vertically, the display I ist is changed. The technique is odd but very effective.

2-11

3

GRAPHICS INDIRECTION

(COLOR REGISTERS AND CHARACTER SETS)

Indirection is a powerful concept in programming. In 6502 assembly

language, there are three levels of indirection in referring to numbers. The first and most direct level is the immediate addressing mode In which the number itself is directly stated:

LOA #$F4

The second level of Indirection is reached when the program refers to a memory location that holds the number:

LOA $0602

The third and highest level of indirection with the 6502 is attained when the program refers to a pair of memory locations which together contain the address of the memory location that holds the number. In the 6502, this indirection is compl icated by the addition of an index:

LOA ($00), Y

Indirection provides a greater degree of general ity (and hence power) to the programmer. Instead of trucking out the same old numbers every time you want

to get something done, you can simply point to them. By changing the

pointer, you can change the behavior of the program. Indirection is

obviously an important capabi I ity.

COLOR REGISTERS

Graphics indirection is bui It into the ATARI Home Computer in two ways: with color registers and with character sets. Programmers first approaching this computer after programming other systems often think in terms of direct colors. A color register is a more complex beast than a color. A color specifies a permanent value. A color register is indirect; it holds any co I or va I ue. The d if ference between the two is ana logous to the d i f ference between a box-end wrench and a socket wrench. The box-end wrench comes in one size only but a socket wrench can hold almost any size socket. A socket wrench is more flexible but takes a I ittle more ski II to use properly. Simi larly, a color register is more flexible than a color but takes more ski I I to use effectively.

There are nine color registers in the ATARI 400/800 Computer; four are for player-missile graphics and will be discussed in Section 4. The remaining five are not always used; depending on the graphics mode used, as few as two reg i sters or as many as five wi I I show up on the screen. I n BAS I C mode 0, only two and one-half registers are used because the hue value of the characters is ignored; characters take the same hue as playfield register 2 but take their luminance from register 1. The color registers are in CTIA at addresses $0016 through $001A. They are "shadowed" from OS RAfv1 locations into CTIA during vertical blank. Figure 3-1 gives color register shadow and hardware addresses.

3-1

GRAPHICS INDIRECTION
-)
Image Hardware OS Shadow
Contro lied Label Address Label Address
Player 0 COLPMO 0012 PCOLRO 2CO
Player 1 COLP~jl1 0013 PCOLR1 2C1
Player 2 COLPM2 0014 PCOLR2 2C2
Player 3 COLPfv13 0015 PCOLR3 2C3
Playfield 0 COLPFO 0016 COLORO 2C4
Playfield 1 COLPF1 0017 COLOR1 2C5
Playfield 2 COLPF2 0018 COLOR2 2C6
Playfield 3 COLPF3 0019 COLOR3 2C7
Background COLBK 001A COLOR4 2C8
Figure 3-1 Color Register Labels and Addresses For most purposes, the user controls the color registers by writing to the shadow locations. There are only two cases in which the programmer would write directly to the CTIA addresses. The first and most common is the display I ist interrupt which wil I be discussed in Section 5. The second arises when the user disables the OS vertical blank interrupt routines that move the shadow values Into CTIA. Vertical blank interrupts are discussed in Section 8.

Colors are encoded in a color register by a simple formula. The upper nybble gives the hue value, which is identical to the second parameter of the BASIC SETCOLOR command. Table 9-3 of the BASIC Reference Manual lists hue va lues. The lower nybb lei n the co I or reg i ster gives the I urn i nance va I ue of the co I or. It is the same as the th i rd parameter in the BAS I C SETCOLOR command. The lowest order bit of th is nybb lei s not sign if i cant. Thus, there are eight I um i nances for each hue. There are a tota I of 128 colors from which to choose (8 luminances times 16 hues). In this book, the term 'color' denotes a hue-luminance combination.

Once a co I or is encoded into a co I or reg i ster, it is mapped onto the screen by referring to the color register that holds it. In map display modes which support four color registers the screen data specifies which color register is to be mapped onto the screen. Since there are four color registers it takes only two bits to encode one pixel. Thus, each screen data byte holds data for four pixels. The value in each pair of bits specifies which color register provides the color for that pixel.

In text display modes (BASIC's GRAPHICS modes 1 and 2) the selection of color registers is made by the top two bits of the character code. This I eaves on I y six bits for def in i ng the character, wh i ch is why these two modes have only 64 character available.

Color register indirection gives you four special capabil ities. First, you can choose from 128 different colors for your displays. This al lows you to choose the color that most nearly meets your needs.

3-2

GRAPHICS INDIRECTION

Second, you can manipulate the color registers in real time to produce

pretty effects. The simplest versfon of this is demonstrated by the

fo I low i ng BAS I C line:

FOR 1=0 TO 254 STEP 2:POKE 712,I:NEXTI

This I ine simply cycles the border color through all possible colors. The effect is quite pleasing and certainly grabs attention. The fundamental technique can be extended in a variety of ways. A special variation of this is to create simple cycl ic animation by drawing a figure in four colors and then cyc I the co I ors through the co I or reg i sters rather than redraw i ng the figure. The fol lowing program illustrates the idea:

10 GRAPHICS 23 20 FOR X=O TO 39 30 FOR 1=0 TO 3 40 COLOR I

50 PLOT 4*X+I,0

60 DRAWTO 4*X+ 1,95 70 NEXT I

80 NEXT X

90 A=PEEK (712)

100 POKE 712,PEEK(710) 110 POKE 710,PEEK(709) 120 POKE 709,PEEK(708) 130 POKE 708,A

140 GOTO 90

The third appl ication of color registers is to logically key colors to situations. For example, a paged menu system can be made more understandable by changing the background color or the border color for each page in the menu. Perhaps the screen could flash red when an i I legal key is pressed. The use of the color characters avai lable in BASIC Graphics modes 1 and 2 can great I y extend the impact of textua I mater i a I. An account sum could be shown in red if the account is in the red, or black if the account is in the black. Important words or phrases can be shown in special colors to make them stand out. The use of colors in map modes (no text) can also improve the uti I ity of such graphics. A single graphics image (a monster, a boat, or whatever) could be presented in several different colors to represent severa i d i f ferent vers ions of the same th i ng. I t costs a great deal of RAM to store an image, but it costs very I ittle to change the color of an existing image. For example, it would be much easier to show three different boats by presenting one boat shape in three different colors than three different boat shapes.

The fourth and most important appl ication of color registers is used with display I ist interrupts. A single color register can be used to put up to 128 colors onto a single screen. This very important capabi I ity wil I be discussed in Section 5.

3-3

GRAPHICS INDIRECTION

CHARACTER SETS

Graph i cs i nd i rect i on is a I so prov i ded through the use of redef i nab Ie character set. A standard character set is provided In ROM, but there is no reason why this particular character set must be used. The user can create and d i sp I ay any character set des ired. There are three steps necessary to use a redefined character set. First, the programmer must define the character set. This is the most time-consuming step. Each character is displayed on the screen on an 8x8 grid; it is encoded in memory as an 8-byte table. Figure 3-2 depicts the encoding arrangement.

Character Image

Binary Representation Hex Representation

00000000 00011000 00111100 01100110 01100110 01111110 01100110 00000000

00 18 3C 66 66 7E 66 00

Figure 3-2 Character Encoding

A fu I I character set has 128 characters in it, each with a norma I and an inverse video i ncarnat ion. Such a character set needs 1024 bytes of space and must start on a 1K boundary. Character sets for BASIC modes 1 and 2 have only 64 distinct characters, and so require only 512 bytes and must start on a 1/2K boundary. The first 8 bytes define the zeroth character, the next 8 bytes define the first character, and so on. Obviously, defining a new character set is a big job. Fortunately, there are software packages on the market to make this job easier.

Once the character set is defined and placed into RAM, 'you must tell ANTIC where it can find the character set. This is done by poking the page number of the beginning of the character table into location $0409 (decimal 54281 ) • The OS shadow I ocat ion, wh i ch is the I ocat i on you wou I d norma I I Y use, is called CHBAS and resides at $2F4 (decimal 756). The third step in us i ng character sets is to pri nt the character you want onto the screen. Th i s can be done direct I y from BAS I C with simp I e PR I NT statements or by writing numbers directly into the screen memory.

A spec i a I capab iii ty of the system not supported in BAS I Cis the four-color character set option. BASIC Graphics modes 1 and 2 support five colors, but each character in these modes is really a two-color character; each one has a foreground color and a background color. The foreground color can be any of four single colors, but only one color at a time can be shown within a single character. This can be a serious hindrance when using

3-4

GRAPHICS INDIRECTION

character graphics.

There are two other text modes des igned espec i a I I Y for character graphics. They are ANTIC modes 4 and 5. Each character in these modes is only four pixels wide, but each pixel can have four colors (counting background) The characters are defined just I ike BASIC Graphics mode 0 characters, except that each pixel is twice as wide and has two bits assigned to itto specify the color register used. Unl ike ANTIC modes 6 and 7 (BASIC modes 1 and 2), color register selection is not made by the character name byte but instead by the defined character set. Each byte in the character table is broken into four bit pairs, each of which selects the color for a pixel. (This is why there are only four horizontal pixels per character. ) The hi g hest bit (07) of the character name byte mod i f i es the co I or reg i ster used. Co I or reg i ster se I ect i on is made accord i ng to Fig u re 3-3:

bit pair in D7 = 0 D7
character defn
00 COLBAK COLBAK
01 PFO PFO
10 PF1 PF1
11 PF2 PF3 Figure 3-3 Color Register Selection for Characters

Us i ng these text modes, mu I t i co I ored graph i cs characters can be put onto the screen.

Another interest i ng ANTI C character mode is the lowercase descenders mode (ANTI C mode 3). Th i s mode d i sp lays 10 scan lines per mode line, but since characters use only eight bytes vertically, the lower two scan lines are normally left empty. If a character in the last quarter of the character set is displayed, the top two scan I ines of the character wi I I be left empty; the data that should have been displayed there wi 1'1 instead be shown on the bottom two lines. Th i s a I lows the user to create lowercase characters with descenders.

APPLICATIONS OF CHARACTER SETS

Many interesting and useful appl ication possibi I ities spring from character set indirection. The obvious appl ication is the modified font. A

different font can give a program a unique appearance. It is possible to

have Greek, Cyr i I I i c, or other spec i a I character sets. Go i ng one step

further, you can create graph i cs fonts. The ENERGY CZAR'" computer program uses a redef i ned character set for bar graphs. A character occup i es eight pixels; this means that bar charts implemented with standard characters have a resolut of eight pixels, a rather poor resolution. ENERGY CZAR uses a

3-5

GRAPHICS INDIRECTION

~)

special character set in which some of the less popular text symbols (ampersands, pound signs, and the I Ike) have been replaced with special bar chart characters. One character is a one-pixel bar, another Is a two-pixel bar, and so on to the full eight-pixel bar. The program can thus draw detai led bar charts with resolution of a single pixel. Figure 3-4 shows a typical display from this program. The mix of text with map graphics is only apparent; the entire display Is constructed with characters.

PRZCES COAL T .1.4-

OXL T

.1.S

NLGA'S T .16

URANH T .14-

HVDRO T ..1.2:

~OLAR T ..1.4-

HXND T ~8

BMASS. T .15

FREEZE THAH

co ......

Figure 3-4 ENERGY CZARm Bar Charts

In many appl ications, character sets can be created that show special images. For example, by defining a terrain graphics character set with river characters, forest characters, mounta in characters, and' so forth, It is possible to make a terrain map of any country. Indeed, with imagination a map of terra in on a different planet can be done just as eas II y. When doing this, it is best to define five to eight characters for each terrain type. Each variation of a single type should be positioned slightly different I yin the character pi xe I • By mix I ng the different characters together, it is possible to avoid the monotonous look that is characteristic of primitive character graphics. Most people won't realize that the resu I t I ng map uses character graph i cs unt i I they study the map close I y. Figure 3-5 shows a display of a terrain map created with character set graph i cs • The reproduct i on in black and wh i te does not do just i ce to the original display, which has up to 18 colors.

3-6

GRAPHICS INDIRECTION

Figure 3-5 Terrain Map With Character Set Graphics

You could create an electronics character set with transistor characters, diode characters, wire characters, and so forth to produce an electronics schematics program. Or you could create an architectural character set with doorway characters, wa I I characters, corner characters, and so on to make an architectural blueprint program. The graphics possibi I ities opened up by character graphics with personal computers have not been fu I Iy exp I ored •

Characters can be turned upside down by pokeing a 4 into location 755.

One possible application of this feature might be for displaying playing cards (as ina Blackjack game). The upper ha I f of the card can be shown right side up; with a display list interrupt the characters can be turned ups i de down for the lower ha I f of the card. Th is feature might a I so be of some use in displaying images with mirror reflections (reflection pools, lakes, etc

Even more exciting possibi I ities spring to mind when you real ize that it is quite practical to change character sets while the program is running. A character set costs either 512 bytes or 1024 bytes; in either case it is quite inexpensive to keep multiple character sets in memory and flip between them during program execution. There are three time regimes for such character set multiplexing: human slow (more than 1 second); human fast (1/60 second to 1 second); and machine fast (faster than 1/60 sec).

3-7

GRAPHICS INDIRECTION

Human-slow character set multiplexing is useful for "change of scenery" work. For example, a space travel program might use one graphics character set for one planet, another set for space, and a th i rd set for another planet. As the traveler changes locations, the program ohanges the character set to give exotic new scenery. An adventure program might change character sets as the player changes locales.

Human-fast character set mu It i P I ex i ng is p r i mar i I Y of va I ue for animation. This can be done in two ways: changing characters within a single character set, and changing whole character sets. The SPACE INVADERS (trademark of Taito America Corp.) program on the ATARI Home Computer uses the former techn i que. The invaders are actua I I Y characters. By rap i d I Y changing the characters, the programmer was able to animate them. This was easy because there are only six different monsters; each has four different incarnations.

High-speed cycl ic animation of an entire screen is possible by setting up a number of character sets, drawing the screen image, and then simply cyc ling through the character sets. I f each character has as light I Y different incarnation in each of the character sets, that character will go through an animated sequence as the character sets are changed. In this way a screen ful I of objects could be made to cycl icly move with a very simple loop. Once the character set data is in p I ace and the screen has been drawn, the code to animate the screen would be this simple:

1000 FOR 1=1 TO 10

1010 POKE 756,CHARBASE( I) 1020 NEXT I

1030 GOTO 1000

Computer-fast character set animation is used to put multiple character sets onto a sing I e screen. Th i s makes use of the d i sp I ay list interrupt capabi I ity of the computer. Display I ist interrupts are discussed in Section 5.

The use of character sets for graphics and animation has many advantages and some I l m i tat ions. The biggest advantage is that it costs very little RNl to produce detai led displays. A graphics display using BASIC mode 2 characters (such as the one shown in Figure 3-5) can give as much deta i I and one more co I or than a BAS I C mode 7 d i sp I ay. Yet the character image wi I I cost 200 bytes wh i I e the map image wi I I cost 4000 bytes. The RAM cost for multiple character sets is only 512 bytes per set, so it is inexpensive to have multiple character sets. Screen manipulations with character graphics are much faster because you have less data to manipulate. However, character graphics are not as flexible as map graph i cs. You cannot put cnyth i ng you want anywhere on the screen. Th i s limitation would preclude the use of character graphics in some app I i cat ions. However, there rema in many graph i cs app I i cat ions for wh i ch the program need display only a I imited number of predefined shapes in fixed locations. In these cases, character graphics provide great uti I ity.

3-8

4 PLAYER-MISSILE' GRAPHICS

DIFFICULTIES WITH HIGH-SPEED ANIMATION

Animation is an Important capability of any home computer system.

Act I v I ty on the screen can great I y add to the exc I tement and rea I I sm of any

program. Certainly animation Is crucial to the appeal of many computer

games. More Important, an an I mated I mage can convey I n format Ion with more

Impact and clarity than a static Image. It can draw attention to an item or event of Importance. I t can direct I y show a d ynam I c process rather than i nd I rect I y ta I k about It. An I mat Ion must accord I ng I y be regarded as an Important element of the graphics capabl I Itles of any computer system.

The conventional way to effect animation with home computers Is to move the I mage data through the screen RAM area. Th i s requ I res a two-step process. First, the program must erase the old Image by writing background values to the RAM containing the current Image. Then the program must write the Image data to the RAM corresponding to the new position of the Image. By repeat I ng th I s process over and over, the I mage w I I I appear to move on the screen.

There are two problems with this technique. First, if the animation Is being done In a graphics mode with large pixels, the motion wi II not be smooth; the Image wll I jerk across the screen. With other computers the only solution is to use a graphics mode with smaller pixels (higher resolution). The second problem Is much worse. The screen Is a two-dimensional Image but the screen RAM I s organ I zed one-d I mens I ona I I y. Th I s means that an I mage which is contiguous on the screen will not be contiguous in the RAM. The discrepancy Is Illustrated In Figure 4-1.

IMAGE

Corresponding Bytes In RAM

00 00 00 00 99 00 00 BD 00 00 FF 00 00 BD 00 00 99 00 00 00 00

Spacing of Bytes In RAM:

00 00 00 00 99 00 00 BD 00 00 FF 00 00 BD 00 00 99 00 00 00 00

Image Bytes Scattered Through RAM

Figure 4-1 Noncontiguous RAM Images

4-1

)

PLAYER-MISSILE GRAPHICS

The significance of this discrepancy does not become obvious until you try to write a program to move such an image. Look how the bytes that make up the i mage are scattered through the RAM. To erase them, your program must calculate their addresses. This calculation is not always ~asy to do. The assembly code just to access a single screen byte at screen location (XPOS, YPOS) wou I d look like th i s (th is code assumes 40 bytes per screen line) :

LOA SCRNRM STA POINTR LOA SCRNR~1+1 STA POINTR+l LOA #$00

STA TEMPA+l LOA YPOS

ASL A

ROL TEMPA+l ASL A

ROL TErv1PA+l ASL A

ROL TE~1PA+l LOX TEMPA+l STX TEMPS+l STA TEMS ASL A

ROL TEMPA+l ASL A

ROL TEMPA+l CLC

AOC TEMPS STA TEt-1PS LOA Tn1PA+l AOC TEMPB+l STA TEMPB+l LOA TEtvlPS CLC

AOC POINTR STA POINTR LOA TEMPB+l AOC POINTR+l STA POINTR+l LOY XPOS

LOA (POINTR),Y

Address of beginning of screen RAM zero page pointer

high order byte of address high order pointer

temporary register vertical position times 2

shift carry into TEMPA+l times 4

shift carry again times 8

shift again

save YPOS*8

into TEr.1PB

low byte

times 16

times 32

add in YPOS*8 to get YPOS*40

now do high order byte

TEMPS contains the offset from top of screen to pixel

Clearly, this code to access a screen location is too cumbersome. This is certainly not the most elegant or fastest code to solve the problem. Certainly a good programmer could take advantage of special circumstances to make the code more compact. The point of this is that accessing pixels on a screen takes a lot of computing. The above routine takes about 100 machine cyc I es to access a sing I e byte on the screen. To move an i mage that occupies, say, 50 bytes, would require 100 accesses or about 10,000 machine cycles or roughly 10 mi I I iseconds. This may not sound I ike much but if you

4-2

PLAYER-MISSILE GRAPHICS

want to achieve smooth motion, you have to move the object every 17 milliseconds. If there are other objects to move or any calculations to carry out there isn't much processor time left to devote to them. What this means is that this type of animation (called "playfield animation") Is too slow for many purposes. You can sti II get animation this way, but you are I imited to few objects or small objects or slow motion or few calculations between motion. The trade-offs that a programmer must make in using such animation are too restrictive.

PLAYER-MISSILE FUNDAMENTALS

The ATARI Home Computer solution to this problem is player-missile graphics. In order to understand player-missi Ie graphics, it is Important to understand the essence of the problem of playfleld animation: the screen Image is two-dimensional whl Ie the RAM image is one-dimensional. The solution was to create a graphics object that is one-dimensional on the screen as well as one-dimensional In RAM. This object <Called a player) appears in RAM as a table that is either 128 or 256 bytes long. The table I s mapped direct I y to the screen. I t appears as a vert i ca I band stretch i ng from the top of the screen to the bottom. Each byte in the table is mapped Into either one or two hor I zonta I scan I I nes, with the cho ice between the two made by the programmer. The screen image is a simp I e bit-map of the data In the table. If a bit Is on, then the corresponding pixel in the vertical column Is lit; If the bit is off, then the corresponding pixel is off. Thus, the player image Is not strictly one-dimensional; it is actually eight bits wide.

Drawing a player Image on the screen is quite simple. First you draw a picture of the desired image on graph paper. This image must be no more than eight pixels wide. You then translate the image into binary code, substituting ones for I I luminated pixels and zeros for empty ones. Then you translate the resulting binary number into decimal or hexadecimal, depending on wh I ch is more con ven i ent • Then you store zeros into the player RAM to c I ear the image. Next, store the i mage data into the player RAM, with the byte at the top of the player image going first, fol lowed by the other image bytes in top to bottom sequence. The further down in RAfvl you p I ace the data, the lower the image wi I I appear on the screen.

VERTICAL MOTION

Animating this image Is very easy. Vertical motion is obtained by

moving the image data through the player RAM. This is, In principle, the same method used In playfield animation, but there is a big difference in practice; the move routine for vertical motion is a one-dimensional move Instead of a two-dimensional move. The program does not need to multiply by 40 and it often does not need to use Indirection. It could be as simple as:

4-3

PLAYER-MISSILE GRAPHICS

LOX #$01

LOOP LOA PLAYER,X STA PLAYER-1,X INX

BNE LOOP

Th i s rout i ne takes about 4 mil I i seconds to move the ent i re player, about half as long as the playfield animation routine which actually moves only 50 bytes where th i s one moves 256 bytes. If high speed is necessary, the loop can be trimmed to move only the image bytes themselves rather than the whole player; then the loop wou Ideas i I Y run in about 100-200 microseconds. The point here Is that vertical motion with players is both simpler and faster than motion with playfield objects.

HOR I ZONTAL rvlOT ION

Hor i zonta I mot ion is even eas i er than vert i ca I mot i on. There is a register for the player cal led the horizontal position register. The value in this register sets the horizontal position of the player on the screen. AI I you do is store a number into this register and the player jumps to that hor i zonta I pos it i on. To move the player hor i zonta I I Y simp I y change the number stored in the hor i zonta I pos it i on reg i ster. That's a I I there is to it.

Horizontal and vertical motion are independent; you can combine them in any fashion you choose.

The scale for the horizontal position register is one color clock per un it. Thus, add i ng one to the hor i zonta I pos it i on reg i ster wi I I move the player one color clock to the right. There are only 228 color clocks In a single scan line; furthermore, some of these are not displayed because of overscan. The horizontal position register can hold 256 positions; some of these are off the left or right edge of the screen. Position 47 corresponds to the I eft edge of the standard pi ayf i e I d; pos it i on 208 corresponds to the right edge of the standard playfield. Thus, the visible region of the player is in hor i zonta I pos it ions 47 through 208. Remember, however, that this may vary from television to television due to differences in overscan. A conservative range of values is from 60 to 200. This coordinate range can sometimes be clumsy to use, but it does offer a nice feature: a simple way to remove a player from the screen Is to set the player's horizontal position to zero. With a single load and store in assembly (or a single POKE in BASIC), the player wi 11 disappear.

OTHER PLAYER-MISSILE FEATURES

The system descr i bed so far makes it poss i b I e to produce high-speed an i mat i on. There are a number of embe I I i shments wh i ch great I y add to its overal I uti I ity. The first embel I ishment is that there are four independent players to use. These players al I have their own sets of control registers

4-4

PLAYER-MISSILE GRAPHICS

and RAM area; thus their operation Is completely Independent. They are labeled PO through P3. They can be used side by side to give up to 32 bits of horizontal resolution, or they can be used Independently to give four movable objects.

Each player has Its own color register; this color register Is

completely Independent of the playfleld color registers. The player color

registers are called COLP(X) an are shadowed at PCOLR(X). This gives you

the capability to put much more color onto the screen. However, each player has only one color; multicolored players are not possible without display list Interrupts (display list Interrupts are discussed In Section 5).

Each player has a controllable width; you can set It to have normal width, double width, or quadruple width with the SIZEP(X) registers. This Is usefu I for mak I ng p I ayers take on d I f ferent sizes. You a I so have the opt I on of choos I ng the vert I ca I reso I ut I on of the p I ayers. You can use single-line resolution, In which each byte In the player table occupies one horizontal scan line, or double-line resolution, In which each byte occupies two hor I zonta I scan I I nes. With sing I e-I I ne reso I ut I on, each p l aver bit-map table Is 256 bytes long; with double-line resolution each table Is 128 bytes long. Th is I s the on I y case where player propert I es are not Independent; the selection of vertical resolution applies to al I players. Player vert I ca I reso I ut I on Is contro I I ed by bit 04 of the OMACTL reg I s+er . In single-line resolution, the first 32 bytes In the player table area I l e above the standard playfleld. The last 32 bytes I l e below the standard playfleld. In double-line resolution, 16 bytes I l e above and 16 bytes I Ie below the standard playfleld.

MISSILES

The next embel I Ishment Is the provIsion of missiles. These are 2-blt wide graphics objects associated with the players. There Is one missile assigned to each player; It takes Its color from the player's color reg I ster. Miss I I e shape data comes from the miss I Ie bit-map tab I e I n RAM just In front of the player tables. All four missiles are packed Into the same table (four missiles times 2 bits per missile gives 8 blt$). Missiles can move I ndependent I y of P I ayers; they have the I r own hor I zonta I pos I t I on registers. Missiles have their own size register, SIZEM, which can set the horizontal width just I Ike the SIZEP(X) registers do for players. However, miss I I es cannot be set to d I f ferent sizes; they are a I I set together. Missiles are useful as bullets or for skinny vertical lines on the screen. I f des I red, the ml ss I I es can be grouped together I nto a fifth player, In which case they take the color of playfleld color register 3. This Is done by setting bit 04 of the priority control register (PRIOR). Note that missiles can stl II move Independently when this option Is In effect; their hor I zonta I pos It r ons are set by the I r hor I zonta I pos I t I on reg I sters. The fifth player enable bit only affects the color of the missiles.

You move a missile vertically the same way that you move a player: by moving the missile Image data through the missile RN1 area. This can be difficult to do because missiles are grouped Into the same RAM table. To

4-5

PLAYER-MISSILE GRAPHICS

~\ )

access a single missi Ie, you must mask out the bits for the other missiles.

PLAYER AND PLAYFIELD PRIORITIES

An important feature of player-missi Ie graphics is that players and missiles are completely independent of the playfield. You can mix them with any graphics mode, text or map. This raises a problem: what happens if a player ends up on top of some playfield image? Which image has priority? You have the option to define the priorities used In displaying players. If you wish, al I players can have priority over al I playfield color registers. Or you can set all playfield color registers (except background) to have pr i or i ty over a I I P I ayers. Or you can set player 0 and player 1 (henceforth referred to as PO and P1) to have priority over al I playfield color registers, with P2 and P3 having less priority than the playfield. Or you can set playfield color registers 0 and 1 (PFO and PFl) to have priority over al I players, which then have priority over PF2 and PF3. These priorities are selected with the priority control register (PRIOR) which is shadowed at GPRIOR. This capabi I ity al lows a player to pass in froht of of one Image and behind another, al lowing three-dimensional effects.

HARDWARE COLLISION DETECTION

The final embellishment is the provision for hardware coil ision detection. This Is primari Iy of value for games. You can check if any graphics object (player or missile) has col I ided with anything else. Specifically, you can check for missi Ie-player col I isions, missile-playfield collisions, player-player coil isions, and player-playfield collisions. There are 54 possible col I isions, and each one has a bit assigned to it that can be checked. If the bit is set, a coil l s l on has occurred. These bits are mapped Into 15 registers in CTIA (only the lower 4 bits are used and some are not meaningful). These are read-only registers; they cannot be cleared by writing zeros to them. The registers can be cleared for further coil ision detection by writing any value to register HITCLR. All coil ision registers are cleared by this command.

In hardware terms, col I Isions occur when a player image coincides with another image; thus, the col I islon bit wil I not be set until the part of the screen show i ng the co I lis ion is drawn. Th is means that co I lis i on detect i on might not occur unti I as much as 16 mi II iseconds have elapsed since the player was moved. The preferred solution is to execute player motion and col I ision detection during the vertical blank interrupt routine (see Section 8 for a discussion of vertical blank interrupts). In this case coil ision detect i on shou I d be checked first, then co I lis Ions c I eared, then p I ayers moved. Another solution is to wait at least 16 mil I iseconds after moving a player before checking for a col I ision involving that player.

There are a number of steps necessary to use player-missile graphics.

First you must set as I de a pi ayer-mi ss i I e RA~l area and te II the computer where it is. I f you use sing Ie-I i ne reso I ut ion, th is RAr-1 area wi I I be 1280 bytes long; if you use double-I ine resolution it wi II be 640 bytes long. A

4-6

PLAYER-MISSILE GRAPHICS

good pract i ce is to use the RAM area just in front of the d i sp I ay area at the top of RAM. The layout of the player-missile area is shown in Figure 4-2.

double line

single line

PMBASE

+384 +512 +640 +768 +896 +1024

unused
unused
M3 I M21 M1 I MO
Player 0
Player 1
Player 2 M31M21 M11 MO
Player 3
Player 0
Player 1
Player 2
Player 3 +768

+1024

+1280

+1536

+1792

+2048

Figure 4-2 Player-Missi Ie RAM Area Layout

The pointer to the beginning of the player-missile area is labeled PMBASE. Because of internal I imitations of ANTIC, P~lBASE must be on a 2K address boundary for single-I ine resolution, or a 1K address boundary for doub Ie-I i ne reso I ut i on. I f you elect not to use a II of the p I ayers or none of the missi les, the areas of RAM set aside for the unused objects may be used for other purposes. Once you have decided where your player-missi Ie RAM area wi II be, you inform ANTIC of this by storing the page number of PMBASE into the P~'lBASE reg i ster in ANTI C. Note that the address boundary restrictions on P~1BASE preclude vertical motion of players by modifying pr~BASE •

The next step is to clear the player and missile RAM by storing zeros into all locations in the player-missi Ie RAM area. Then draw the players and missi les by storing image data into the appropriate locations in the player-missi Ie RAM area.

Next, set the player parameters by setting the player color, horizontal position, and width registers to their initial values. If necessary, set the player/playfield priorities. Inform ANTIC of the vertical resolution you des ire by sett i ng bit 04 of reg i ster OMACTL (shadowed at SOMCTL) for sing Ie-I i ne reso I ut i on, and c I ear i ng the bit for doub Ie-I i ne reso I ut i on. Finally, enable the players by setting the PM OMA enable bit in OMACTL. Be careful not to disturb the other bits in DMACTL. A sample BASIC program for setting up a player and moving it with the joystick is given below:

4-7

PLAYER-MISSILE GRAPHICS

1 PMBASE=54279:REM 2 RMHOP= 1 06 : REr~

3 SDMCTL=559:REM

4 GRACTL=53277:REM 5 HPOSPO=53248:REM 6 PCOLRO=704:REM

10 GRAPHICS O:SETCOLOR 2,0,0:REM 20 X=100:REM

30 Y=48:REM

40 A=PEEK (RAtvlTOP) -8: REM 50 POKE PMBASE,A:REM

60 MYPMBASE=256*A:REM 70 POKE SDMCTL,46:REM 80 POKE GRACTL,3:REM

90 POKE HPOSPO,100:REM 100 FOR I=MYPMBASE+512 TO 110 POKE 1,0

120 NEXT I

130 FOR I=MYPMBASE+512+Y TO MYPMBASE+518+Y

140 READ A:REM This loop draws the player

150 POKE I,A

160 NEXT I

170 DATA 8,17,35,255,32,16,8 180 POKE PCOLRO,88:REM

190 A=STICK(O):REM

200 IF A=15 THEN GOTO 190:RE~·1

210 IF A=ll THEN X=X-l :POKE HPOSPO,X 220 IF A=7 THEN X=X+l:POKE HPOSPO,X

230 IF A<>13 THEN GOTO 280

240 FOR 1=8 TO 0 STEP -1

250 POKE MYPMBASE+512+Y+I,PEEK(MYPMBASE+511+Y+I) 260 NEXT I

270 Y=Y+l

280 IF A<>14 THEN GOTO 190 290 FOR 1=0 TO 8

300 POKE MYPMBASE+511+Y+I,PEEK(MYPMBASE+512+Y+I» 310 NEXT I

320 Y=Y-l

330 GOTO 190

Player-missile base pointer OS top of RAM pointer

RAM shadow of DMACTL register CTIA graphics control register Horizontal position of PO

Shadow of player 0 color

Set background color to black BASIC's player horizontal position

BASIC's player vertical position Get RAM 2K below top of RAM

Tell ANTIC where PM RAfvi is

Keep track of PM RAM address Enable PM DMA with 2-1 ine res Enable PM display

Declare horizontal position MYPMBASE+640:REM this loop clears player

Make the player pink Read joystick

If inactive, try again

Once players are displayed, they can be difficult to remove from the screen. This is because the procedure by which they are displayed involves several steps. First, ANTIC retrieves player-missi Ie data from RAM (if such retr i eva lis enab led in DMACTL). Then ANT I C sh ips the pi ayer-m iss i I e data to CTIA (if such action is enabled in GRACTL). CTIA displays whatever is in its player and missi Ie graphics registers (GRAFPO through GRAFP3 and GRAFM). Many programmers attempt to turn off player-missi Ie graphics by clearing the control bits in DrvlACTL and GRACTL. This only prevents ANTIC from sending new player-missi Ie data to CTIA; the old data in the GRAF(X) registers w l II sti II be displayed. To completely clear the players the GRAF(X) registers

4-8

PLAYER-MISSILE GRAPHICS

must be cleared after the control bits in DMACTL and GRACTL have been cleared. A simpler solution is to leave the player up but set its horizontal position to zero. Of course, if this solution is used, ANTIC wi II continue to use DMA to retrieve player-missi Ie data, wasting roughly 70,000 machine cycles per second.

APPLICATIONS OF PLAYER-MISSILE GRAPHICS

Player-missi Ie graphics allow a number of very special capabi I ities.

They are obviously of great value in animation. They do have I imitations: there are only four players and each is only 8 bits wide. If you need more bits of horizontal resolution you can always fal I back on playfield animation. But for high-speed animation or quick and dirty animation, player-missi Ie graphics work very wei I.

It is possible to bypass ANTIC and write player-missile data directly into the player-missi Ie graphics registers (GRAFP(X» in CTIA. This gives the programmer more direct control over player-missile graphics •. It also increases his responsibi I ities concomitantly. The programmer must maintain a bit map of player-missi Ie data and move it into the graphics registers at the appropr i ate times. The 6502 must therefore be slaved to the screen drawing cycle. (See the discussion of kernels in Chapter 5.) This is a clumsy techn i que that offers minor performance improvements in return for major programm i ng ef forts. The programmer who bypasses the hardware power offered by ANTIC must make up for it with his own effort.

P I ayers can a I so be used to produce apparent 3-d i mens i ona I mot i on.

This is accompl ished with the player width option. Each player is drawn with one of several bit maps. One bit map shows the player as 6 bits wide, and another shows the player in 8 bits. When the 6 bit player is drawn at normal resolution, it wi II be 6 color clocks wide. The next size step is achieved by going to double width with the 6 bit image; this wi II be 12 color clocks wide. The 8 bit image wi I I be 16 color clocks wide. Simi larly, going to quadruple width wi II produce images 24 and 32 color

clocks wide. Thus, the image can grow in size from 6 color clocks to 32

color clocks. This technique is used very effectively in STAR RAIDERS'".

The Zylons there are two players with 16 bits, so the size transistions are even smoother.

Player-missi Ie graphics offer many capabi I ities in addition to animation. Players are an excel lent way to increase the amount of color in a display. The four additional color registers they provide al low four more

colors on each I ine of the display. Of course, the 8-bit resolution does

lim i t the range of the i r app I i cat ion. There is a way around th is that can

sometimes be used. Take a player at quadruple width and put it onto the screen. Then set the priorities so that the player has lower priority than a playfield color. Next reverse that playfield color with background, so that the apparent background color of the screen is really a playfield

color. The player disappears behind this new false background. Now cut a

hole in the false background by drawing true background on it. The player

wi II show up in front of the true background color, but only in the area

4-9

PLAYER-MISSILE GRAPHICS

where true background has been drawn. In this way the player can have more than eight bits of horizontal resolution. A sample program for doing this is:

1 RA~1TOP=106:REM

2 PMBASE=54279:REM ~ SDMCTL=559:REM

4 GRACTL=53277:REM 5 HPOSPO=53248:REM 6 PCOLRO=704:REM

7 SIZEPO=53256:REM 8 GPRIOR=623:REM 10 GRAPHICS 7

20 SETCOLOR 4,8,4 30 SETCOLOR 2,0,0 40 COLOR 3

50 FOR Y=O TO 79: RH1 60 PLOT O,Y

70 DRAWTO 159,Y 80 NEXT Y

90 A=PEEK( RAtnOP) -20: REM 100 POKE PMBASE,A

110 MYPMBASE=256*A

120 POKE SDMCTL,46

130 POKE GRACTL,3

140 POKE HPOSPO,100

150 FOR I =fvlYPMBASE+512 TO fv1YP~1BASE+640 160 POKE 1,255:REM

170 NEXT I

180 POKE PCOLRO,88 190 POKE SIZEPO,3:REM 200 POKE GPRIOR,4:REM 210 COLOR 4

220 FOR Y=30 TO 40 230 PLOT Y+22,Y 240 DRAWTO Y+43,Y 250 NEXT Y

OS top of RAfv1 po inter

ANTIC player-missi Ie RAM pointer Shadow of DMACTL

CTIA graphics control register Horizontal position register of PO Shadow of player 0 color register Player width control register Priority control register

This loop fi I Is the screen

Must back up further for GR. 7

Make player sol id color

Set player to quadruple width Set priority

4-10

PLAYER-MISSILE GRAPHICS

This program produces the fol lowing display:

Figure 4-3 Masking a Player for More Resolution

SPECIAL CHARACTERS

Another appl ication of player-missi Ie graphics is for special characters. There are many spec i a I types of characters that cross vert i ca I boundar i es in norma I character sets. One way to dea I with these is to create special character sets that address this problem. Another way is to use a player. Subscripts, integral signs, and other special symbols can be done this way. A sample program for doing this is:

1 RAtHOP= 1 06: RHl

2 PMBASE=54279:REM 3 SDMCTL=559:REM

4 GRACTL=53277:REM 5 HPOSPO=53248:REM 6 PCOLRO=704:REM

10 GRAPHICS 0:A=PEEKCRAtvlTOP)-16:REfvl 20 POKE PMBASE,A

30 MYPMBASE=256*A

40 POKE SDMCTL,62

50 POKE GRACTL,3

60 POKE HPOSPO,102

70 FOR I =f'vlypr~BASE+l 024 TO t~YPMBASE+1280 80 POKE 1,0

90 NEXT I

100 POKE PCOLRO,140 110 FOR 1=0 TO 15 120 READ X

130 POKE MYPMBASE+ll00+I,X 140 NEXT I

150 DATA 14,29,24,24,24,24,24,24 160 DATA 24,24,24,24,24,24,184,112 170 ?" ":REM

180 POSITION 15,6 190 ?"xdx"

OS top of RAM pointer

ANTIC player-missi Ie RAM pointer Shadow of DMACTL

CTIA's graphics control register Horizontal position register of PO Shadow of player 0 color register Must back up for 1-1 ine resolution

Clear screen

4-11

PLAYER-MISSILE GRAPHICS

This program produces the fol lowing display:

xdx

Figure 4-4 Using a Player as a Special Character

A particularly useful application of players is for cursors. With

their abi I ity to smoothly move anywhere over the screen without disturbing its contents they are ideally suited for such appl ications. The cursor can change color as it moves over the screen to indicate what it has under It.

Player-missile graphics provide many capabi I ities. Their uses for

action games as animated objects are obvious. They have many serious uses as we I I • They can add co I or and reso I ut i on to any d i sp I ay. They can present special characters. They can be used as cursors. Use them.

4-12

5

DISPLAY LIST INTERRUPTS

The display I ist interrupt (Dll) is one of the most powerful capab iii ties bu i It into the ATAR I Home Computer. It is a I so one of the I east accessible features of the system, requiring a firm understanding of assembly language as wei I as al I of the other characteristics of the machine. Display list interrupts a I I by themse I ves prov i de no add it i ona I capab iii ties; they must be used in conjunct i on with the other features of the system such as player-missi Ie graphics, character set indirection, or color register indirection. With display I ist interrupts the full power of these features can be deployed.

THEORY OF OPERATION

Display I ist interrupts take advantage of the sequential nature of the raster scan te I ev i s ion d i sp I ay. The te I ev is i on draws the screen image ina

time sequence. It draws images from the top of the screen to the bottom.

This drawing process takes about 17,000 microseconds, which looks

instantaneous to the human eye, but is a long time in the time scale that the computer works in. The computer has plenty of time to change the parameters of the screen display whi Ie it is being drawn. Of course, it must effect each change each time the screen is drawn, which is 60 times per second. A I so (and th i sis the tr i ck y part), it must change the parameter inquest i on at exactly the same time each time the screen is drawn. That is, the cycle of chang i ng screen parameters must be synchron i zed to the screen draw i ng cycle. One way to do this might be to lock the 6502 up into a tight timing loop whose execution frequency is exactly 60 Hertz. This would make it very difficult to carry out any computations other than the screen display computat ions. It wou I d a I so be a ted i ous job. A much better way wou I d be to Interrupt the 6502 just before the time has come to change the screen parameters. The 6502 responds to the interrupt, changes the screen parameters, and returns to its normal business. The interrupt to do this must be precisely timed to occur at exactly the same time during the screen drawing process. This specially timed interrupt is provided by the ANTIC chip; it is called a display I ist interrupt (DLI).

The timing and execution of any interrupt process can De intricate; therefore we wi I I first narrate the sequence of events ina proper I y work i ng DL I • The process beg ins when the ANTI C ch i p encounters a d i sp I ay list instruction with its interrupt bit (bit D7) set. ANTIC waits until the last scan I ine of the mode I ine it is currently displc:ying. ANTIC then refers to Its NMIEN register to see if display list interrupts have been enabled. If the enable bit is clear, ANTIC ignores the interrupt and continues its regular tasks. If the enable bit is set, ANTIC pulls down the NMI I ine on the 6502. ANTI C then goes back to its norma I d i sp I ay act i vi ties. The 6502 vectors through the NM I vector to an interrupt serv i ce rout i ne in the OS. This routine first determines the cause of the interrupt. If the interrupt is indeed a DLI, the routine vectors through addresses $0200, $0201 (low then high) to a DL I serv i ce rout i ne. The DL I rout i ne changes one or more of the graph i cs reg i sters wh i ch contro I the d i sp I ay. Then the 6502 RT I s to resume its mainl ine program.

5-1

DISPLAY LIST INTERRUPTS

There are a number of steps i nvo I ved in sett i ng up a OL I • The very

first th i ng you must do is wr i te the OL I rout i ne I tse If. The rout I ne must push any 6502 reg i sters that wi I I be a I tered onto the stack, as the OS interrupt pol I routine saves no registers. (The 6502 does automatically push the Processor Status Reg i ster onto the s+ack , ) The rout I ne shou I d be short and fast; it should only change registers related to the display. It should end by restor i ng any 6502 reg i sters pushed onto the stack. Next you must place the OLI service routine somewhere in memory. Page 6 is an ideal place. Set the vector at $0200, $0201 to po i nt to you r rout I ne. Oeterm i ne the vertical point on the screen where you want the OLI to occur, then go to the corresponding display I ist instruction and set bit 07 of the previous instruction. Finally, enable the OLI by setting bit 07 of the NMIEN register at $040E. The OLI wi II immediately begin functioning.

OLI TIMING

As with any interrupt service routine, timing considerations can be critical. ANTIC does not send the Interrupt to the 6502 Immediately upon encountering an interrupt instruction; it delays this until the last scan I ine of the interrupting mode I ine. There are a number of processing delays before the OLI reaches your service routine. Thus, your OLI service routine wi I I begin executing whi Ie the electron beam is partway across the screen in the last scan I ine of the interrupting mode I ine. For example, if such a OLI routine changes a color register, the old color wll I be displayed on the left half of the screen and the new color will show up on the right half of the screen. Because of uncerta in tim i ng I n the response of the 6502 to an interrupt, the border between them wi I I not be sharp but wi I I jiggle back and forth irritatingly.

There is a solution to this problem. It is provided In the form of the

WSYNC (wait for horizontal sync) register. Whenever this register is add ressed in any way, the ANTI C ch i P pu I I s down the ROY I I ne on the 6502. This effectively freezes the 6502 until the register is reset by a horizontal sync. The effect is that the 6502 freezes unti I the electron beam reaches the right edge of the standard playfield. If you insert a STA WSYNC instruction just before the instruction which stores a value 'into a color register, the color wil I go into the color register while the beam is off the screen. The color transition will occur one scan line lower, but will be neat and clean.

The proper use of a OL I then is to set the OL I bit on the mode line before the mode I ine for which you want the action to occur. The OLI service rout i ne shou I d first save the 6502 reg i sters onto the stack, and then load the 6502 registers with the new graphics values to be used. It should execute a STA WSYNC, and then store the new values into the appropriate ANTIC or CTIA registers. Finally, it should restore the 6502 registers and return from the interrupt. This procedure wil I guarantee that the graphics registers are changed at the beginning of the desired line whiJe the electron beam is off the screen.

5-2

DL I EXM~PLE

DISPLAY LIST INTERRUPTS

A simple program demonstrating a DLI is given below:

10DLIST=PEEK(560)+256*PEEK(561):REM 20 POKE DLIST+15,130:REM

30 FOR 1=0 TO 19:REM

40 READ A:POKE 1536+I,A:NEXT I 50 DATA 72,138,72,169,80,162,88 60 DATA 141,10,212,141,23,208

70 DATA 141,24,208,104,170,104,64 80 POKE 512,0:POKE 513,6:REM

90 POKE 54286,192:REM

Find display list

Insert interrupt instruction

Loop for poking DLI service routine

Poke in interrupt vector Enable DLI

Th i s rout i ne uses the fo I low i ng assemb I y language DL I serv i ce rout i ne:

PHA TXA PHA

LOA #$50 LOX #$58 STA WSYNC STA COLPF1 STX COLPF2 PLA

TAX

PLA

RTI

Save accumulator

Save X-register

Dark color for characters Pink

Wait

Store color Store color

Restore registers Done

This is a very simple DLI routine. It changes the background color from blue to pink. I t a I so changes the co I or of the characters so that they show up as dark against the pink background. You might wonder why the upper ha I f of the screen rema ins blue even though the DL I rout i ne keeps stu f f i ng pink into the co I or reg i ster. The answer is that the OS vert i ca I blank interrupt routine keeps stuffing blue into the color register during the vertical blank period. The blue color comes from the OS shadow register for that color register. Every hardware color register is shadowed out to a RAM location. You may already know about these shadow registers at locations 708 through 712. For most purposes you can change colors by poking values into the shadow registers. If you poke directly into the hardware registers, the OS shadow process will wipe out your poked color within a 60th of a second. For DLls, however, you must store your new color values direct I y into the hardware reg i sters. You can not use a DL I to set the co I or of the first d i sp I ayed line of the screen; the OS takes care of that I ine for you. Use DLls to change colors of I ines below the first line.

5-3

DISPLAY LIST INTERRUPTS

)

ATIRACT MODE

By stuffing colors directly into the hardware registers, you create a new problem: you defeat the automatic attract mode. Attract'mode is a feature provided by the operating system. After nine minutes without a keypress, the co I ors on the screen beg into cyc I e through random hues at lowered luminances. This ensures that a computer left unattended for several hours does not burn an image into the television screen. It is easy to bu i I d attract mode into a d i sp I ay list interrupt. On I y two lines of assembly code need be inserted into the DLI routine:

01 d

New

LDA NEWCOL STA WSYNC STA COLPF2

LDA NEWCOL EOR COLRSH AND DRK~~SK STA WSYNC STA COLPF2

DRKMSK and COLRSH are zero page I ocat ions ($4E and $4F) set up and updated by the OS during vertical blank Interrupt. When attract mode is not in force, COLRSH takes a va I ue of 00 and DRKMSK takes $FF. When attract mode is in force, COLRSH is given a new random value every 4 seconds and DRKMSK holds a value of $F6. Thus, COLRSH scrambles the color and DRKrvlSK lops off the highest luminance bit.

DETAILED TIMING CONSIDERATIONS

The imp I ementat i on of attract mode in DL I s exacerbates an a I ready difficult problem: the shortage of execution time during a DLI. A description of DLI timing wi I I make the problem more obvious. DLI execution is broken into three phases: - Phase One covers the period from the beginning of the DLI to the STA WSYNC instruction. During Phase One the electron beam is drawing the last scan I ine of the interrupting mode line. - Phase Two covers the period from the STA WSYNC instruction to the appearance of the beam on the te I ev is i on screen. Phase Two corresponds to horizontal blank; all graphics changes should be made during Phase Two. Phase Three covers the period from the appearance of the beam on the screen to the end of the DLI service routine. The timing of Phase Three is not critical.

One horizontal scan I ine takes 114 processor clock cycles of real time.

A DL I reaches the 6502 on cyc I e number 8. The 6502 takes from 8 to 14 cycles to respond to the interrupt. The OS routine to service the interrupt and vector it on to the DLI service routine takes 11 machine cycles. During this time from 1 to 3 cycles wll I be stolen for memory refresh DMA. Thus, the DLI service routine is not reached until from 28 to 36 clock cycles have elapsed. For planning purposes we must assume the worst case and program as if the DLI service routine is reached on cycle number 36. Furthermore, the

5-4

DISPLAY LIST INTERRUPTS

STA WSYNC instruction must be reached by cycle number 100; this reduces the time avai l ab l e in Phase One by 14 cycles. Finally, ANTIC's DMA wi II steal some of the remaining clock cycles from the 6502. Nine cycles wi I I be lost to memory refresh DMA. This leaves an absolute maximum of 55 cycles available for Phase One. This maximum is achieved only with blank I ine mode II nes. Character and map mode instruct ions wi I I resu It in the loss of one cycle for each byte of display data. The worst case arises with BASIC modes 0, 7, and 8, which require 40 bytes per I ine. Only 15 machine cycles are ava i I ab I e to Phase One I n such modes. Thus, a Phase One rout i ne wi I I have from 15 to 55 machine cycles of execution time avai lable to it.

Phase Two, the critical phase, extends over 27 clock cycles of real

t I me. As with Phase One, some of these cyc I es are lost to cyc I e stea ling

DMA. Player-missi Ie graphics wi II cost five cycles if they are used. The

display Instruction wi I I cost one cycle; if the LMS option is used, two more cyc I es wi I I be sto I en. F I na I I y, one or two cyc I es may be lost to memory refresh or display data retrieval. Thus, from 17 to 26 machine cycles are available to Phase Two.

The problems of DLI timing now become obvious. To load, attract and

store a single color will consume 14 cycles. Saving A, X, and Y onto the stack and then loading, attracting, and saving three colors Into A, X, and Y will cost 47 cycles, most If not all of Phase One. Obviously, the programmer who wishes to use DLI for extensive graphics changes wil I expend much effort on the timing of the DLI. Fortunately, the beginning programmer need not be concerned with extensive timing calculations. If only single color changes or simple graphics operations are to be performed, cycle counting and speed optimization are unnecessary. These considerations are only Important for high-performance situations.

)

There are no simple options for the programmer who needs to change more than three color registers in a single DLI. It might be possible to load, attract, and store a fourth color early in Phase Three if that color is not displayed on the left edge of the screen. Similarly, a color not showing up on the right side of the screen could be changed during Phase One. Another approach is to break one overact i ve DL I into two less amb it i ous DL Is, each do i ng ha I f the work of the or I gina I • The second DL I cou I d be prov i ded by Inserting a single scan I ine blank instruction (with DLI bit set) into the display list just below the main Interrupting mode I ine. This wi II consume some screen space.

Another partial solution is to perform the attract chores during vertical blank periods. To do this, two tables of colors must be kept in RAM. The first table contains color values intended to be displayed by the DL I rout i nes. The second tab Ie conta ins the attracted va I ues of these colors. During vertical blank, a user-suppl ied interrupt service routine fetches each color from the first table, attracts it, and stores the attracted color to the second table. The DLI routine then retrieves values directly from the second table without paying the time penalty for attract.

5-5

DISPLAY LIST INTERRUPTS

It is often desirable to have a number of DLls occurring at several vertical positions on the screen. This is an important way to add color to a display. Unfortunately, there is only one DLI vector; if multiple DLls are to be imp I emented then the vector i ng to the appropr i ate DL I must be imp I emented, in the DL I rout i ne i tse If. There are severa I ways to do th is. I f the DL I rout i ne does the same process with d i f ferent val ues then it can be table-driven. On each pass through the DLI routine, a counter is incremented and used as an index to a table of values. A sample DLI routine for doing this is as fol lows:

PHA TXA PHA

INC COUNTR LOX COUNTR

LOA COLTAB,X STA WSYNC STA COLBAK

CPX #$4F BNE ENDDLI LOA #$00 STA COUNTR

ENDDLI PLA TAX

PLA RTI

)

MULTIPLE DLls

Use page two for color table Wait

Last line?

No, exit

Yes, reset counter

Restore accumulator

The BASIC program to cal I this routine is:

10 GRAPHICS 7

20 DLIST=PEEK(560)+256*PEEK(561 ):REM 30 FOR J=6 TO 84: RD~

40 POKE DLIST+J,141:REM 50 NEXT J

60 FOR J=O TO 30

70 READ A:POKE 1536+J,A:NEXTJ:REM 80 DATA 72,138,72,238,32,6,175,32,6

90 DATA 189,0,240,141,10,212,141,26,208 100 DATA 224,79,208,5,169,0

110 DATA 141,32,6,104,170,104,64 120 POKE 512,0:POKE 513,6:REM 130 POKE 54286,192:REM

Find display list

Give every mode I ine a DLI BASIC mode 7 with DLI bit set

Poke in DLI service routine

Vector to DLI service routine Enable DLI

This program will put 80 different colors onto the screen.

There are other ways to implement multiple DLls. One way is to use a DLI counter as a test for branching through the DLI service routines to the

5-6

DISPLAY LIST INTERRUPTS

proper DLI service routine. This slows down the response of all the DLls, part I cu I ar I y the ones at the end of the test sequence. A better way I s to have each DLI service routine write the address of the next routine into the DLI vector at $200, $201. This should be done during Phase Three. This is the most general solution to the problem of multiple DLls. It has the additional advantage that vectoring logic is performed after the time critical portion of the DLI, not before.

The OS keyboard cl ick routfne interferes with the function of the DLI.

Whenever a key is pressed and acknowledged, the onboard speaker is cl icked. The timing for this cl ick is provided by several STA WSYNC instructions. This can throw off the timing of a DLI routine and cause the screen colors to jump downward by one scan I ine for a fraction of a second. There is no easy solution to this problem. One possible solution involves the VCOUNT register, a read-only register in ANTIC which tells what scan I ine ANTIC is displaying. A DLI routine could examine this register to decide when to change a co I or. Another so I ut i on is to d I sab I e the OS keyboard serv i ce routine and provide your own keyboard routine. This would be a tedious job. The final solution is to accept no Inputs from the keyboard. If key presses are not acknowledged, the screen jiggle does not occur.

KERNELS

The DLI was designed to replace a more primitive software/hardware techn i que ca I I ed a kerne I • A kerne lis a 6502 program loop wh i ch is precisely timed to the display cycle of the television set. By monitoring the VCOUNT register and consulting a table of screen changes cataloged as a function of VCOUNT values, the 6502 can arbitrarily control all graphics values for the entire screen. A high price is paid for this power: the 6502 Is not available for computations during the screen display time, which is about 75 percent of the time. Furthermore, no computation may consume more than the 4000 or so machine cycles available during vertical blank and overscan periods. This restriction means that kernels can only be used with programs requiring I l+t l e computation, such as certain ski II and action games. For example, the BASKETBALL program for the ATARI 400/800 Computers uses a kernel; the program requires I ittle computation but much color. The multicolored players In this game could not be done with 'display list interrupts, because DLls are keyed to playfield vertical positions, not player positions.

It is possible to extend the kernel idea right into a single scan line and change graphics registers on the fly. In this way a single color reg I ster can present severa I co I ors on a sing I e scan line. The hor i zonta I position of the color change is determined by the amount of time that

e I apses before the change goes In. Thus, by carefu I I Y count I ng mach i ne

cycles, the programmer can get more graphics onto the screen.

Unfortunately, this Is extremely difficult to achieve in practice. With ANTIC DMAing the 6502, it is very difficult to know exactly how many cycles have really elapsed; a simple count of 6502 cycles is not adequate. If ANTIC's DMA Is turned off, the 6502 can assume ful I control of the display but must then perform a II the work that ANTI C norma I I Y does. For these

5-7

DISPLAY LIST INTERRUPTS

reasons horizontal kernels are seldom worth the effort. However, if the two images to be displayed in different colors are widely separated, say by 20 color clocks or more, the separation should cover up the timing uncertainties and render this technique feasible.

APPLICATIONS OF DISPLAY LIST INTERRUPTS

The tremendous value of graphics indirection and al I those modifiable registers in the hardware now becomes obvious. With display list interrupts, everyone of those registers can be changed on the fly. You can put lots of color, graphics, and special effects onto the screen. The most obv i ous app I i cat i on of DL lsi s to put more co I or onto the screen. Each color register can be changed as many times as you have DLls. This appl ies to both playfield color registers and player color registers. Thus, you have up to nine color registers, each of which can display up to 128 different colors. Is that enough color for you? Of course, a normal program would not lend itself to effectively using al I of those colors. Too many DLls start slowing down the whole program. Sometimes the screen layout cannot accommodate lots of DLls. In practice, a dozen colors is easy, two dozen requ ires carefu I p I ann i ng, and more than that requ i res a contr i ved situation.

Display I ist Interrupts can give more than color; they can also be

) used to extend the power of player-missi Ie graphics. The horizontal

/

position of a player can be changed by a DLI. In this way a player can be

repos it i oned partway down the screen. A sing Ie player can have severa I i ncarnat ions on the screen. I f you i mag i ne a player as a vert i ca I co I umn with images drawn on it, a DLI becomes a pair of scissors with which you can snip the column and reposition sections of it on the screen. Of course, no two sect ions of the player can be on the same hor i zonta I line, so two incarnations of the player cannot be on the same horizontal I ine. If your display needs al low graphics objects that wil I never be on the same horizontal I ine, a single player can do the job.

Another way to use DLls in conjunction with players is to change their width or priority. This would most often be used along with the priority masking trick described in Section 4.

The last appl ication of DLls is the changing of character sets partway down the screen. This al lows a program to use character graphics in a large window and regular text in a text window. "'1ultiple character set changes are possible; a program might use one graphics character set at the top of the screen, another graphics character set in the middle of the screen, and a regular text character set at the bottom. A 'Rosetta Stone' program would also be possible, showing different text fonts on the same screen. The vert i ca I ref I ect bit can be changed with a DL I rout i ne, a I low i ng some text to be rights ide up and other text to be upside down.

The proper use of the DL I requ ires carefu I I ayout of the screen display. The designer must give close consideration to the vertical architecture of display. The raster scan television system is not

5-8

DISPLAY LIST INTERRUPTS

two-dimensionally symmetric; it has far more vertical structure than horizontal structure. This is because the pace for horizontal screen drawing is 262 times faster than the pace for vertical screen drawing. The ATARI Home Computer display system was designed specifically for raster scan television, and it mirrors the anisotropy of the raster scan system. The ATARI Home Computer display is not a flat, blank sheet of paper on which you draw; it is a stack of thin strips, each of which can take different parameters. The programmer who insists on designing an isotropic display wastes many opportunities. You wi I I achieve optimal results when you organize the information you wish to display in a strong vertical structure. This al lows the ful I power of the DLI to be brought to bear.

Figure 5-1 shows some screen displays from various programs and gives estimates of the degree of vertical screen architecture used in each.

)

5-9

DISPLAY LIST INTERRUPTS

\.{_ \.{_ \.{_ \.{_ \.{_ \.{_ \.{_

-~- -r-i -,:..- i'='i -I'='i

SPACE INVADERS

(Trademark of Taito America Corporation) ***LOTS***

24600 .14648

..•..... \,\

.......

l



'.'

. ...

I' I,



+ :.:

MI SS I LE COMMANDTIt ***SOME***

OPE 3'6%

l>IV sr.

~UR 1.7Y.

GRAPH IT'" ***NONE***

SCRA~lT"

(A Nuclear Reactor Simulation) ***LITTLE***

STAR RAIDERST" ***LITTLE***

• .,~: •
• •
: ..; :
• ..t
• ••
• ASTERO I DS T" ***NONE***

Figure 5-1 Examples of Vertical Screen Ar.chitecture

5-10

6 SCROLLING

Quite frequently the amount of information that a programmer wants to display exceeds the amount of information that can fit onto the screen. One way of solving this problem is to scrol I the information across the display. For example, I istings of BASIC programs scroll vertically from the bottom to the top of the screen. A I I persona I computers imp I ement th i s type of scroll ing. However, the ATARI Home Computer has two additional scroll ing faci I ities that offer exciting possibi I ities. The first is "Load Memory Scan" (U'1S) coarse scroll ingj the second is fine scroll ing.

Conventional computers use coarse scroll ingj in this type of scroll ing, the pixels that hold the characters are fixed in position on the screen and text is scrolled by moving bytes through the screen RAM. The resolution of the scrol I ing is a single character pixel, which is very coarse. The scroll ing this produces is jerky and quite unpleasant. Furthermore, it is achieved by moving up to a thousand bytes around in memory, a slow and clumsy task. I n essence, the program must move data through the pi ayf i e I d to scro I I •

Some persona I computers can produce a somewhat finer scro I I by draw i ng images in a higher resolution graphics mode and then scroll ing these images. Although hLgher scrol ling resolutton is achieved, more data must be moved to attain the scrolling and the program is consequently slowed. The fundamental problem is that the scroll ing is implemented by moving data through the screen area.

There is a better way to achieve coarse scroll ing with the ATARI 400/800: move the screen area over the data. The d i sp I ay list opcodes support the Load Memory scan feature. The LMS instruction was first described in Section 2 and tel Is ANTIC where the screen memory is. A normal display I ist wi II have one LMS instruction at the beginning of the display I l s+j the RAM area it points to provides the screen data for the entire screen ina I i near sequence. By man lpu I at i ng the operand bytes of the LMS instruction, a primitive scroll can be implemented. In effect, this moves the playfield window over the screen data. Thus, by manipulating just 2 address bytes, you can produce an effect identical to moving the entire screen RAM. The fol lowing program does just that:

10 DLIST=PEEK(560)+256*PEEK(561 ):REM 20 LMSLOW=DLIST+4:REM

30 LMSHIGH=DLIST+5:REM

40 FOR 1=0 TO 255:REM

50 POKE LMSHIGH,I

60 FOR J=O TO 255:REM 70 POKE LMSLOW,J -

80 FOR Y=l TO 50:NEXT Y:REM 90 NEXT J

100 NEXT I

Find display list

Get low address of LMS operand Get high address of LMS operand Outer loop

Inner loop

Delay loop

6-1

SCROLLING

This program sweeps the display over the entire address space of the computer. The contents of the memory are a I I dumped onto the screen. The scro I lis a clumsy ser i a I scro I I comb i n i ng hor i zonta I scro I ling with vert i ca I scrol I ing. A pure vertical scrol I can be achieved by adding or subtracting a fixed amount (the line length in bytes) to the LMS operand. The fo I low i ng program does that:

10 GRAPHICS 0

20 DLIST=PEEK(560)+256*PEEK(561) 30 LMSLOW=DLIST+4

40 LMSHIGH=DLIST+5

50 SCREENLOW=O

60 SCREENHIGH=O

70 SCREENLOW=SCREENLOW+40:REM Next line 80 IF SCREENLOI'/<256 THEN GOTO 120:RErVl Overflow?

90 SCREENLOW=SCREENLOW-256:REM Yes, adjust pointer

100 SCREENHIGH=SCREENHIGH+l

110 IF SCREENHIGH=256 THEN END

120 POKE LMSLOW,SCREENLOW

130 POKE LMSHIGH,SCREENHIGH

140 GOTO 70

HORIZONTAL SCROLLING

A pure horizontal scroll is not so simple to do as a pure vertical scroll. The problem is that the screen RAM for a simple display I ist is organ i zed ser i a I I y. The screen data bytes for the lines are strung in sequence, with the bytes for one I ine immediately fol lowing the bytes for the previous I ine. You can horizontally scroll the I ines by shifting all the bytes to the I eft; th is is done by decrement i ng the LMS operand. However, the I eftmost byte on each line wi I I then be scro I led into the rightmost position in the next higher I ine. The first sample program above illustrated this problem.

The solution is to expand the screen data area and brea~ it up into a series of independent horizontal I ine data areas. Figure 6-1 schematically illustrates this idea:

6-2

SCROLLING

............... ~ .

.............. .

.............. .

.............. .

................ .

................. .

............... .

.............. .

normal data arrangement

arrangement for horizontal scrol I

Figure 6-1

Arranging Screen RAM

On the I eft is the norma I arrangement. One-d i mens i ona I ser i a I RAM is

stacked in I i near sequence to create the screen data area. On the right is

the arrangement we need for proper hor i zonta I scro I ling. The RAtJl is of

course still one-dimensional and still serial, but now it ls used d i f ferent I y. The RAr-1 for each hor i zonta I line extends much fu rther than the screen can show. This is no accident; the whole point of scroll ing is to allow a program to display more information than the screen can hold. You can't show a I I that extra in format ion if you don't a I locate the RAr-l to ho I d it. With this arrangement you can implement true horizontal scrol I ing. You can move the screen window over the screen data without the undes i rab Ie vertical rol I of the earl ier approach.

The first step in imp I ement i ng pure hor i zonta I scro I lis to determ i ne the tota I hor i zonta I line I ength and a I locate RAr-1 accord i ng I y. Next, you must write a completely new display I ist with an LMS instruction on each mode line. The display list wil I of course be longer than usual, but there is no reason why you cannot write such a display I ist. What values do you use for the LMS operands? It is most convenient to use the address of the first byte of each horizonta1 screen data I ine. There wi I I be one such address for each mode I ine on the screen. Once the new display I ist is in place, ANTIC must be turned onto it and screen data must be written to populate the screen. To execute a scro I I, each and every LMS operand in the d i sp I ay t i st must be incremented for a rightward scroll or decremented for a leftward scroll. Program logic must ensure that the image does not scrol I beyond the I imits of the allocated RAr-1 areas; otherwise, garbage displays wi II result. In setting up such log i c, the programmer must remember that the LMS operand po i nts to the first screen data byte in the d i sp I ayed line. The max i mum va I ue of the LMS operand is equal to the address of the last byte in the long horizontal I ine minus the number of bytes in one displayed I ine. Remember also that the LMS value should not come within one screen display I ine's length (in bytes) of a 4K address boundary I or the wrong data VI i I I be d i sp I ayed due to L~1S counter rol lover.

As this process is rather intricate, let us work out an example. First, we must se I ect our tota I hor i zonta I line length. We sha I I use a hor i zonta I I ine length of 256 bytes, as this wi II simpl ify address calculations. Each hor i zonta I line 'II i I I then requ ire one page of RArvl. Since we 'II i I I use BAS I C

6-3

SCROLLING

mode 2, there wi I I be 12 mode lines on screen; thus, 12 pages or 3K of RAM wi I I be required. For simpl icity (and to guarantee that our screen RAM wit I be populated with nonzero data), we wi I I use the bottom 3K of RAM. This area is used by the OS and DOS and so shou I d be fu I I of interest i ng data. To make matters more interest i ng, we' I I put the d i sp I ay list onto page 6 so that we can display the display I ist on the screen as we are scrol I ing. The initial va I ues of the LMS operands wi I I thus be part i cu I ar I y easy to ca I cu I ate; the low order bytes wi I I al I be zeros and the high order bytes wit I be (in order) 0, 1, 2, etc. The following program performs all these operations and scrol Is the screen horizontally:

10 REM first set up the display list 20 POKE 1536,112:REM

30 POKE 1537,112:REM

40 POKE 1538,112:REM

50 FOR I =1 TO 12:RD~

60 POKE 1536+3*1,71:REM 70 POKE 1536+3*I+l,0:REM 80 POKE 1536+3*1+2,I:REM 90 NEXT I

100 POKE 1575,65:REM 110 POKE 1576,0:REM

,120 POKE 1577,6 )130 RD~ te II ANTI C where d i sp I ay list is

/140 POKE 560,0

150 POKE 561,6

160 REM now scrol I horizontally

170 FOR 1=0 TO 235:REM Loop through LMS low bytes

175 REM we use 235---not 255---because screen width is 20 characters

180 FOR J= 1 TO 12: RD·1 for each mode line

190 POKE 1536+3*J+l,I:REM Put in new LMS low byte

200 NEXT J

210 NEXT I

220 GOTO 170:REM

8 blank lines 8 blank lines 8 blank lines

Loop to put in display list BAS I C mode 2 with L~1S set Low byte of LMS operand High byte of LMS operand

ANTIC JVB instruction Display I ist starts at $0600

Endless loop

Th i s program scro I I s the data from right to I eft. page is reached, its imp I y starts over at the beg inn i ng. can be found on the sixth I ine down (it's on page 6). sequence of double quotation marks.

.

When the end of a

The d i sp I ay list I t appears as a

The next step is to mix vertical and horizontal scroll ing to get diagonal scroll ing. Horizontal scroll ing is achieved by adding 1 to or subtracting 1 from the LMS operand. Vertical scrol I ing is achieved by adding the line I ength to or subtract i ng the line I ength from the LMS operand. Diagonal scrol I ing is achieved by executing both operations. There are four possible diagonal scroll directions. If, for example, the I ine length is 256 bytes and we wish to scrol I down and to the right, we must add 256+(-1)=255 to each LMS operand in the d i sp I ay list. Th i sis a 2-byte add; the BAS I C program example given above avoids the difficulties of 2-byte address manipulations but most programs wi II not be so contrived. For truly fast

6-4

SCROLLING

two-dimensional scrol I ing, assembly language wi I I be necessary.

All sorts of weird arrangements are possible if we differentially man i pu I ate the LMS bytes. Lines cou I d scro I I re I at i ve to each other or hop over each other. Of course, some of this could be done with a conventional display but more data would have to be moved to do it. The real advantage of LMS scroll ing is its speed. Instead of manipulating an entire screenful of data, many thousands of bytes in size, a program need only manipulate two or perhaps a few dozen bytes.

FINE SCROLLING

The second important scrolling facility of the ATARI Computer is the fine scro I ling capab iii ty. Fine scro I ling is the capab iii ty of scro I ling a pi xe lin steps sma I I er than the pi xe lsi ze. <Throughout th is sect i on the term pi xe I refers to an ent i re character, not to the sma I I er dots that make up a character.) Coarse scrol Is proceed in steps equal to one pixel d i mens ion; fine scro II s proceed insteps of one scan line vert i ca 1,1 y and one color clock horizontally. Fine scroll ing can only carry so far; to get full fine scrol I ing over long distances on the screen you must couple fine scrol I ing with coarse scrol ling.

There are on I y two steps to imp I ement fine scro I ling. First, you set

the fine scroll enable bits in the display I ist instruction bytes for the mode lines in wh i ch you want fine scro I ling. ( I n most cases you want the ent i re screen to scro I I so you set a I I the scro I I enab Ie bits ina I I the display I ist instruction bv+es • ) Bit 05 of the display I ist instruction is the vertical scrol I enable bit; bit 04 of the display I ist instruction is the hor i zonta I scro I I enab l e bit. You then store the scro I ling va I ue you des ire into the appropriate scroll ing register. There are two scroll ing registers, one for hor i zonta I scro I ling and one for vert i ca I scro I ling. The hor i zonta I scro I I reg i ster (HSCROL) is at $0404; the vert i ca I scro I I reg i ster (VSCROL) is at $0405 • For hor i zonta I scro I ling, you store into HSCROL the number of color clocks by which you want the mode line scrol led. For vertical scro I ling, you store into VSCROL the number of scan lines that you want the mode I ine scrolled. These scroll values wi II be appl ied to ,every I ine for wh i ch the respect i ve fine scro l l is enab led.

There are two compl icating factors that you encounter when you use fine scroll ing. Both arise from the fact that a partially scrolled display shows more information than a normal display. Consider for example what happens when you hor i zonta I I Y scro I I a line by ha I f a character to the I eft. There are 40 characters in the I ine. Half of the first character disappears off of the I eft edge of the screen. The 40th character scro I I s to the I eft. What takes its p I ace? Ha I f of a new character shou I d scro I lin to take the p I ace of the now scrol led 40th character. This character would be the 41st character. But there are only 40 characters in a normal I ine. What happens?

I f you have implemented coarse scroll ing, then the 41st character sudden I y appears on the screen after the first character disappears of f of the left edge. This sudden appearance is jerky and unsightly. The solution

6-5

SCROLLING

to th is prob I em has a I ready been bu i It into the hardware. There are three display options for I ine widths: the narrow playfield (128 color clocks wide), the normal playfield (160 color clocks wide) and the wide playfleld

(192 color clocks wide). These options are set by setting appropriate bits

in the DMACTL register. When using horizontal fine scrol I ing, ANTIC

automatically retrieves more data from RAM than it displays. For example, if DMACTL is set for norma I pi ayf i e I d , wh i ch in BAS I C mode 0 has 40 bytes per line, then ANTI C wi I I actua I I Y retr i eve data at a rate appropr i ate to wide playfield---48 bytes per I ine. This wi II throw I ines off horizontally if it is not taken into account. The problem does not manifest itself if the you have already organized screen RAM into long horizontal I ines as in Figure 6-1.

The correspond i ng prob I em for vert i ca I scro I ling can be hand I ed in either of two ways. The sloppy way is to ignore it. Then you wi I I not get half-images at both ends of the display. Instead, the images at the bottom of the display will not scroll in proper l vj they will suddenly pop into view. The proper way takes very I ittle work. To get proper fine scrol I ing into and out of the display region you must dedicate one mode I ine to act as a buffer. You do this by refraining from setting the vertical scrol I bit in the display I ist instruction of the last mode I ine of the vertically scrol led zone. The window wil I now scrol I without the unpleasant jerk. The screen image wi I I be shortened by one mode line. An advantage of scro I ling d i sp I ays now becomes apparent. It is qu i te poss i b I e to create screen i mages that have more than 192 scan lines in the d i sp I ay • Th i s cou I d be disastrous with a stat i c display, but with a scroll ing display images which are above or below the displayed region can always be scrol led into view.

Fine scroll ing wi II only scroll so far. The vertical I imit for fine

scroll ing is 16 scan I l nes j the horizontal I imit for fine scroll ing is 16 color clocks. If you attempt to scroll beyond these I imits, ANTIC simply ignores the higher bits of the scroll registers. To get full fine scrolling (in which the entire screen smoothly scrolls as far as you wish) you must couple fine scroll ing with coarse scrolling. To do this, first fine scroll the image, keeping track of how far it has been scrol led. When the amount of fine scro I ling equa I s the size of the pi xe I, reset the fine scro I I reg i ster to zero and execute a coarse scrol I. Figure 6-2 illustrates the process.

6-6

E
E E E E
start fine fine fine fine fine fine fine reset and
position scroll scroll scroll scroll scroll scroll scroll to coarse
once twice thrice four five six seven start scroll
times times times times position SCROLLING

one step

--_ .... --- .... _---

(- ,

Figure 6-2 Linking Fine Scrol I to Coarse Scrol I

The fol lowing program I I lustrates simple fine scrol ling:

1 HSCROL=54276 2 VSCROL=54277

10 GRAPHICS O:LIST

20 DLIST=PEEK(560)+256*PEEK(561) 30 POKE DLIST+l0,50:REM

40 POKE DLIST+ll,50:REM

50 FOR Y=O TO 7

60 POKE VSCROL, Y:Rn1 70 GOSUB 200:REM

80 NEXT Y

90 FOR X=O TO 3

100 POKE HSCROL,X:REM 110 GOSUB 200:REM

120 NEXT X

130 GOTO 40

200 FOR J=l TO 200 210 NEXT J:RETURN

Enable both scrol Is

Do It for two mode lines

Vertical scroll Delay

Horizontal scrol I Delay

Th is program shows fine scro I I I ng tak I ng p I ace at very s low speed. It demonstrates severa I prob I ems that ar I se when us I ng fine scro I I I ng . First, the display I ines below the scrolled window are shifted to the right. This Is due to ANTIC's automatically retrieving 48 bytes per line Instead of 40. The problem arises only in unrealistic demonstration programs such as this one. I n rea I scro I I I ng app I i cat Ions, the arrangement of the screen data (as shown in Figure 6-1) precludes this problem. The second, more serious

6-7

SCROLLING

prob I em ar i ses when the scro I I reg i sters are mod i f i ed wh i I e ANTI Cis in the middle of its display process. This confuses ANTIC and causes the screen to jerk. The so I ut ion is to change the scro I I reg i sters on I y du ring vert i ca I blank periods. This can only be done with assembly language routines. Thus, fine scro II i ng norma II y requi res the use of assemb I y language.

APPLICATIONS OF SCROLLING

The app I i cat ions of fu I I fine scro I ling for graph i cs are numerous. The obvious appl ication is for large maps that are created with character graphics. Using BASIC Graphics mode 2, I have created a very large map of Russ i a wh i ch conta i ns about 10 screen fu I s of image. The screen becomes a window to the map. The user can scrol I about the entire map with a joystick. The system is very memory efficient; the entire map program plus data plus d i sp I ay list and character set def in it ions requ i res a tota I of about 4K of RAM.

There are many other app I i cat ions of th is techn i que. Any very large

image that can be drawn with character graphics Is amenable to this system. (Scrol I ing does not require character graphics. Map graphics are less desirable for scroll ing appl ications because of their large memory requ I r-emen+s , ) Large electron i c schemat i cs cou I d be presented in th is way. The joystick could be used both to scroll around the schematic and to indicate particular components that the user wishes to address. Large blueprints or architectural diagrams could also be displayed with this techn i que. Any big i mage that need not be seen in its ent I rety can be presented with this system.

Large blocks of text are also usable here, although it might not be

practical to read continous blocks of text by scroll ing the Image. This

system Is more suited to presenting blocks of independent text. One

particularly exciting idea is to apply this system to menus. The program starts by present i ng a we I come sign on the screen with signs i nd i cat i ng submenus po i nt i ng to other reg Ions of the larger image. "Th I s way to addition" could point up while "this way to subtraction" might point down. The user scrolls around the menu with the joystick, perusing .h I s options. When he wishes to make a choice, he places a cursor on the option and presses the red button. A I though th is system cou I d not be app lied to a I I programs, it could be of great value to certain types of programs.

There are two "blue sky" appl ications of fine scrolling which have not yet been fully explored. The first is selective fine scroll ing, in which different mode I ines of the display have different scroll bits enabled. Normally you would want the entire screen to scrol I, but it is not necessary to do so. You cou I d se I ect one I I ne for hor i zonta I scro I ling on I y, another I ine for vertical scrol I ing only, and so forth. The second blue sky feature is the prospect of us i ng d i sp I ay list interrupts to change the HSCROL or VSCROL registers on the fly. However, changing VSCROL on the fly is a tricky operation; it would probab.ly confuse ANTIC and produce undesirable results. Changing HSCROL is also tricky but might be easier.

6-8

7 SOUND

The ATARI 400/800T" Home Computers have extens ive hardware sound capabi I l r l es . There are four independently controllable sound channels, all able to play simultaneously. Each channel has a frequency register determ in i ng the note, and a contro I reg i ster regu I at i ng the vo I ume and the noise content. Several options al low you to insert high-pass fi Iters, choose clock bases, set alternate modes of operation, and modify polynomial counters.

DEFINITION OF TERMS AND CONVENTIONS

For the purposes of this discussion, a few terms and conventions need to be c I ar i fi ed :

Hz (Hertz)

KHz (k i I o-Hertz) MHz (mega-Hertz)

is 1 pulse per second

is 1,000 pulses per second

is 1,000,000 pulses per second

A "pulse" is a sudden voltage rise followed somewhat later by a sudden voltage drop. If a pulse is sent to the television speaker, it will be heard as a single pop.

A "wave" as used here is a cont i nuous ser i es of pu I ses. There are different types of waves, distinguished by the shape of the individual pulses. \'laves created by the ATARI Computer are square waves (as in Figure 7-2). Brass instruments typ i ca I I Y produce tr i ang I e waves, and a singer produces sine waves (depicted in Figure 7-15).

A shift register is like a memory location (in that it holds binary data) that, when so instructed, shifts all its bits to the right one position; i.e., bit 5 wi II get whatever was in bit 4, bit 4 wi II get whatever was in bit 3, etc. Thus, the rightmost bit is pushed out, and the leftmost bit assumes the value on its input wire (see Figure 7-1).

before shift

1

2

3

4

5

input

output

after shift

1

2

3

4

5

Figure 7-1 Diagram of Bit Flow of a Shift Register

7-1

AUOF 1-4 is to be read, "any of the aud i 0 frequency reg i sters, 1 through 4." Their addresses are: $0200, $0202, $0204, $0206 (53760, 53762, 53764, 53766).

AUOC1-4 is to be read, "any of the aud i 0 contro I reg i sters, 1 through 4." Their addresses are: $0201, $0203, $0205, $0207 (53761, 53763, 53765,53767).

For the purposes of this discussion, frequency is a measure of the number of pulses in a given amount of time; i.e., a note with a frequency of 100 Hz means that in one second, exact I y 100 pu I ses wi I I occur. The more frequent (hence the term. "frequency") the pu I ses of a note, the higher the note. For example, a singer sings at a high frequency (perhaps 5 KHz), and a cow moos at a low frequency (perhaps 100 Hz). The words "frequency," "note," "tone," and "pitch" are used interchangeably.

"Noise" and "distortion" are used interchangeably although their meanings are not the same. "Noise" is a more accurate description of the function performed by the ATARI Computer.

The 60-Hz interrupt referred to later in this section is also cal led the vertical blank interrupt.

All examples are in BASIC unless otherwise stated. Type the examples exactly as they appear. If there are no line numbers, don't use any; and if several statements are on the same I ine, type them as such.

SOUND HARDWARE

Sound is generated in the ATARI computer by the POKEY chip, which also hand I es the ser i a I I/O bus and the keyboard. The POKEY ch i p must be initial ized before it wi II work properly. Initial ization is required after

any serial bus operation (cassette, disk drive, printer, or RS-232

read/write). To initial ize POKEY in BASIC, execute a null sound statement;

i.e., SOUND 0,0,0,0. In machine language, store a 0 at AUOCTL ($0208 = 53768), and a 3 at SKCTL ($020F = 53775, shadowed at $232 = 562):

AUOF1-4

Each audio channel has a corresponding frequency register that controls the note played by the computer. The frequency register contains the number "N" used in a divide-by-N circuit. This divide is not a division in the mathematical sense, but rather something much simpler: for every N pulses coming in, 1 pulse goes out. For example, Figure 7-2 shows a divide-by-4 function:

7-2

Input
pulses
I I I
output Jl n n n
pulses
Figure 7-2 Dlvlde-by-4 Operation As N gets larger, output pu I ses w I I I become I ess frequent, mak I ng a lower frequency note.

AUDCl-4

Each channe I a I so has a correspond I ng contro I reg I ster. These

registers al low the volume and distortion content of each channel to be set. The bit assignment for AUDCl-4 Is as fol lows:

AUDCl-4

7

3

o

bit number

5

vol only

4

vo I ume

distortion

Figure 7-3 AUDCl-4 Bit Assignment

Vo I ume

The vo I ume contro I for each aud 10 channe I Is stra I ghtforward. The

lower 4 bits of the audio control register contain a 4-bit number that specifies the volume of the sound. A zero in these bits means zero volume, and a 15 means as loud as possible. The sum of the volumes of the four channels should not exceed 32, since this forces overmodulatlon of the audio output. The sound produced tends to actua I I Y lose vo I ume and assume a buzzing quality.

Distortion

Figure 7-3 shows that each channel also has three distortion control

bits in Its aud i 0 contro I reg I ster. 0 i stort i on I s used to create spec i a I

sound effects any time a pure tone is undesirable.

The computer's use of distortion offers great versatil ity and

control I ab I I Ity. It Is easy to synthesize of an almost endless variety of

7-3

~)

sounds, from rumbles, rattles, and squawks to cl l ck s , whispers, and mood setting background tempos.

Distortion as used here is not equivalent to the standard interpretation. For example, "intermodulation distortion" and "harmonic distortion" are qual ity criteria specified for high-fidel ity stereo systems. These types of distortion refer to waveform degeneration, where the shape of the wave is sl ightly changed due to error in the electronic circuitry. The computer's distortion does not alter waves (they are always square waves), but rather deletes selected pulses from the waveform. This technique is not adequately characterized by the word "distortion." A more descriptive and appropriate term for these distortion methods is "noise".

Before you can fu I I Y grasp what we mean by distort ion, you must understand po I ynom i a I counters ( po I v-coun+er s) . Po I y counters are emp loyed in the ATARI Computer as a source of random pulses used in noise generation. The ATARI Computer's poly-counters util ize a shift register working at 1.79 ~1Hz. The shift register's contents are shuffled and fed back into the input; this produces a semi-random sequence of bits at the output of the shift register.

For example, in the diagram below, the old value of bit 5 wi II be pushed out of the shift register to become the next output pulse, and bit 1 wi I I become a function of bits 3 and 5:

shift register

random pulses

bit processor

Figure 7-4 5-Bit Poly-Counter

The bit processor gets values from certain bits in the shift register (bits 3 and 5 above), and processes them in a way irrelevant to this discussion. It yields a value that becomes bit 1 of the poly-counter's shift register.

These poly-counters are not truly random because they repeat their bit sequence after a certain span of time. As you might suspect, their repetition rate depends upon the number of bits in the poly-counter; i.e.,

7-4

the longer ones requ ire many cyc I es before they repeat, wh i I e the shorter ones repeat more often.

On the ATARI Computer, distortion is achieved by using random pulses from these poly-counters in a selection circuit. This circuit is actually a digital comparator, but "selection circuit" is more descriptive. The only pu I ses mak i ng it through the se I ect i on c i rcu it to the output are those

coinciding with a random pulse. Various pulses from the input are thereby

el iminated in a random fashion. Figure 7-5 illustrates this selection

method. A dotted I ine connects pulses that coincide.

poly-counter's random pulses

tone pulses from freq. divider

pulses that make it through

Figure 7-5 Selection Function Used To Mix In Distortion

The net effect is this: some pulses from the frequency divider circuit

are deleted. Obviously, if some of the pulses are deleted, the note wi II

sound different. This Is how distortion is introduced into a sound channel.

Because poly-counters repeat their bit sequences, their output pattern of pulses Is cycl lc , And since the selection circuit uses this output pattern to delete pulses from the original note, the distortetl note wi II contain the same repetitious pattern. This allows the hardware to create noises such as drones, motors, and other sounds having repetitive patterns.

The ATARI Computer is equipped with three poly-counters of different lengths, which can be combined in many ways to produce interesting sound effects. The smaller poly-counters (4 and 5 bits long) repeat often enough to create droning sounds that rise and fall quickly; whi Ie the larger po I y-counter (17 bits long) takes so long to repeat that no pattern to the distort i on can be read i I Y discerned. Th i s 17-b it po I y-counter can be used to generate exp I os Ions, steam, and any sound where random crack ling and popping is desired. It is even irregular enough to be used to generate white noise (an audio term meaning a hissing sound).

Each audio channel offers six distinct combinations of the three

7-5

poly-counters:

AUDCl-4

d v clock by freq, select using 5 bit then 17 bit polys, div by 2
d v clock by freq, select using 5-bit poly, then div by 2
d v clock by freq, select using 5-bit then 4 bit polys, div by 2
d v clock by freq, select using 17 -b i t po I Y , div by 2
d v clock by freq, then div by 2 (no poly-counters)
d v clock by freq, select using 4 bit poly, div by 2 Notes: "Clock" means the input frequency.

An "X" means, "it doesn't matter if this bit is set or

not."

Figure 7-6 Avai lable Poly-Counter Combinations

These upper AUDCl-4 bits control three switches in the audio circuit as shown below. This diagram wil I help you understand why the table of Figure 7-6 is structured as it is:

7-6

AUDCTL bit no.

6

I

14 bit poly 1-1 -----e.

17 bit poly

5 bit poly

selection circuit

input from div. by

7

5

selection circuit

to TV speaker

Figure 7-7 AUDC1-4 Block Diagram

Each combination of the poly-counters offers a unique sound.

Furthermore, the distorted sounds can sound quite different at different frequenc i es. For th is reason some tr i a I and error is necessary to find a combination of distortion and frequency that produces the desired sound effect. Below is a table of guides, just to get you started:

AUDC1-4

low frequencies middle frequencies high frequencies

geiger counter raging fire rushing air steam

machine gun auto at idle electric motor power transformer

calm fire laboring auto auto with a "miss"

bui Iding crashing in radio interference waterfal I

pure tones

air lane lawn mower electric razor

Figure 7-8

Sounds Produced by Distortion Combinations at Several Frequencies

7-7

Volume Only Sound

Bit 4 of AUDC1-4 specifies the volume only mode. When this bit is set, the volume value in AUDC1-4 bits 0-3 is sent directly to the television speaker; it is not modu I ated with the frequency spec if i ed in the AUDF 1-4 registers.

To fu I I Y understand the use of th i s mode of operat ion, you must understand how a speaker works and what happens to the te I ev is i on speaker when it rece i ves a pu I se. Any speaker has a cone that moves in and out. The cone's position at any time is directly proportional to the voltage it is rece i vi ng from the computer at that time. I f the vo I tage sent is zero, then the speaker is in the rest i ng pos it i on. Whenever the cone changes position, it moves air that is detected by your ear as sound.

From our definition of a pulse, you know that it consists of a rising vo I tage fo I lowed by a fa I ling vo I tage. I f you were to send the speaker a pulse, it would push out with the rising voltage and pull back with the fal I ing voltage, resulting in a wave of air that can be detected by your ear as a pop. The fol lowing statements wi I I produce such a pop on the television speaker by sending a single pulse:

POKE 53761,31:POKE 53761,16

A stream of pu I ses (or wave) wou I d set the speaker into constant motion, and a continuous buzz or note would be heard. The faster the pulses are sent, the higher the note. This is how the computer generates sound on the television speaker.

It Is essential to note that in the volume only mode the volume sent does not drop back to zero automatically, but rather remains constant until the program chqnges it. The program should modulate the volume often enough to create a no i se. Now try the fo I low i ng statements, listen i ng carefu I I Y after each:

POKE 53761,31 POKE 53761,31

The first time you heard a pop, wh i ch is as expected. The speaker pushed out and moved air. But the second time you didn't. This is because the speaker cone was a I ready in the extended pos it ion; another extens ion command did noth i ng to the speaker, mov i ng no air, so you heard noth i ng. Now try this:

POKE 53761,16 POKE 53761,16

7-8

Just as before, you heard a pop the first time as the speaker moved back to its resting position, and you heard nothing the second time because the speaker was already in the resting position.

Thus, the volume only bit gives the program complete control over the position of the speaker at any time. Although the examples given above are only binary examples (either on or off), you are by no means I imited to this type of speaker modu I at ion. You may set the speaker to any of 16 d i st i nct positions.

For example, a simple triangle wave (similar to the waveform produced by brass instruments) cou I d be generated by send i ng a vo I ume of 8 fo I lowed by 9,10,11,10,9,8,7,6,5,6,7, and back to 8, and repeating this sequence over and over very rapidly. By changing the volume quickly enough, vi rtua I I Y any waveform can be created. It is feas i b Ie, for examp Ie, to perform voice synthesis using this technique. It requires the use of assembly language. There is more discussion of this bit in a later section.

AUDCTL

In addition to the independent channel control bytes (AUDCl-4), there is an option byte (AUDCTL> affecting all four channels. Each bit in AUDCTL is assigned a specific function:

AUDCTL ($0208 = 53768)

if set, this bit •••

switches main clock base from 64 KHz to 15 KHz

inserts high-pass fi Iter into chan 2, clocked by chan 4 ~--_'inserts high-pass fi Iter into chan 1, clocked by chan 3 ~----_'joins channel 4 to channel 3 (16 bit resolution) ~-------'joins channel 2 to channell (16 bit resolution) ~--------+Clocks channel 3 with 1.79 MHz

-------------.clocks channell with 1.79 ~1Hz

~------------_'~akes the 17 bit poly-counter into a 9 bit poly-counter

Figure 7-9 AUDCTL Bit Assignment

Clocking

Before proceeding with the explanations of the AUDCTL options, a new concept must be explained: clocking. In general, a clock is a train of pulses used to synchronize the m l II ions of internal operations occurring every second in any computer. The central clock pulses continuously, each pulse tel I ing the circuitry to perform another step in its operations. You may remember that a d I vi de-by-N frequency d i vi der outputs one pu I se for every Nth input pu I se. You may have wondered where the input pu I ses come from. There is one main input clock running at 1.79 MHZ; it can provide the

7-9

)

input pulses. There are also several secondary clocks that can be used as input clocks. The AUDCTL register al lows you to select which clock is used as the input to the divide-by-N circuit. If you select a different input clock, the output from the frequency divider wi I I change drastically.

For example, imagine that you are using the 15 KHz clock, and the frequency register is set to divide by 8. The rate of output pulses from the d i v i de-by-N c i rcu it \'IOU I d be about 2 KHz. But if you changed. the selection of clocks to get the 64 KHz clock and did not change the frequency reg i ster, then what wou I d happen? The d i vi de-by-N wou I d st i I I be putt i ng out one pulse for every 8th input pulse, but the input rate would be 64 KHz. The result is an output frequency (from the divide-by-N) of 8 KHz.

The formula for the output frequency (from the d l v l de-bv-N) is quite simple:

clock

output frequency =

N

Setting bit 1 of the AUDCTL register switches from the 64-KHz clock to the 15 KHz clock. It is important to note that if th is bit is set, every sound channe I clocked with the 64 KHz clock wi I I instead use the 15 KHz clock. Similarly, by setting bits 5 or 6, you can clock channels 3 or 1, respectively, with 1.79 MHz. This wi II produce a much higher note, as demonstrated with the fol lowing example:

SOUND 0,255,10,8 POKE 53768,64

Turn on channell, low tone Set AUDCTL bit 6

16-Bit Frequency Options

The eight bits of resolution in the frequency control registers seems to prov i de more than adequate reso I ut i on for the task of se I ect i ng any desired frequency. There are, however, situations in which eight bits are inadequate. Consider for example what happens when we execute the fol lowing statements:

FOR 1=255 TO 0 STEP -1:S0UND 0,1,10,8:NEXT I

The sound in it i a I I Y rises smooth I y, but as it approaches the end of its range the frequency takes larger and larger steps which are noticeably clumsy. Th i sis because we are d i vi ding the clock by sma I I er and sma I I er numbers. 15 KHz divided by 255 is almost the same as 15 KHz divided by 254; but 15 KHz divided by 2 is very far from 15 KHz divided by 1. The only way to solve this problem is to use a larger number that allows us to specify our frequency with greater precision. The means to do this is built into

7-10

POKEY.

AUDCTL bits 3 and 4 al low two channels to be joined, creating a single channe I with an extended dynam i c frequency range. Norma I I y, each channe I "s frequency divider number can range from 0 to 255 (8 bits of divide-by-N capabi I ity). Joining two channels allows a frequency range of 0 to 65535 (16 bits of divide-by-N capability). In this mode, it is possible to reduce the output frequency to less than one Hertz. The fol lowing program uses two channels in the 16-bit mode, and two paddles as the frequency inputs. Insert a set of paddles into port 1, type in and run the fol lowing program:

10 SOUND 0,0,0,0 Initial ize sound

20 POKE 53768,80 Clock ch1 w 1.79 MHz, clock ch2 w ch1

30 POKE 53761,160:POKE 53763,168 Turn off ch1, turn on ch2 (pure tones) 40 POKE 53760,PADDLE(0):POKE 53762,PADDLE(1)

50 GOTO 40 set paddles to put freqs in freq regs

The right paddle tunes the sound coarsely, and the left paddle finely tunes the sound between the coarse increments.

Th i s program first sets bits 4 and 6 of AUDCTL wh i ch means, "c lock channel 1 with 1.79 MHz, and join channel 2 to channelL" Once this happens, the 8-bit frequency registers of both channels are assumed to represent a single 16-bit number N, used to divide the input clock. Next, channell's volume is set to zero. Since channel 1 no longer has its own direct output, its vo I ume sett i ng is mean i ng I ess to us and we zero it. Channell's frequency register is used as the fine or low byte In the sound generation, and channel 2's frequency register is the coarse or high byte. For example, pokeing a 1 into channell's frequency register makes the pair d i v i de by 1. Poke i ng ali nto channe I 2' s frequency reg i ster makes the pa i r divide by 256. And pokeing a 1 into both frequency registers makes the pair divide by 257.

\

/

Bit 3 of AUDCTL can be used to join channel 4 to channel 3 in precisely the same way.

The fo I low i ng instruct ions demonstrate some interest i ng aspects of 16-bit sound.

7-11

SOUND 0,0,0,0 POKE 53768,24 POKE 53761,168 POKE 53763,168 POKE 53765,168 POKE 53767,168

POKE 53760,240:REM try pokeing other numbers into these next 4 locations POKE 53764,252

POKE 53762,28

POKE 53766,49

High-Pass Fi Iters

AUDCTL bits 1 and 2 contro I high-pass f i I ters in channe I s 2 and 1 respect i ve I y. A high-pass f i I ter a II ows on I y higher frequenc i es to pass through. In the case of these high-pass fi Iters, high frequencies are defined to be anything higher than the output of another channel selected by the AUDCTL bit combination. For example, if channel 3 is playing a cow's moo, and AUDCTL bit 2 is set, then only sounds with frequencies higher than the moo wi I I be heard on channe I 1 (anyth i ng lower than the "moooo" wi I I be f i I tered out):

f r e q

cow's moo (played by channel 3)

)

/

channel 1

__ I"'--"'--JU... __ .....L w i I I on I y play frequencies in

,.....,__,.,......---r----- th i s shaded area

time

Figure 7-10

The Effect of a High-Pass Fi Iter Inserted in Channel 1 and Clocked by Channel 3

The fi Iter is programmable in real time since the fi Itering channel can be changed on the fly. This opens a large field of pos s lb l I ities to the programmer. The fi Iters are used mostly to create special effects. Try the fol lowing statements:

7-12

SOUND 0,0,0,0 POKE 53768,4

POKE 53761,168:POKE 53765,168 POKE 53760,254:POKE 53764,127

9-Bit Polynomial Conversion

Bit 7 of AUDCTL turns the 17-bit poly-counter into a 9-bit po I y-counter. The shorter the po I y-counter, the more often its distort i on pattern repeats, or the more discern i b I e the pattern in the distort i on. Therefore, changing the 17-bit poly counter into a 9-bit poly counter will

make the noise pattern more repetitious and more discernible. Try the

fo I low i ng demonstrat i on of the 9-b it po I y counter opt ion, listen i ng

carefully when the POKE is executed:

SOUND 0,80,8,8 POKE 53768,128

Use the 17-bit poly Change to the 9-bit poly

7-13

SOUND GENERATION SOFTWARE TECHNIQUES

There are two bas ic ways to use the ATAR I Computer sound system: static and dynamic. Static sound generation is the simpler of the two; the program sets a few sound generators, turns to other activities for a whl Ie, and then turns them off. Dynamic sound generation is more difficult; the computer must continuously update the sound generators during program execution. For example:

Static Sound

Dynamic Sound

SOUND 0,120,8,8

FOR X=O TO 255 SOUND 0,X,8,8 NEXT X

Static Sound

Static sound is normally I imited to beeps, cl icks, and buzzes. There are exceptions. Two examples are the programs given as special effects in the sect ions on high-pass f i I ters and 16 bit sound. Another way to obta in interesting effects is to use interference, as in this example:

SOUND 0,255,10,8 SOUND 1,254,10,8

The strange effect is a result of closely phased peaks and valleys.

Examine Figure 7-11. It shows two channels independently running sine waves at sl ightly different frequencies, and their sum. The sum curve shows the strange interference pattern created when these two channels are added.

7-14

ch.1

ch.2

ch.1 + ch.2

+

+

+

pos. + neg. = 0

'--------------. neg. + neg. = double neg..

'--- ---. pos. + pos. = double pos.

Figure 7-11

Two Sine Waves at Different Frequencies and Their Sum

7-15

Figure 7-11 shows that at some points in time the waves are assisting each other, and at other points, they interfere with each other. Adding the volumes of two waves whose peaks coincide wil I yield a wave with twice the strength or volume. Simi larly adding the volumes of two waves while one is at maximum and the other is at minimum wi I I result in a cancellation of both of them. On the graph of the sum curve, we can see this effect. Toward the ends of the graph, volume increases since both channels' peaks and valleys are close together, almost doubl ing the sound. Toward the middle of the graph, the waves oppose each other and the resu It i ng wave is f I at. An interesting project might be writing a program to plot interaction patterns of 2, 3, and 4 channels as in Figure 7-11. You might discover some unique sounds.

The sl ighter the difference in frequency between the two channels, the longer the pattern of repetition. To understand this, draw some graphs simi lar to Figure 7-11 and study the interaction. As an example, try the fol lowing statements:

SOUND 0,255,10,8 SOUND 1,254,10,8 SOUND 1,253, 10,8 SOUND 1,252,10,8

As the difference in frequency grows, the period of repitltion decreases.

Dynamic sound

More complex sound effects normally require the use of dynamic sound techniques. Three methods of dynamic sound generation are available to the ATARI 400/800 programmer: sound In BASIC, 60-Hz Interrupt sound, and sound in machine code.

BASIC Sound

BASIC is somewhat I imited in its handl ing of sound generation. As you may have not iced, the SOUND statement k i I I s any spec i a I AUDCTL sett I ng • This problem can be avoided by poking values directly into the sound registers rather than using the SOUND statement.

In addition, BASIC is I imlted on account of its speed. If the program is not completely dedicated to sound generation, there Is seldom enough processor time to do more than static sound or choppy dynamic sound. The only alternative is to temporarily halt al I other processing while generating sound.

7-16

Another problem can occur when using the computer to play music on more than one channe I. I f a I I four channe I s are used, the time separat ion between the first sound statement and the fourth can. be substant i a I enough to make a noticeable delay between the different channels.

The fol lowing program presents a solution to this problem:

10 SOUND O,O,O,O:DIM SIMUL$(16) 20 RESTORE 9999:X=1

25 READ Q:IF Q<>-l THEN SIMUL$(X)=CHR$(Q):X=X+l:GOTO 25 27 RESTORE 100

30 READ Fl,Cl,F2,C2,F3,C3,F4,C4 40 IF Fl=-l THEN END

50 X=USR(ADR(SIMUL$),Fl,Cl,F2,C2,F3,C3,F4,C4) 55 FOR X=O TO 150:NEXT X

60 GOTO 30

100 DATA 182,168,0,0,0,0,0,0

110 DATA 162,168,182,166,0,0,0,0

120 DATA 144,168,162,166,35,166,0,0 130 DATA 128,168,144,166,40,166,35,166 140 DATA 121,168,128,166,45,166,40,166 150 DATA 108,168,121,166,47,166,45,166 160 DATA 96,168,108,166,53,166,47,166 170 DATA 91,168,96,166,60,166,53,166 999 DATA -1,0,0,0,0,0,0,0

9000 REM

9010 REM

9020 REM this data contains the machine lang. program, 9030 REM and is read into SIMUL$

9999 DATA 104,133,203,162,0,104,104,157,0,210,232,228,203,208,246,96,-1

)

In this program, SIMUL$ is a tiny machine language program that pokes all four sound channels very quickly. A BASIC program using SlfvlUL$ can rapidly manipulate all four channels. Any program can call SIMUL$ by putting the sound register values inside the USR function in line 50 of the demonstration program. The parameters should be ordered as shown, with the control register value fol lowing the frequency register value, and repeating this ordering one to four times, once for each sound channel to be set.

As a speed consideration as wei I as a convenience, SIMUL$ al lows you to specify sound for less than four channels; i.e., 1,2, and 3 or 1 and 2, or just channel 1. Simply don't put the unused parameters inside the USR function.

SIMUL$ offers another distinct advantage to the BASIC programmer. As mentioned earl ier, the AUDCTL register is reset upon execution of any SOUND statement in BASIC. However, using SIMUL$, no SOUND statements are

7-17

executed, and thus the AUDCTL setting is retained.

There is another, but impractical, method of sound generation in BASIC.

Th i s method uses the vo I ume-on I y bit of any of the fou r aud i 0 contro I registers. Type in and run the fol lowing program:

SOUND 0,0,0,0

10 POKE 53761 ,16:POKE 53761,31:GOTO 10

This program sets the volume-only bit in channel 1 and modulates the

volume from 0 to 15 as fast as BASIC can. This program uses all of the

processing time avai lable to BASIC, yet it produces only a low buzz.

60-Hz Interrupt

This technique is probably the most versati Ie and practical of all methods avai lable to the ATARI Computer programmer.

Precisely every 60th of a second, the computer hardware automatically generates an interrupt. When th is happens, the computer temporar i I Y I eaves the mainl ine program, (the program running on the system; i.e., BASIC, STAR RAIDERS~). It then executes an interrupt service routine, which is a smal I routine designed specifically for servicing these interrupts. When the interrupt service routine finishes, it executes a special machine language instruction that restores the computer to the interrupted program. This al I occurs in such a way (i f done proper I y) that the program execut i ng I s not affected, and in fact has no idea that it ever stopped!

The interrupt service routine currently resident on the ATARI 400/800 Computer simply maintains timers, translates controller information, and performs miscellaneous other chores requiring regular attention.

Before the interrupt service routine returns to the mainl ine program, it can be made to execute any user routine; i.e., your sound generation routine. This is ideal for sound generation since the timing is precisely controlled, and especially since another program can be executing without paying heed to the sound generator. Even more impressive is its versat iii ty. Because it is a mach i ne I anguage program, the interrupt sound program wi II lend itself equally well to a mainl ine program written in any language - BASIC, assembler, FORTH, PASCAL. In fact, the sound generator Vi i I I requ ire few, if any, mod i f i cat ions to work with another program or even another language.

A table-driven routine offers maximum flexibility and simplicity for such a purpose. "Tab I e-dr I ven" refers to a type of program that accesses data tables In memory for its informction. In the case of the sound generator, the data tab I es wou I d conta I n the frequency va I ues and poss I b I Y the aud 10 contro I reg i ster va lues. The rout I ne wou Ids I rnp I y read the next entries in the data table, and put them into their respective audio

7-18

reg I sters • Us i ng th i s method, notes cou I d change as often as 60 times per second, fast enough for most appl ications.

Once such a program has been wr i tten and p I aced in memory (say, at I ocat I on $600), you need to i nsta I lit as a part of the 60-Hz interrupt service routine. This Is accompl ished by a method known as vector steal ing.

Memory I ocat ions $224, $225 conta in the address of a sma I I rout i ne called XITVBL (eXIT Vertical BLank Interrupt service routine). XITVBL is designed to be executed after all 60-Hz Interrupt processing is complete, restoring the computer to the mainl ine program as previously discussed.

The procedure to instal I your sound routine is as fol lows:

1. Place your program in memory.

2. Verify that the last Instruction executed Is a JMP $E462

($E462 Is XITVBL, so this wil I make the mainl ine program continue).

3. Load the x register with the high byte of your routine's address (a 6 In this case).

4. Load the y register with the low byte of your routine's address (a 0 In this case).

5. Load the accumulator with a 7.

6. Do a JSR $E45C (to set locations $224,$225).

Steps 3-6 are a I I requ i red to change the va I ue of $224, $225 without error. The routine called Is SETVBV (SET Vertical Blank Vectors), which wi I I simply put the address of your routine Into locations $224,$225. Once instal led, the system wi I I work as fol lows when an interrupt occurs:

1. The computer's Interrupt routine is executed.

2. It jumps to the program whose address is in $224,$225, which is

now your routine.

3. Your routine executes.

4. Your routine then jumps to XITVBL.

5. XITVBL restores the computer and makes It resume normal operation.

If you do not wish to implement such a program yourself, there is one ava II ab I e from the Atar i Program Exchange. The package is ca I I ed I NSOMN I A (Interrupt Sound Inltlalizer/Alterer). It allows creation and modification of sound data while you listen. It is accompanied by an interrupt sound generator that Is table driven and compatible with any language.

Machine-Code Sound Generation

Direct control of sound registers with mainl ine machine language opens new doors In sound generation. The technique is as fol lows: write a program

7-19

simi lar to the 60-Hz interrupt routine in that it is table-driven, but now the mainl ine routine is dedicated to sound generation. By expending much more processor time on sound generation, you can produce higher qual ity sounds. Consider, for example, the output of a typical 60 Hz music routine:

f r e q

I

~note....l

time

Figure 7-12

Example of 3 Music Notes Played With a 60 Hz Interrupt Music Routine

Since much more process i ng time is ava i I ab lew i th ma in line mach i ne language, we can change the frequency at very high speed during the note's

playing time so that it simulates an instrument. For example, suppose we

discovered that whenever any piano key is struck it produces a

characteristic sequence of frequencies, as shown in Figure 7-13.

Figure 7-13

Graph of Frequency Sequence for a Piano Note

Let's cal I the above graph the "piano envelope". To simulate a piano, the idea would be to very quickly apply the piano envelope to the plain vani Iia beep. The note is thus sl ightly modified during its playing time. For example, a piano simulation of the 3 notes in Figure 7-12 would look I ike this:

7-20

f r e q

~ note+-!

Figure 7-14

Example of the 3 Notes of Figure 7.10 Played With a Piano Envelope

We have essentially the same sound produced by the standard music routine of Figure 7-12, only the notes now have a piano tone, and sound much prettier than just the flat beeps. Unfortunately, we had to sacrifice all other process I ng to get that plano tone. The soun d channe I I s no longer updated only once every note, but perhaps 100 times within the note's duration.

Volume only sound

Ear II er we exper i men ted with the AUDC1-4 vo I ume on I y bits, but discovered that they weren't of much use in BASIC. This was due entirely to the fact that BASIC Is too slow to effectively use them. This is not the case with machine language.

As mentioned earl ier, this bit offers a tremendous capacity for accurate sound reproduct i on. True waveform generat ion (to the time and volume resolution limits of the computer) is made possible with this bit. Instead of just putting a piano flavor into the music, you can now make it closely repl icate a piano sound. Unfortunately, it can never precisely duplicate an Instrument. 4 bits (16 values) is not enough volume resolution for tru I y high-qua I i ty work. Neverthe less, the techn i que does generate surprisingly good sounds. The fol lowing program demonstrates the use of one of the volume only bits. If you have an assembler, type it in and try it:

7-21

0100

0110 ; VONLY 0120 ;

0130 ;

0140 ; volume-only AUOC1-4 bit test routine 0150

0160

0170 ;

0180 ;

0190 AUOCTL = 0200 AUOF1 = 0210 AUOC1 = 0220 SKCTL = 0230 ;

0240 ; 0250

0260 TEMPO 0270 MSC 0280 ;

0290

0300 00B2 0310 4000 A900 0320 4002 800802 0330 4005 A903 0340 4007 800F02 0350 400A A200 0360

0370 400C A900 0380 400E 800E04 0390 4011 8DOED20400 4014 800004 0410

0420 0430 ;

0440 ; 4017 B05240 0450 LOO 401A 85B1 0460

0470 401C B03640 0480 401F A4BO 0490 LO 4021 800102 0500

4024 88 0510 L1

4025 OOFO 0520

0530

0540 ; 4027 C6B1 0550 4029 00F4 0560

0570 ;

0580

0590 new note 0600

0208 0200 0201 020F

0000 OOBO 01 00B1 00

Bob Fraser 7-23-81

$0208 $0200 $0201 $020F

*= $BO .BYTE 1 .BYTE 0

*= $4000
LOA 110
STA AUOCTL
LOA 113
STA SKCTL
LOX 110
LOA 110
STA $040E kill vb I 's
STA $020E kill Irq's
STA $0400 kill dma LOA OTAB,X
STA MSC
LOA VTAB,X
LOY TEMPO
STA AUOC1
OEY
BNE L1 dec most s i 9 ctr OEC MSC BNE LO

7-22

402B E8 0610 INX
402C EC3540 0620 CPX NC
402F 00E6 0630 BNE LOO
0640
0650 wrap note pointer
4031 A200 0660 LOX #0
4033 FOE2 0670 BEQ LOO
0680
0690 ;
4035 lC 0700 NC .BYTE 28 note count
0710 ;
0720 ; table of volumes to be played In succession
0730 VTAB
4036 18 0740 .BYTE 24,25,26,27,28,29,30,31
4037 19
4038 lA
4039 lB
403A 1C
403B 10
403C lE
4030 IF
403E lE 0750 .BYTE 30,29,28,27,26,25,24
403F 10
4040 lC
4041 lB
4042 lA
4043 19
4044 18
4045 17 0760 .BYTE 23,22,21,20,19,18,17
4046 16
4047 15
4048 14
4049 13
404A 12
404B 11
404C 12 0770 .BYTE 18,19,20,21,22,23
4040 13
404E 14
404F 15
4050 16
4051 17 4052 01 4053 01 4054 01 4055 02 4056 02 4057 02 4058 03 4059 06

0780 ;

0790 ; this table contains the duration of each entry above 0800 OTAB

0810 .BYTE 1,1,1,2,2,2,3,6

7-23

405A 03 0820 .BYTE 3,2,2,2,1,1,1
405B 02
405C 02
4050 02
405E 01
405F 01
4060 01
4061 01 0830 .BYTE 1,1,2,2,2,3,6
4062 01
4063 02
4064 02
4065 02
4066 03
4067 06
4068 03 0840 .BYTE 3,2,2,2,1,1
4069 02
406A 02
406B 02
406C 01
4060 01 Supr is i ng I y, speed is not rea I I Y a prob I em here. The wave has a I most 60 steps, and the program can st i II be made to play the wave at up to 10 Khz.

Remove lines 400-410, and try the program once more. It wi I I sound quite broken up. The cause is the 60 Hz interrupt discussed in the previous section. You can actually hear the interrupts taking place since al I sound stops during that time.

Line 420 d i sab I es screen OMA. Th i sis why the screen goes to so lid background color when the program is executed. It serves two purposes: to speed up the processor, and to make the timing consistent, since DMA steals cycles at odd intervals.

In this demonstration program, the sound created is a sine wave. The

wave is remarkably pure, and does indeed sound like a sine wave. If

graphed, the data looks I ike this:

7-24

15-1 ------

14-1

13-1

12-1

11-1

10-1

9-1 -

8=1-----------------------------------------------------------

7-1 6-1 5-1 4-1 3-1 2-1

1-1 ------

Figure 7-15

Graph of Sine Wave Data for Volume Only Program

This section has discussed the technical aspects of sound generation

with the ATAR I Computer. The programmer must a I so understand the broader

role of sound in the complete software package.

~10v i e makers have long understood the importance of mood sett i ng backgroud mus i c. The recent space adventure mov i es by George Lucas are exce I lent examp I es. When the v i I I i an enters the room you know i mmed i ate I y to fear and hate him from the menacing background rhythms accompanying his entry. You gleefully clap your hands when the hero saves the princess whi Ie gallant music plays in the background. Likewise, horror fi Ims can frighten you by merely playing eerie music, even though the action may be completely ordinary.

SPACE INVADERS (trademark of Taito America Corp) issues a personal threat to its player and vi ct i m with its echo i ng stomp. As the tempo increases, knuckles whiten and teeth grind. When a Zylon from STAR RAIDERSm fires a photon torpedo you push frantically on the control to avoid impact. As it bores straight for your forehead, time slows and you hear it hissing louder and louder as it approaches. Just before impact, you duck and dislodge yourself from your armchair.

Impressionistic sounds affect our subconcious and our state of mind.

This is due possibly to the fact that sounds, if present, are continuously entering our mind whether or not we are actively listening. Visual inputs, on the other hand, require the user's attention. If we are distracted from the TV set, we cease to concentrate on the picture and the image leaves our mi nd. Sound therefore offers the programmer a direct path to the user's mind - bypassing his thought processes and zeroing in on his emotions.

7-25

8

THE OPERATING SYSTEM

INTRODUCTION

With every ATARI Home Computer System comes an ATARI 10K Operating System Cartr i dge. The I mportance of th Is cartr I dge I s often over looked. Without it, you have a lot of potential, but absolutely nothing else! This situation is not unique to the ATARI Home Computer System; It Is encountered with all computers. A computer is, after all, merely a collection of hardware devices. A user must manage these resources to accompl Ish any task. If al I programmers had to start from scratch on each program, we would have an even larger software shortage than we have today. The solution that has evo I ved over the years I s to b u i I din a program that manages the resou rces available to the system, and eases the programming burden required to control them. This program is known by various names: Operating System, Master Control Program, System Executive, System Monitor, etc. In the ATARI Home Computer System It Is known as the Operating System or OS.

The first task facing the student of the Operating System, Is to take an Inventory of exactly what resources are available to the OS. These are:

6502 Microprocessor

RAM Memory (various amounts) ANTIC LSI Integrated Circuit CTIA LSI Integrated Circuit POKEY LSI Integrated Circuit

PIA Peripheral Interface Adapter Integrated Circuit

By us i ng these resou rces, the OS can interact with and contro I a w I de variety of external hardware devices, Including a television rece I ver /mon i tor, keyboard, conso I e speaker, conso I e sw itches, joyst I cks, paddles, cassette recorder, disk drive, printers, RS-232 Interface and modem.

The remainder of this subsection briefly lists the main elements of the OS. These elements are described in detail In fol lowing subsections.

MON I TOR. The OS mon I tor is the system rout I ne that I s executed when the computer is turned on or the [SYSTEM RESET] button is pressed. ~hrough this rout i ne the OS takes contro I of the system; I t does not re I I nqu ish contro I unless control Is taken away from It by the programmer. The Monitor sets up the memory management system, Initializes the I/O subsystem, sets up system vectors and selects the execution environment after initialization is complete.

INTERRUPT PROCESSING STRUCTURE. The computer utilizes the standard Interrupt processing structure of the 6502 microprocessor, with some external augmentation for enhanced flexibility. Interrupts are generated by numerous events, Including keyboard keystrokes, the [BREAK] keystroke, some serial bus events, system timer timeouts, and the vertical blank Interval on the television.

8-1

OPERATING SYSTEM

OS SYSTEM VECTORS. The system vectors provide a mechanism that al lows users to access system routines, or customize the OS for special needs. The most frequent uses of the vectors are to call I/O system routines, set timers, and transfer control to different execution environments. System routines maybe vectored to in one of two ways. ROM vectors are locations that contain JMP Instructions to system routines and cannot be altered. RAM vectors are RAM locations that contain alterable addresses of system routines. The locations of both types of vectors are guaranteed to remain the same In future releases of the OS.

INPUT/OUTPUT SUBSYSTEM. The OS gives an application programmer access to the ful I capabilities of the computer's peripherals. The Input/Output subsystem Is a set of routines that link high level I/O operations with device handlers that control the physical I/O hardware.

REAL TIME PROGRAMMING. The ATARI Home Computer is wei I equipped to deal with problems In the "real time domain". To facillate this feature, the OS has two types of timers: hardware timers and system software timers. Hardware timers are countdown timers that can be used to time events with durations that range from ha I f a microsecond to severa I seconds. System timers are software timers that tick at 60 Hertz, and can be used for appl icatlons as diverse as serial bus timing and sound effect generation.

ROM CHARACTER SET. The computer is equ i pped with what is known as a "soft character set", I.e., It can be changed. The ROM-based character set is used to provide a standard character set at power-up.

)

FLOATING POINT PACKAGE. The floating point package is a set of mathematical rout I nes that extend the ar I thmet I c capab i I I ty of the system. The rout I nes use binary coded decimal (BCD) arithmetic to provide standard mathematical functions (+, -, *, I), exponential and logarithmic functions as well as conversion from ATASCI I to BCD and BCD to ATASCI I.

8-2

OPERATING SYSTEM

THE MONITOR

The OS mon i tor is that port i on of the OS ROM that hand I es both the power-up and SYSTEM RESET sequences. These sequences a I low the OS to ga In Initial control of the computer and ensure that everything Is properly initialized before releasing partial control to an application program. Both sequences are similar In function and In fact share much of the same code.

The power-up routine (also known as Coldstart) Is Invoked either by turn i ng on the computer or by jump I ng to COLDSV ($E477), a system rout i ne

vector. Important Items to remember about the power-up sequence are:

1. ALL of RAM memory Is cleared except locations $OOOO-$OOOF.

2. Both a cassette and disk boot are attempted. BOOT? ($0009) Is a flag that indicates the success or fai lure of the boots. Bit 0 = 1 for a successful cassette boot; Bit 1 = 1 for a successful disk boot.

3. COLDST ($0244) is a flag that te I I s the Mon i tor that I tis In the m i dd I e of power-up. COLDST=O means the [SYSTEM RESET] key has been pressed, whereas COLDST<>O indicates initial power-up. The COLDST flag can be used to gain a certain amount of program security. If COLDST Is set to a non-zero value during program execution, then pressing [SYSTEM RESET] will Initiate the power-up sequence. Th Is w II I prevent the user from ga I n I ng contro I of the computer while the program Is running.

Press i ng the [SYSTEM RESET] key causes a SYSTEM RESET (a I so known as

Warmstart) • Some of the key facts to remember about the SYSTEM RESET

sequence are:

1. The OS RA~1 vectors are down loaded from ROM du ring both SYSTEM RESET and power-up sequences. I f you wish to "stea I" a vector, some provision must be made to handle SYSTEM RESET. See the MEMORY MANAGE~1ENT subsect I on of th i s sect I on for suggest Ions on how th is Is done.

2. MEMLO, MEMTOP, APPMHI, RAMSIZ and RAMTOP are reset during System Reset. I f you wish to a I ter these RAM po inters to reserve some space for assemb I er modu I es ca I I ed by BAS I C, you must make some provision for handling SYSTEM RESET. Figure 8-3 provides an example of how to do this.

The next few pages present a deta II ed flowchart for the power-up and SYSTEM RESET sequences.

8-3

RESET

SEI

WARMST= $FF

OPERATING SYSTEM

( POWER-UP

SEI WARMST= 0

(RESET)NO ~

..... -------'--.:.._-<~

CLEAR O.S. RAM (S200-3FF,S10-7F)

GOTO STANDALONE DIAGNOSTIC CARTRIDGE (JMP ($BFFE))

NO

FIND # OF 4K BLOCKS OF RAM (TRAMSZ) INITIALIZE POKEY,ANTIC, CTIA/GTIA

YES (POWER-UP)

CLEAR ALL RAM ($OB-TRAMSZ)

SET DEFAULT CARTRIDGE TO BLACKBOARD (DOSVEC = BLKBDV) SET COLDST TO MIDDLE OF POWER-UP (CO LOST = $FF)

Figure 8-1.1 System Initialization

8-4

SET SCREEN MARGINS (LMARGN= 2 RMARGN=39)

MOVE IRQ VECTOR TABLE FROM ROM TO RAM (VDSLST-VVBLKD)

PAGE 2

)

OPERATING SYSTEM

CLEAR BREAK KEY (BRKKEY = $FF) SET MEMORY SIZE

RAMSIZ = TRAMSZ MEMTOP = TRAMSZ

MELO=$700

INITIALIZE DEVICE HANDLERS EDITOR (E:)

SCREEN (S:) KEYBOARD (K:) PRINTER (P:) CASSETTE (C:)

YES

SET CASSETTE BOOT (CKEY51)

NO CASSETTE BOOT

(CKEY= 0)

YES

INITIALIZE

B CARTRIDGE (JSR(9FFF)

MOVE DEVICE HANDLER TABLE FROM ROM TO RAM

(TBLENT HATABS)

CLEAR B CART. FLAG(TSDAT = 0)

SET B CARTRIDGE FLAG(TSDAT = 1)

Figure 8-1.2 System Initialization

8-5

CLEAR A CARTRIDGE FLAG (TRAMSZ = 0) (JSR ($BFFE»

YES

INITIALIZE A CARTRIDGE (JSR ($BFFE»

SET A CARTRIDGE FLAG (TRAMSZ= 1)

OPEN EDITOR (E:)

WAIT FOR VBLANK TO SET UP SCREEN

YES

OPERATING SYSTEM

YES

DO CASSETTE BOOT

YES

YES (RESET)

PRINT 'BOOT ERROR' ON SCREEN

NO

YES

RUN PROGRAM BOOTED (JSR (CASINI»

8-6

Figure 8-1.3 System Initialization

)

OPERATING SYSTEM

)

NO

YES

DO DISK BOOT

CLEAR POWER-UP FLAG (CO LOST = 0)

GO TO DOS OR CASSETTE PROGRAM OR BLACKBOARD

YES

PRINT 'BOOT ERROR'

YES

GOTO A CARTRIDGE (JMP ($BFFA))

YES

GOTO B CARTRIDGE (JUM ($9FFA))

Figure 8-1.3 System Initialization

8-7

YES

OPERATING SYSTEM

MEMORY MANAGEMENT

The fact that the OS Is wr I tten for a 6502 m I crop rocessor dictates a number of overal I memory management decisions. In the 6502, there are three special regions In the memory address space. Page zero has crucial significance In that the use of data values on this page will result In tighter, faster executing code. Indeed, there are Instructions that absolutely require page zero locations to work. Page one Is special because I tis used for the 6502 stack. Add resses $FFFA - $FFFF are a Iso spec I a I because they are reserved for hardware reset and Interrupt vectors.

Thus, the first task of memory management Is to assign the OS ROM to the highest part of memory address space. The OS resides In the address space from $D800 to $FFFF. Just under th I s area Is the space reserved for the hardware registers In ANTIC, CTIA, and POKEY. These reside In the $DOOO-$DFFF range.

At the other end of memory address space, the OS reserves half of page zero for Its own use. Pages two, three, four and five are also reserved for OS usage. From a programming viewpoint, the usable memory area runs from $0600 to $BFFF.

When the system Is powered-up, one of the first actions taken by the OS Is to determine how much RAM memory Is present. This Is accomplished by checking the first byte of each 4K block of memory starting at $1000. The contents of this byte are read, complemented and an attempt Is made to store the complemented value back out. If this attempt Is successful, the temporary memory size counter Is Incremented by 4K. This process continues untl I a location Is found that cannot be changed. Two variables, RAMTOP and RAMSIZ contain the number of RAM pages present. In addition to these locations, pointers MEMLO, MEMTOP, and APPMHI are maintained by the OS memory management rout I nes. The re I at I onsh I ps between these po I nters are shown In Figure 8-2, a simple memory map.

)

MEMLO I s a 2-byte I ocat Ion that the OS uses to I nd I cate where an application program may begin. You can modify MEMLO to create reserved areas for assembly language routines that may be cal led from BASIC. BASIC uses the value In MEMLO to determine the starting location of a program {see Section 10 for a discussion of the structure of a BASIC program). If the value of MEMLO Is changed to a higher address, It must be done before control Is trans ferred to the BAS I C cartr I dge. Th I sis a tr I ck y operat Ion, because MEMLO Is reset by both power-up and SYSTEM RESET.

If an application program Is running In a disk drive environment, the AUTORUN. SYS fac II I ty can be used to change MEMLO to reserve space. However, DOS Is also Initialized during SYSTEM RESET via the DOSINI vector ($OOOC). This vector contains the address of the DOS Initialization code called as part of the monitor system initialization. DOSINI is also the only point at which you can "trap" the SYSTEM RESET sequence. Since the DOS Initialization must occur regard I ess of what Is done to the MEMLO po Inter, you must a I low the normal Initialization to occur before "stealing" the DOSINI vector. This may be done by mov I ng the contents of DOS I N I I nto the 2-byte address of a JSR

8-8

OPERATING SYSTEM

information on the AUTORUN.SYS feature). Just after the JSR Instruction, place the code which sets ME~lLO to a new value. Follow this with aRTS Instruction. DOSINI must then be reset to the address of the JSR Instruction. When a SYSTEM RESET occurs, the new code sequence I~ cal led and the first Insructlon, JSR OLDDOSINI, Initializes DOS. The remaining code Is then executed which sets MEMLO to Its new value and then rejoins the rest of the Initialization sequence. Figure 8-3 presents an example showing how to do this.

The above technique can also be used with MEMTOP, the user high memory pointer. This pointer indicates the highest RAM address accessible to an application program. This RAM address differs from the highest physical RAM address because the OS a II ocates some RAM at the very top of RAM for its display list and display data. Space for assembly language modules and data can be set aside by lowering MEMTOP from the values set by power-up and SYSTEM RESET. Using MEMTOP Instead of MEMLO to reserve space does create one problem. The value of MEMTOP depends on both the amount of RAM In the system and the graphics mode of the display. This makes It difficult to predict Its va I ue before actua II y exam In i ng the I ocat i on un I ess you make assumpt ions about the system configuration. This uncertainty over the final location of the machine code forces the programmer to use only relocatable code.

APPMH I I s a I ocat Ion that conta I ns an address spec I fy i ng the lowest address to which the display RAM may extend. Correctly setting APPMHI ensures that the display handler wil I not clobber some of your program code or data.

RAMSIZ, I Ike MEMTOP, can also be used to reserve space for user routines or data. Since RAMSIZ Is a single byte value that contains the number of RAM pages present (I.e., groups of 256 bytes), lowering Its value by 1 will reserve 256 I ocat Ions. The advantage of us i ng RAMS I Z I nstead of MEMTOP Is that the space saved by mov I ng RAMS I Z down I s above the d I sp I ay memory, whereas space saved by moving MEMTOP down remains below the display memory.

8-9

os

MEMLO 2E7,2E8

APPMHI OE,OF

OPERATING SYSTEM

MEMTOP 2E5,2E6 _

SDLST 230,231

SAVMSC 58,59

TXTMSC 294,295

RAMTOP 6A RAMSIZ 2E4

MEMORY MAP

RAM

PAGE
SIX
DOS
BASIC
TOKEN
PROGRAM
FREE
RAM
DISPLAY
LIST
SCREEN
RAM
TEXT
WINDOW BASIC

_~.__ 80,81 LOMEM

___ 90,91 MEMTOP OE,OF APHM

I

FRE(O)

I

___ 2E5,2E6 HIMEM

)

Figure 8-2 OS and BASIC Pointers (DOS present)

8-10

0010 ; RESET THE MEMLO POINTER

0020 ;

0030 START 0040 DOSINI = 0050 MEMLO 0060 NEWMEM =

0065

0070 0090 0100 0120 0130 0140 0150 0160 0170 ; 0180 0185 0190

0200 0210 0600 200D06 0220 0603 A900 0230

0605 8DE702 0240

.. 0608 A930 0250 )060A 8DE802 0260

0270 TROJAN

0280 RTS

0290 THIS PART IS EXECUTED AT POWER UP ONLY AND 0300 CAN BE DELETED AFTER POWER-UP.

0330 THIS ROUTINE STORES THE CONTENTS OF DOSINI INTO THE 0350 TROJAN INSTRUCTION. IT THEN REPLACES DOSINI WITH 0370 ; A NEW VALUE, LOCATION INITDOS.

0390 GRABDOSI

060E A50C 0400 LDA

0610 8D0106 0410 STA

0613 A50D 0420 LDA

0615 8D0206 0430 STA

0618 A900 0440 LDA

061A 850C 0450 STA

061C A906 0460 LOA

061E 850D 0470 STA

0620 A500 0480 LOA

0622 8DE702 0490 STA

0625 A930 0500 LOA

0627 8DE802 0510 STA

062A 60 0520 RTS

062B 0530 *= $2E2

02E20E06 0540 .WORD GRABDOSI

02E4 0550 .END

0600 OOOC 02E7 3000

0000

060D 60

OPERATI NG SYSTE~~

=

$600 $OC $2E7 $3000

; THIS IS THE NEW VALUE FOR MEMLO

=

THIS ROUTINE RESERVES SPACE FOR ASSEMBLY ROUTINES BY RESETING THE MEMLO POINTER. IT RUNS AS

AN AUTORUN.SYS FILE. IT ALSO RESETS MEMLO ON [RESET]. MEMLO I S SET TO THE VALUE OF NE~,{MEM.

THIS PART IS PERMANENT, IE. NEEDS TO BE RESIDENT. THE SYSTEM DOSINI VECTOR HAS BEEN STOLEN

AND STORED IN THE ADDRESS PORTION OF THE JSR TROJAN INSTRUCTION. SO WHEN [RESET] IS PRESSED, DOSINI VECTORS TO INITDOS, JSR TROJAN THEN CALLS THE DOS INITIALIZATION ROUTINES, MEMLO IS RESET TO NEW VALUE AND CONTROL RETURNS TO THE tvl0N I TOR.

*= START

INITDOS JSR LOA STA LOA STA

TROJAN ; DO DOS #NEWMEM&255

MEMLO

#NEWMEM/256 MEMLO+l

INITIALIZATION

JSR

DOSINI INITDOS+l DOSINI+l INITDOS+2 #INITDOS&255 DOSINI #INITDOS/256 DOSINI+l NEWMEtvl&255 MEMLO #NEWMEM/256 MEMLO+l

; SAVE DOSINI

SET DOSINI

SET MEtvlLO

SET RUN ADDRESS

Figure 8-3 Reset MEMLO

8-11

OPERATING SYSTEM

INTERRUPT PROCESSING STRUCTURE

The capability to selectively respond to special hardware and software events (I.e. Interrupts), provides enormous flexibility to any computer system. As I n any 6502-based system, there are two types of Interrupt requests at the processor level, maskable (IRQ) and nonmaskable (NMI) Interrupts. A higher level of Interrupt control Is provided by ANTIC, POKEY and the PIA chip. Each of these chips Is responsible for mediating a number of events wh i ch cou I d cause Interrupts. I f a part I cu I ar I nterrupt Is enab led at the I eve I of the three guard I an ch i ps, then they a I low the Interrupt request to pass on to the 6502. ANTI C hand I es NM I requests, and POKEY and the PIA handle IRQ requests.

The fol lowing Interrupt functions are available:

Name (vector) Type

DISPLAY LIST •••••••••••• (VDSLST) NMI SYSTEM RESET •••••••••••••• (none) NMI VERTICAL BLANK ••• (VVBLKI,VVBLKD) NMI SERIAL INPUT READY •••••• (VSERIN) IRQ SERIAL OUTPUT READY ••••• (VSEROR) IRQ SERIAL OUTPUT COMPLETE •• (VSEROC) IRQ POKEY TIMER 1 ••••••••••• (VTIMR1) IRQ POKEY TIMER 2 ••••••••••• (VTIMR2) IRQ *POKEY TIMER 4 •••••••••• (VTIMR4) IRQ KEYBOARD •••••••••••••••• (VKEYBD) IRQ *BREAK KEY ••••••••••••••• (BRKKY) IRQ SERIAL BUS PROCEED •••••• (VPRCED) IRQ SERIAL BUS INTERRUPT( •••• VINTER) IRQ

Function

Graphics timing System Inlt. Graphics display Ser I a I Input Serial output Serial output Hardware timer Hardware timer Hardware timer Key presssed [BREAK] key Device proceed Device Interrupt

Used By

User

OS OS,user OS

OS

OS

User User User

OS

OS Unused Unused

* This IRQ Is vectored only in the Rev. B version of the OS

Section 6 of the OPERATING SYSTEM Manual contains more detal led Information on Interrupts. Extreme care needs to be taken in working with Interrupts. For example, If you accidentally disable the keyboard IRQ Interrupt, the computer will Ignore all the keys except the. [BREAK] key. Although this may be useful sometimes, It may make debugging your program a bit difficult!

The IRQ Interrupt Handler

The OS has an I RQ I nterrupt hand I er that processes the var lous I RQs.

Th I s hand I er has RAM vectors for a I I of the I RQs. (Note - the [BREAK] key IRQ Is not vectored In the original version of the OS.) The IRQ vectors are set to their Initial values during both power-up and SYSTEM RESET. The I ocat Ions of the I RQ RAM vectors are descr I bed I n the sub sect I on on System Vectors.

8-12

OPERATING SYSTEM

IRQ vector functions are:

V I M I RQ - I mmed I ate I RQ vector. A I I I RQs vector through this location. VIMIRQ normally points to the system IRQ handler. You can steal this vector to do your own IRQ Interrupt processing.

VSEROR - Pokey Ser I a I Output Needed I RQ vector.

This normally points to the code to provide the next byte In a buffer to the serial output port.

VSERIN - Pokey Serial Input Ready IRQ vector. This points to the code to place a byte from the serial Input port Into a buffer.

VSEROC - Pokey Serial Output Complete IRQ vector.

Norma I I Y th I s vector po I nts to code that sets a transm It done flag after the checksum byte goes out.

VTIMR1 - Pokey Timer 1 IRQ vector. Initialized to point to a PLA,RTI Instruction sequence.

VTI MR2 - Pokey Timer 2 I RQ vector. In It I a II zed to point to a PLA,RTI Instruction sequence.

VTIMR4 - Pokey Timer 4 IRQ vector. Initialized to point to a PLA,RTI Instruction sequence.

VKEYBD - Keyboard I RQ vector. Press i ng any key except [BREAK] causes th is IRQ. VKEYBD can be used to pre-process the key code before It Is converted to ATASC I I by the OS. VKEYBD norma I I Y po i nts to the OS keyboard IRQ routine.

BRKKY - [BREAK] key vector. I n the Rev. B vers Ion of the OS, +h I s I RQ has I ts own vector. I tis In it i a L zed to a PLA,RTI instruction sequence.

VPRCED - Peripheral Proceed IRQ vector. The proceed I ine Is available to peripherals on the serial bus. This IRQ is unused at present and normally points to a PLA,RTI instruction sequence.

V INTER - Per I phera I I nterrupt I RQ vector. The Interrupt line Is also available on the serial bus. VINTER normally points to a PLA,RTI Instruction sequence.

8-13

OPERATI NG SYSTEfvl

VBREAK - 6502 BRK Instruction IRQ vector. Whenever a software break instruct I on I s executed, +h I s Interrupt occu rs. VBREAK can be used to set break po I nts for a debugger, though it normally points to a PLA,RTI Instruction sequence.

The I RQs are enab I ed and d I sab I ed as a group by the 6502 I nstruct Ions CLI and SEI respectively. The IRQs also have Individual enable/disable bits In POKEY. The programmer's reference card provided with this book shows the IRQs and their enable/disable bits.

The IRQEN register contains most of the IRQ enable/disable bits and Is a write-only register. The OS keeps a shadow copy of IRQEN In POKMSK ($0010), but IRQEN Is not updated from POKMSK during vertical blank. Each Interrupt Is enabled by setting the proper bit In IRQEN to a one. A zero Is placed In a bit I n I RQEN to c I ear I nterrupt status from that correspond I ng bit In IRQST. You might note that bit 3 In IRQST (Serial data transmission Is finished) Is not cleared by this process. This bit Is simply a status bit and reflects the current status of the serial transmission register.

PACTL and PBCTL are used to enab I e and test the status of the I RQs handled by the PIA. Bit 0 of each of these registers Is the Interrupt enable for that port. Bit 7 represents the I nterrupt status. Th I s bit Is c I eared whenever the PACTL or PBCTL registers are read.

Us I ng The I RQs

The ava II ab I II ty of the I RQ vectors means that you can ta II or much of the system I/O to your liking. Currently, the OS does not provide for over lapp i ng I/O with other process I ng • By red I rect I ng the three ser I a I I/O Interrupt vectors however, It Is possible to rewrite portions of the I/O subsystem to al low for true concurrent processing.

The three timer interrupts can be put to use In any operation requiring precise timing control. These timers would normally be us~d when the 60-Hertz software timers are too slow. Refer to the subsection on Real Time Programming for more Information on this topic.

~1any app II cat ions requ ire that programs be protected from user input error. A coup I e of the I RQ vectors can be used to pov I de extended Input protection. The example In Figure 8-4 uses the VKEYBD IRQ vector to disable the contro I key. The rout i ne a I so masks the [BREAK] key by stea I I ng the VIMIRQ vector and Ignoring the [BREAK] key interrupt. Though written for the original version of the OS, this routine wi I I stll I work In Rev. B.

Two of the I RQs are hand I ed by the P I A, VPRCED and V INTER. These are unused by the OS, and may be utilized to provide more control over external devices.

8-14

You might also like