Classic Computer Magazine Archive COMPUTE! ISSUE 40 / SEPTEMBER 1983 / PAGE 216

Mixing Graphics
Modes On The 64

Part II

Sheldon Leemon

The two programs in the first part of this article (last month's COMPUTE!) showed you how to have different graphics modes simultaneously on the 64 screen. To conclude this discussion of mixing modes, here is a machine language program which uses a mixed graphics mode display to demonstrate the raster interrupt.



The interrupt uses a table of values that are POKEd into four key locations during each of the three interrupts, as well as values to determine at what scan lines the interrupts will occur. The locations affected are Control Register 1, Control Register 2, the Memory Control Register, and Background Color 0.
    Control Register 1 (at location 53265) allows the selection of extended background color text mode, bitmap mode, screen blanking, and 24 or 25 rows of text. Control Register 2, at 53270, controls the selection of multicolor mode, and of a 38-or 40-column display. The Memory Control Register (53272) allows you to select which portion of VIC memory will be used for the video display (screen memory), and which for the data that defines the shape of text characters. Background Color Register 0 (53281) controls the background color in text mode. More detailed information about the bit assignments of these locations can be found in Appendix O of the Commodore 64 User's Guide and in the Programmer's Reference Guide.
    The data for the interrupt routine is contained in lines 49152-49276. Each of these line numbers corresponds to the location where the first data byte in the statement is POKEd into memory. If you look at lines 49264-49276 of the BASIC program, you will see REMark statements that explain which VIC-II registers are affected by the DATA statements in each line. The numbers in these DATA statements appear in the reverse order in which they are put into the VIC register. For example, line 49273 holds the data that will go into Control Register 2. The last number, 8, is the one that will be placed into Control Register 2 while the top part of the screen is displayed. The first number, 24, is placed into Control Register 2 during the bottom part of the screen display and changes that portion of the display to multicolor mode.
    The only tricky part in determining which data byte affects which interrupt comes in line 49264, which holds the data that determines the scan line at which each interrupt will occur. Each DATA statement entry reflects the scan line at which the next interrupt will occur. The first item in line 49264 is 49. Even though this is the entry for the third interrupt, this number corresponds to the top of the screen (only scan lines 50-249 are visible on the display). That is because after the third interrupt, the next to be generated is the first interrupt, which occurs at the top of the screen. Likewise, the last data item of 129 is used during the first interrupt to start the next one at scan line 129, in the middle of the screen. Try experimenting with these values to see what results you come up with. For example, if you change the number 169 to 209, you will increase the text area by five lines (40 scan lines).

Changing Effects
By changing the values in the data tables, you can alter the effect of each interrupt. Change the 20 in line 340 to 22, for example, and you will get lowercase text in the middle of the screen. Change the first 8 in line 49276 to 24, and you will get multicolor text in the center window. Each of these table items may be used in exactly the same way that you would use the corresponding register, in order to change background color, to obtain text or bitmap graphics, regular or multicolor modes, screen blanking, or extended background color mode.

Machine Language Interrupt Routine

00012 0000          ; VIC CHIP EQUATES
00013 0000          ;
00014 0000          SCROLY = $D0ll        ;CONTROL REGISTER 1
00015 0000          RASTER = $D012        ;RASTER LOCATION
00016 0000          SCROLX = $D016        ;CONTROL REGISTER 2
00017 0000          VMCSB  = $D018        ;V/C BASE ADDRESS
00018 0000          VICIRQ = $D019        ;LATCHES ON IRQ FROM VIC
00019 0000          IRQMSK = $D0lA        ;VIC IRQ ENABLE
00020 0000          BGCOLO = $D021        ;BACKGROUND COLOR 0
00021 0000          CIAICR = $DC0D        ;INTERRUPT CONTROL
00022 0000          ;
00023 0000          INTNO  = $FB          ;INTERRUPT COUNTER
00024 0000          ;
00025 0000                 * = $C000
00026 C000          ;
00027 C000 78       SETIRQ SEI            ;DISABLE ALL INTERRUPTS
00028 C001 A9 7F           LDA #$7F
00029 C003 8D 0D DC        STA CIAICR     ;DISABLE CIA INTERRUPTS
00030 C006 A9 01           LDA #01
00031 C008 8D lA D0        STA IRQMSK     ;ENABLE RASTER IRQ
00032 C00B A9 03           LDA #03
00033 C00D 85 FB           STA INTNO      ;INITIALIZE INTERRUT NO.
00034 C00F AD 70 C0        LDA RASTBL
00035 C012 8D 12 D0        STA RASTER     ;SET SCAN LINE OF TOP RIRQ
00036 C015 A9 18           LDA #24
00037 C017 8D 11 D0        STA $D011      ;SET HIGH BIT OF RIRQ SCAN LINE
00038 C01A         ;
00039 C01A AD 14 03        LDA $314       ;SAVE OLD IRQ VECTOR AND
00040 C01D 8D 6E C0        STA OLDIRQ+1   ;MODIFY OLDIRQ TARGET ADDRESS TO
00041 C020 AD 15 03        LDA $315       ;INSURE AGAINST CHANGE IN ADDRESS
00042 C023 8D 6F C0        STA OLDIRQ+2   ;OF NORMAL INTERRUPT.ROUTINE
00043 C026    ;
00044 C026 A9 32           LDA #<RASIRQ   ;SET IRQ VECTOR
00045 C028 8D 14 03        STA $314       ;TO USER ROUTINE
00046 C02B A9 C0           LDA #>RASIRQ
00047 C02D 8D 15 03        STA $315
00048 C030 58              CLI            ;RE-ENABLE INTERRUPTS
00049 C031 60              RTS
00050 C032          ;
00051 C032          ;
00052 C032 AD 19 D0 RASIRQ LDA VICIRQ
00053 C035 8D 19 D0        STA VICIRQ     ;CLEAR VIC INTERRUPTS
00054 C038 29 01           AND #01        ;IS RASTER THE SOURCE OF IRQ?
00055 C03A F0 2B           BEQ INTRT      ;NO, EXIT
00056 C03C C6 FB           DEC INTNO      ;NEXT INTERRUPT
00057 C03E 10 04           BPL RAS1       ;NOT LAST INTERRUPT
00058 C040 A9 02           LDA #2         ;LAS INTERRUPT, RESET COUNTER
00059 C042 85 FB           STA INTNO
00060 C044          ;
00061 C044 A6 FB    RAS1   LDX INTNO
00062 C046 BD 73 C0        LDA COLTBL,X   ;SET BACKGROUND COLOR
00063 C049 8D 21 D0        STA BGCOLO
00064 C04C BD 76 C0        LDA CRITBL,X   ;SET-CONTROL REG 1
00065 C04F 8D 11 D0        STA SCROLY
00066 C052 BD 79 C0        LDA CR2TBL,X   ;SET CONTROL REG 2
00067 C055 8D 16 D0        STA SCROLX
00068 C058 BD 7C C0        LDA MEMTBL,X   ;SET MEMORY CONTROL
00069 C05B 8D 18 D0        STA VMCSB
00070 C05E BD 70 C0        LDA RASTBL,X   ;RESET INTERRUPT SCAN LINE
00071 C061 8D 12 D0        STA RASTER
00072 C064 8A              TXA            ;LAST INTERRUPT EMITS
00073 C065 F0 06           BEQ OLDIRQ     ;THROUGH OLD VECTOR
00074 C067         ;
00075 C067 68      INTRT   PLA            ;RESTORE STACK
00076 C068 A8              TAY
00077 C069 68              PLA
00078 C06A AA              TAX
00079 C06B 68              PLA
00080 C06C 40              RTI
00081 C06D          ;
00082 C06D 4C 31 EA OLDIRQ JMP $EA31      ;OLD IRQ--ADDRESS MODIFIED ABOVE
00083 C070    ;
00084 C070 31       RASTBL .BYT 49,170,129;SCAN LINE OF NEXT INTERRUPT
00084 C071 AA
00084 C072 81
00085 C073 00       COLTBL .BYT 0,6,0     ;BACKGROUND COLORS
00085 C074 06
00085 C075 00
00086 C076 3B       CRITBL .BYT 59,27,59  ;CONTROL REGISTER 1 VALUES
00086 C077 1B
00086 C078 3B
00087 C079 18       CR2TBL .BYT 24,8,8    ;CONTROL REGISTER 2 VALUES
00087 C07A 08
00087 C07B 08
00088 C07C 18       MEMTBL .BYT 24,20,24  ;MEMORY CONTROL REGISTER VALUES
00088 C07D 14
00088 C07E 18
00089 C07F
00090 C07F                 .END