Jump to content
IGNORED

Session Notes (beware of errata!)


Recommended Posts

Hi I am posting the notes that I take on the Andrew Davies tutorials. If you see errors or want to add to it feel free.

 

These notes originally appeared in the sticky posting about chapter links, Andrew felt (and I agreed) because of some of the errors in my notes that it would confuse new readers. So, new readers beware! However in the spirit of distributed learning I felt like these notes might be of some help to someone out there. I am going to work to get rid of the errata when I find it! :wink:

Link to comment
Share on other sites

The Atari 2600 is a cartridge based system.

 

The cartridge consists of a circuit board containing a ROM (EPROM).

 

All interactivity and graphics are just data (binary numbers) stored on the cartridge.

 

The Atari 2600's processor is the 6507 chip which is a stripped down version of the 6502 processor. The 6502 is the same CPU that other systems like the NES, APPLE II used.

 

The Atari 2600 Consists of these components:

 

Memory:

Memory is both RAM (Random Access Memory) and ROM (Read Only Memory). The Atari contains 128 Bytes of ram and depending on the type of cartridge used in the game only about 4k of ROM.

 

Input/Output:

The Atari allows for basic input using the ports on the front of the unit. Into these sockets you can plug a variety of paddles and joysticks to control that Atari's games. Typically the only output of the Atari is the signal it sends to the TV that displays the picture and sound of the game.

 

Development Process

The development of an Atari game is an iterative process which involves developing source code in a text editor and then using a program called a compiler to interpret your source-code and build a new file in machine code called a "Binary Image". This image is then burned onto an EPROM and inserted into a cartridge for use on the Atari. You can also use an emulator to play the binary image on a computer.

 

Links:

 

Atari 2600 Emulators

- Z26 - available at http://www.whimsey.com/z26/ (recommended)

- Stella - available at http://sourceforge.net/projects/stella/

 

Mailing lists and Web Sites:

- the Stella list - at http://www.biglist.com/lists/stella/

- AtariAge - at http://www.atariage.com/

Stella Programmers Guide

- text version at http://stella.sourceforge.net/download/stella.txt

- PDF version at http://www.atarihq.com/danb/files/stella.pdf

 

Text Editors

- Crimson Editor http://crimsoneditor.com/

Link to comment
Share on other sites

Session 2: Television Display Basics

 

Televisions have been around since the 20's

 

Televisions don't display a continuos moving image. Instead the show static images in rapid succession. The fact that we see the image as a moving sequence is called "persistence of vision".

 

The static images of the television are actually not made out of a single image. They are constructed out of several lines (scanlines). The number of scanlines varies depending on your television.

The two main types of televisions are NTSC and PAL.

 

NTSC

- 60 images per second (fps)

- 525 scanlines deep

- 262.5 interlaced scanlines deep (Atari 2600 is non-interlaced)

- 192 visible lines on the television

 

PAL

- 50 images per second (fps)

- 625 scanlines deep

- 312.5 interlaced scanlines deep (Atari 2600 is non-interlaced)

- 228 visible lines on the television

 

More correctly, televisions display 50 *fields* (NTSC) or 60 *fields* (PAL) per second, and a single frame is made from two fields interlaced together (with half a scanline vertical shift between them). The eye perceives these consecutive interlaced fields as a single higher-resolution picture. Two fields together are called a frame. Since the Atari 2600 typically doesn't do interlacing, each of the fields are identical. BUT, it is possible for a '2600 programmer to generate a true interlaced display, thus setting the effective vertical resolution of the machine to a whopping 525 lines (NTSC) or 625 lines (PAL).

 

So, it's not that the Atari 2600 is non-interlaced. It's just that traditonally, programmers do not generate interlaced frames.

 

 

 

The visible lines will effect game elements like sprite sizes, size of the playing field, vertical motion rate etc...

 

It is important for the programmer to be aware of the difference because it is the programmer who has control of the data going to the TV. The 2600 only generates a signal for a single line.

 

However, televisions also employ a technique called interlacing which allows for the image to be built up over two separate frames. Each frame (either even or odd) is displayed 1/30th of a second (30hz) on NTSC. On a PAL television the interlaced scanline is showed 1/25th (25hz).

 

The use of interlacing improves screen resolution.

 

The extra .5 of a scanline is used to tell the TV if it is an even or odd scanline.

 

How a television works:

It forms the images we see by shining an electron beam (or 3, for color TVs) onto a phosphor coating on the front of the picture tube. When the beam strikes the phosphor, the phosphor starts to glow - and that glow slowly decreases in brightness until the phosphor is next hit by the electron beam. The TV 'sweeps' the electron beam across the screen to form 'scanlines' - at the same time as it sweeps, adjusting the intensity of the beam, so the phosphor it strikes glow brightly or dimly. When the beam gets to the end of a scanline, it is turned off, and the deflection circuitry (which controls the beam) is adjusted so that the beam will next start a little bit down, and at the start (far left-hand-side) of the next scanline. And it will then turn on, and sweep left-to-right to draw the next scanline. When the last scanline is drawn, the electron beam is turned off, and the deflection circuity is reset so that the beam's position will next be at the top left of the TV screen - ready to draw the first scanline of the next frame.

 

The "turning-off" and repositioning process is not instantaneous.

This repositioning time is called the "horizontal blank"

.. and the retrace period where the beam turns off and returns to the top of the TV is called the vertical blank. Horizontal blank is 68 TIA colour-clocks in duration. Vertical blank is thousands of 6502 cycles in duration.

 

 

The Atari 2600 sends the TV the "color and intensity information for the electron beam as it sweeps across that line", and a signal for the start of each new line. The '2600 programmer needs to feed the TV the signal to start the image frame.

Link to comment
Share on other sites

The TIA and the 6502

 

Recap:

- TV frame is composed of 262 scanlines (NTSC)

- TV frame is composed of 312 scanlines (PAL)

 

TIA = Television Interface Adaptor

 

The Atari builds the signal for each scanline. The scanline signal has a color and intensity property.

 

The TIA draws the pixels on the screen 'on-the-fly'.

Each pixel is one 'clock' of the TIA's processing time.

 

TIA Properties:

- 228 Color clocks / per scanline (including horizontal blank)

- 160 visible color clocks (160 pixels per scanline)

- 68 used by the horizontal blank

 

The 6502 clock is derived from the TIA clock through a divide-by-three.

 

For every single clock of 6502 time three color clocks of the TIA have elapsed

 

There are 76 cycles of 6502 processing time per scanline.

 

Seventy six 6502 cycles * 262 lines per frame * 60 frames per second = 1.19mhz (roughly)

 

As the 6502 is executing instructions the TIA is sending data to the TV for each scanline.

 

Since 6502 and the TIA are synched because of their shared timing origin it is possible for the programmer to determine what pixel the TIA is currently drawing.

 

Each assembly command takes a certain amount of time to perform a task. This means that you need to accomplish those tasks as quickly as possible so that you can draw them to the screen with the TIA. Example:

 

A load/store combination takes a minimum of 5 cycles of 6502 time. How many on screen pixels is that? Remember, 3 color clocks per 6502 cycle, so that's 3 x 5 = 15 pixels. Essentially, if one were using the quickest possible load/store combinations to change the color of, say, the background, then the absolute quickest this could be done would be every 15 pixels (ie: just on 11 times per scanline).

Link to comment
Share on other sites

Recap:

 

Covered the TIA (Television Interface Adaptor) and its relationship to the 6502 processor.

 

The TIA has three "color" cycles to the 6502's one programmatic cycle.

 

The TIA has 228 cycles consisting of 160 drawn to the screen and 68 invisible cycles used by the horizontal blank.

 

Unless, the programmer changes the TIA every scanline will look identical.

 

Since the TIA is independent from the 6502 it is possible to just send 160 scanlines to the TIA and wait 76 scanlines and the TIA will take care of the rest.

 

No. Since the TIA has an internal state and draws data to the TV based on this state, it is possible to draw a single line simply by waiting 76 cycles of 6502 time (228 TIA colour clocks). It is possible to draw an entire frame by waiting for 262 lines (NTSC) or 312 lines (PAL). -- AD

 

The TIA is so closely tied to the 6502 that it has the ability to stop and start the 6502 at will. In fact the 6502 can tell the TIA to halt the 6502.

 

If you are unsure of the position of the TIA just ask the TIA to halt the 6502 and since the TIA restarts at the beginning of each scanline the 6502 and the TIA will be back in synch. The best thing is that the 6502 will be unaware that anything happened at all.

 

[No. It is not the TIA which restarts at the beginning of each scanline. It is the TIA which restarts the 6502 at the beginning of each scanline, if it has been halted (through WSYNC writes). -- AD[/b]

 

 

The CPU-Halt is called by writing any value to the TIA's Register called WSYNC.

 

Notes on Assembly

Binary numbers are represented by a "%" prefix

Hexadecimal numbers are represented by a "$" prefix

A base 10 number is represented by a "#" prefix

";" precedes any comments in the code

 

Not quite. Base 10 numbers have NO prefix. the "#" symbol tells the assembler to treat the follwing value as a number, not a number representing a memory location.

 

Example:

 

lda #$80 ; load the number 128 into the accumulator

sta $80 ; store the contents of the accumulator into memory location %10000000

lda 128 ; load the contents of memory location 128 (=$80) back into the accumulator

sta #128 ; totally illegal instruction format - won't assemble. You can't store to a number, you can only store to a location!

 

--AD

 

 

nop = no operation (two 6502 cycles to execute) if you executed 38 nops starting at the beginning of the scanline the TIA would finish drawing the last pixel the same time the 6502 finished executing the last nop command.

 

 

Introduction to the 6502

 

The 6502 is an 8-bit processor which means it works with 8 binary-bits at a time.

 

Eight binary numbers can represent 0 to 255

8 binary bits can represent a number from 0 to 255 (decimal) or from -128 to 127, or whatever range or representation you want to conceptually give to it. The important point is that there are 256 unique values. -- AD

 

You read binary numbers from right to left.

They are no different to any other number we're used to -- it's just the base which is different. -- AD

 

Here is an example of a binary number %01100101

 

This number equals = 101 and this is how:

 

| 128| 64 | 32 | 16 |  8 |  4 |  2 |  1 |

-----------------------------------------

|  0 |  1 |  1 |  0 |  0 |  1 |  0 |  1 | 

-----------------------------------------



64 + 32 + 4 + 1 = 101

 

Ok, I have no math skills and to be honest until last week I had no idea

how to count hex or binary or convert between them.

This tutorial was crucial for me

http://mathforum.org/library/drmath/view/54311.html

 

 

 

The 6502 is able to shift 8-bit numbers to and from various locations in memory (referred to as addresses).

A memory address is a unique location in RAM or ROM like a home address or an post office box number. The 6502 processor is able to get numbers from and in some cases store numbers to these addresses.

 

The 6502 has just six registers but only the first three are covered here. Registers are internal memory/storage locations. The three registers are (X,Y,A)

Link to comment
Share on other sites

Session 5 memory architecture

 

6502 communicates with the TIA by getting and setting values to the TIA registers, these registers are mapped to fixed addresses in the 6502 addressing range.

 

The 6507 (the stripped down 6502) is able to address 2^13 bytes (8192 bytes) of memory each with a unique address. Each 16-bit address ultimately directly controls the "wires" on the 16-bit bus to memory.

 

The 6507 ignores any attempt to access an address above the 13-bits.

 

The 13-bits form the footprint of the 6507 memory ($0 to $1FFF).

 

All communication between the CPU and hardware (be it ROM, RAM, I/O the TIA or other) is through reads and or writes to the memory location.

 

Memory Map:

 

$0000 - $007F TIA registers

$0080 - $00FF RAM

$0200 - $02FF RIOT registers

$1000 - $1FFF ROM

 

Note: 1K = 1024 bytes = $400 bytes = %10000000000 bytes.

Link to comment
Share on other sites

Session Seven, The TV and our Kernel

 

Recap:

Horizontal:

228 TIA color clocks on each scanline

160 color clocks are visible on each scanline of the TV

068 color clocks are used by horizontal retrace

 

Vertical:

3 scanlines of VSYNCH

37 scanlines of vertical blank

192 scanlines of actual picture (NTSC) 242 (PAL)

30 scanlines of overscan

262 total scanlines (NTSC) or 312 scanlines (PAL)

 

If you send an odd number of scanlines to a PAL TV then the image will appear in black and white.

Link to comment
Share on other sites

Session 9: 6502 and DASM -Assembling the Basics

 

The Assembler takes your source code and assembles it into a binary image

The Binary Image is run on the 6502 CPU

 

"DASM converts source-code consisting of instructions (mnemonics) and symbols into a binary form which can be run by the 6502. The assembler converts mnemonics into opcodes (numbers), and symbols into numbers which it calculates the value of during the assembly process."

 

If DASM encounters a word it does not know it stores it in the symbol table. It will continue to compile the code but if it reaches the end and the word has still not been defined a value DASM will produce errors.

 

vcs.h contains symbols for commonly used memory locations.

Example: sta WSYNC

sta = instrunction or opcode

WSYNC = symbol which is defined in vcs.h as $2. (remember that $0-$7F is reserved for the TIA)

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...