Chapter 3: SCREEN PROGRAMMING

Displaying text/characters & their colours on screens

This section is all about displaying PETSCII/Text characters on to the screen. Well, before we move on to the next part of putting text/characters from screen data memory on to the screen RAM, we shall do a simple little HELLO WORLD program. Alright, so this is nothing special, but it will introduce you to a command, often used in turbo assembler called .TEXT. This is useful for those of you who want to write text, without designing a screen using any specific hardware or software, i.e. Action Replay cartridge, Screen Editor, etc. We are using default BANK #3, to display our screen characters. So the character store range will be from $0400-$07E7. Where $0400 will be the very first char on screen, and $07E7 will be the last char on screen.

An example of the HELLO WORLD program.

;======================================
;    HELLO WORLD - ASSEMBLY VERSION
;======================================

          * = $0810 ;SYS 2064 to start
          SEI
          JSR $E544 ;QUICK SCREEN CLEAR
          LDA #$02  ;RED BORDER
          LDX #$00  ;BLACK BACKGROUND
          LDY #$14  ;DEFAULT C64 CHAR
          STA $D020
          STX $D021
          STY $D018

;DISPLAY HELLO WORLD! AT $0400

          LDX #$00
DISPHELLO LDA HELLOTXT,X
          STA $0400,X
          INX
          CPX #$0B
          BNE DISPHELLO

SPACEKEY  LDA $DC01 ;WAIT FOR SPACEBAR
          CMP #$EF
          BNE SPACEKEY
          JMP $9000 ;(RETURN TO ASSEMBLER) - CROSS ASSEMBLERS, JUST ADD RTS INSTEAD!

HELLOTXT   .TEXT "HELLO WORLD!"

RESULT:



Well that is not a good result, as the displayer uses the second set of characters (SHIFT+whatever key used), so what we will want to do is convert the chars by checking what they are. This can easily be done by adding some extra code into the loop which calls the text display. Change the code under ;DISPLAY HELLO WORLD to:

;DISPLAY HELLO WORLD! AT $0400

          LDX #$00
DISPHELLO LDA HELLOTXT,X
          CMP #$40 ;IS TEXT CHAR OVER #$40.
          BCC CHAROKAY ;ELSE DON'T CHANGE
          SEC      ;OTHERWISE CONVERT
          SBC #$40 ;TO CORRECT CHARS.
CHAROKAY  STA $0400,X
          INX
          CPX #$0B
          BNE DISPHELLO

There is a way to bypass this problem without needing to change this code, if you are using ACME cross assembler, as it uses a special screen command which is !SCR. So if you are using ACME, just change the !TEXT to !SCR. Otherwise, use this method if your are using a Turbo Assembler compatible cross assembler or TURBO ASSEMBLER itself. Another method would be to automatically use Action Replay cartridge machine code monitor to update the text. Test the result. Okay, now where SPACEKEY is, insert a INC $D020 but keep the LDA $DC01 prompt.



Now that's a bit of fun for you eh?. Hehehehe. Now for another screen example program.
              
Screen Data to Screen RAM 

How can we display text or characters on the screen? Easy, we use loops, but we need to use screen RAM, which is located in different memory banks. We shall stick to the normal C64 display bank ($0400 - $07E7), so that then we can display some text.

For a start off, let us try and something, which is located at $4000 and then pastes it through the whole of the screen area. Remember, this is only an experiment. There are different methods, but we'll use a simple method on displaying a screen, that is located at $4000.

;================================
;DISPLAYING TEXT AT BANK #$03
;================================

;SET UP PERAMETERS

SCREENLOC1 = $4000
SCREENLOC2 = $4100
SCREENLOC3 = $4200
SCREENLOC4 = $42E8

SCREENPOS1 = $0400
SCREENPOS2 = $0500
SCREENPOS3 = $0600
SCREENPOS4 = $06E8

                    * = $0900
                    SEI
                    LDX #$00                                ;X=0
DISPLAY   LDA SCREENLOC1,X          ;READ FROM SCREENLOC1 'X' TIMES
                    STA SCREENPOS1,X           ;PASTE TO SCREENPOS1 'X' TIMES
                    LDA SCREENLOC2,X         ;READ FROM SCREENLOC2 'X' TIMES
                    STA SCREENPOS2,X           ;PASTE TO SCREENPOS2 'X' TIMES
                    LDA SCREENLOC3,X         ;READ FROM SCREENLOC3 'X' TIMES
                    STA SCREENPOS3,X           ;PASTE TO SCREENPOS3 'X' TIMES
                    LDA SCREENLOC4,X         ;READ FROM SCREENLOC4 'X' TIMES
                    STA SCREENPOS4,X           ;PASTE TO SCREENPOS4 'X' TIMES
                    INX                                         ; X=X+1 UNTIL X = $FF (256)
                    BNE DISPLAY                      ;IF X <> $FF THEN GOTO DISPLAY
                    RTS                                        ;END PROGRAM

Compared to using BASIC, this routine is smaller and more compact to display text.

Now that you know how to display the screens, we want to display colours for the text. And here is how we can do this:

The colour RAM is always between $D800 and $DBE7. Therefore, variables can be created for the colours. So create some new variables, which are as follows:

COLOURPOS1 = $D800
COLOURPOS2 = $D900
COLOURPOS3 = $DA00
COLOURPOS4 = $DAE8

Then inside your loop (underneath STA SCREENPOS4,X) enter the following:

                              LDA #$0A
                    STA COLOURPOS1,X
                    STA COLOURPOS2,X
                    STA COLOURPOS3,X
                    STA COLOURPOS4,X

You don't just get the screen displaying only text, but you get the text to display painted in pink ;o)

Why not play around with the colours. Here is a small table on which colour does what job :o)

 
 
Hexadecimal ($)
Colour
$00
Black
$01
White
$02
Red
$03
Cyan
$04
Purple
$05
Green
$06
Blue
$07
Yellow
$08
Orange
$09
Brown
$0A
Pink
$0B
Dark Grey
$0C
Medium Grey
$0D
Light Green
$0E
Light Blue
$0F
Light Grey

Next Page / Previous Page / Back to Contents Page