The APPLE-II color graphics hardware will display a 40H by 48V grid, each position of which may be anyone of 16 colors. The actual screen data is stored in 1 K bytes of system memory, normally locations $400 to $7FF.(A dual page mode allows the user to alternatively display locations $800 to $BFF). Color displays are generated by executing programs which modify the “screen memory.” For example, storing zeroes throughout locations $400 to $7FF will yield an all-black display while storing $33 bytes throughout will yield an all-violet display. A number of subroutines are provided in ROM to facilitate useful operations.
The x-coordinates range from 0 (leftmost) to 39 (rightmost) and the y-coordinates from 0 (topmost) to 47 (bottommost). If the user is in the mixed graphics/text mode with 4 lines of text at the bottom of the screen, then the greatest allowable y-coordinate is 39.
The screen memory is arranged such that each displayed horizontal line occupies 40 consecutive locations. Additionally. even/odd line pairs share the same byte groups. For example, both lines 0 and 1 will have their leftmost point stored in the same byte. at location $400; and their rightmost point stored in the byte at location $427 The least significant 4 bits correspond to the even line and the most significant 4 hits to the odd line. The relationship between y-coordinates and Memory addresses is illustrated on the following page.
The APPLE-II color graphics subroutines provided in ROM use a few page zero locations for variables and workspace You should avoid using these locations for your own III overall variables It is a good rule not to use page zero locations $20 to $4F for any programs since they are used by the monitor and you may wish to use the monitor (for example, to debug a program) without clobbering your own variables. If you write a program in assembly language that you wish to call from BASIC with a CALL command, then avoid using page zero locations $20 to $FF for your variables.
Color Graphics Page Zero Variable Allocation
GBASL | S26 |
GRASH | S27 |
H2 | S2C |
V2 | S20 |
MASK | S2E |
COLOR | S30 |
GBASL and GBASH are used by the color graphics subroutine as a pointer to the first (leftmost) byte of the current plot line. The (GBASL), Y addressing mode of the 6502 is used to access any byte of that line COLOR is a mask byte specifying the color for even lines in the 4 least significant bits (0 to 15) and for odd lines in the 4 most significant bits These will generally be the same, and always so if the user sets the COLOR byte via the SETCOLOR subroutine provided. Of the above variables only H2, V2, and MASK can be clobbered by the monitor.
Writing a color graphics program in 6502 assembly language generally involves the following procedures. You should be familiar with subroutine usage on the 6502.
1. Set the video mode and scrolling window (refer to the section on APPLE-II text features)
2. Clear the screen with a call to the CLRSCR (48-line clear) subroutines If you are listing the mixed text/graphics feature then call CLRTOP
3. Set the color using the SETCOLR subroutine
4. Call the PLOT, HLINE. and VLlNE subroutines to plot points and draw lines The color setting is not affected by these subroutines.
5. Advanced programmers may wish to study the provided subroutines and addressing schemes When you supply x- and y-coordinate data to these subroutines they generate BASE address, horizontal index, and even add mask information. You can write more efficient programs if you supply this information directly
PlOT1 subroutine (address $F80E)
Purpose — To plot square, in standard resolution mode with no Y-coordinate change from last call to PLOT. Faster than PLOT. uses most recently specified COLOR (see SETCOL)
Entry X-coordinate in Y-Reg (0 to 39)
Exit A-Reg clobbered Y -Reg and carry unchanged
Example: (Plotting two squares, – one at (3, 7) and one at (9, 7))
LDY # $3 X-coordinate
LDA # $7 Y -coordinate
JSR PLOT Plot (3, 7)
LDY # $9 New X-coordinate
JSR PLOTl Call PLOT1 for fast plot.
HLINE subroutine (address $F819)
Purpose: To draw horizontal lines in standard resolution mode. Most
recently specified COLOR (see SETCOL) is used.
Entry: The V-coordinate (0 to 47) is in the A-Reg. The leftmost X-coordinate (0 to 39) is in the V-Reg and the rightmost X-coordinate (0 to 39) is in the variable H2 (location S2C). The rightmost x-coordinate may never be smaller than the leftmost
Calls: PLOT, PLOT1
Exit: The V-Reg will contain the rightmost X-coordinate (same as H2 which is unchanged). The A-Reg is clobbered. The carry is set.
Example: Drawing a horizontal line from 3 (left X-coord) to S1A (right X-coord) at 9 (V-coord)
LDY #S3 Left
LDA #O$1A Right
STA H2 Save it
LOA #$9 Y-coordinate
JSR HLINE Plot line
SETCOL subroutine (address $FS64)
Purpose: To specify one of 16 colors for standard resolution plotting.
Entry: The least significant 4 A-REG bits contained a color code (0 to $F). The 4 most significant bits are ignored.
Exit: The variable COLOR (location $30) and the A-Reg will both contain the selected color in both half bytes, for example color 3 will result in $33. The carry is cleared.
Example: (Select color 6)
LDA #$6
JSR SETCOL ($F864)
Note: When sitting the color to a constant the following sequence. is preferable.
LDA #$66
STA COLOR ($30)
PLOT subroutine (address $F800)
Purpose: To plot a square in standard resolution mode using the most recently specified color (see SETCOL). Plotting always occurs in the primary standard resolution page (memory locations $400 to $7FF).
Entry: The x-coordinate (0 to 39) is in the Y-Reg and the y-coordinate (0 to 47) is in the A-Reg.
Exit: The A-Reg is clobbered but the V -Reg is not. The carry is cleared. A halfbyte mask ($F or $FO) is generated and saved in the variable location MASK (location $2E).
Calls: GBASCALC
Example: (plot a square at coordinate ($A, $2C))
LDA #2C Y-coordinate
LDY #SA X-coordinate
JSR PLOT (F800)
SCRN subroutine. (address $F871)
Purpose: To sense the color (0 to SF) at a specified screen position
Entry: The Y-coordinate is in the A-Reg and the X-coordinate is in the Y-Reg.
Exit: The A-Reg contains contents of screen memory at specified position. This will be a value from 0 to 15). The Y-Reg is unchanged and the “N” flag is cleared (for unconditional branches upon return).
Calls: GBASCALC
Example: To sense the color at position (5, 7)
LDY #$5 X-coordinate
LDA #$7 Y -coordinate
JSR SCRN Color to A-Reg.
GBASCALC subroutine (address $F847)
Purpose: To calculate a base address within the primary standard resolution screen memory page corresponding to a specified Y-coordinate. Once this base address is formed in GBASL and GBASH (locations $26 and $27) the PLOT routines can access the memory location corresponding to any screen position by means of (GBASL). Y addressing.
Entry: (Y-coordinate) 2 (0 to $17) is in the A-Reg. Note that *even/odd Y-coordinate pairs share the same base address)
Exit: The A-Reg is clobbered and the carry is cleared. GBASL and GBASH contain the address of the byte corresponding to the leftmost screen position of the specified Y-coord.
Example: To access the byte whose Y-coordinate is $1A and whose X-coordinate is 7.
LDA #$1A Y-coordinate
LSR Divide by 2
JSR GBASCALC Form base address
LDY #$7 X-coordinate
LDA (GBASL), Y Access byte
Note: For an even/odd Y -coord pair. the even-coord data is contained in the least significant 4 bits of the accessed of the accessed byte and the odd-coord data in the most significant 4.
COLOR GRAPHICS SCREEN MEMORY MAP
Y-Coordinate
0 0 A B C D E F
BASE (leftmost) address
0 0 0 0 0 1 C D E A B A B 0 0 0
GBASH GBASL
Data Byte
X X X X Y Y Y Y
odd even
line line
data data
LINE | BASE ADDR | PG2 BASE ADR | |||
HEX ===== $0, 1 $2, 3 $4, 5 $6, 7 $8, 9 $A, B $C, D $E, F $10,11 $12,13 $14,15 $16,17 $18,19 $lA,lB $lC,lD $1E,1F $20,21 $22,23 $24,25 $26,27 $28,29 $2A,2B $2C,2D $2E,2F |
DEC ===== 0, 1 2, 3 4, 5 6, 7 8, 9 10,11 12.13 14,15 16,17 18,19 20,21 22,23 24,25 26,27 28,29 30,31 32,33 34,35 36,37 38,39 40,41 42,43 44,45 46,47 |
HEX ==== $400 $480 $500 $580 $600 $680 $700 $780 $428 $4A8 $528 $5A8 $628 $6A8 $728 $7A8 $450 $4DO $550 $5D0 $650 $6D0 $750 $7D0 |
DEC ==== 1024 1152 1280 1408 1536 1664 1792 1920 1064 1192 1320 l448 1576 1704 1832 1960 1104 1232 1360 1488 1616 1744 1872 2000 |
HEX ==== $800 $880 $900 $980 $AOO $A80 $BOO $B80 $828 S8AS $928 $9A8 $A28 $AA8 $B28 $BA8 $850 $8DO S950 $9DO $A50 $ADO $B50 $BDO |
DEC ==== 2048 2176 2304 2432 2560 2688 2816 2944 2088 2216 2344 2472 2600 2728 2856 2984 2128 2256 2384 2512 2640 2768 2896 3024 |