Video display modes: Difference between revisions

Added Commodore BASIC (Commodore 64)
m (→‎{{header|Raku}}: Fix comment: Perl 6 --> Raku)
(Added Commodore BASIC (Commodore 64))
Line 38:
=={{header|BBC BASIC}}==
<lang bbcbasic>10 MODE 1: REM 320x256 4 colour graphics</lang>
 
=={{header|Commodore BASIC}}==
===Commodore 64===
 
Since BASIC V2 on the Commodore 64 has no specific commands to operate the graphics functions of the VIC-II, video modes must be activated by directly manipulating the various registers of the VIC-II chip. Also, no initialization is done of any user-programmable graphics memory at start up, as it is not known at startup what memory locations will be utilized for graphics. It is up to the user to decide how to utilize the memory and then make the appropriate initialization.
 
 
====Summary of Video Modes====
 
 
* '''Standard Character Mode'''
** 40 x 25 characters.
** Single foreground color per character.
** 16 colors available for use.
** Font data comes from ROM.
 
* '''Multicolor Character Mode'''
** 40 x 25 characters.
** Characters are either single colored or multi-colored.
** Multi-color allows for 3 foreground colors per character.
** 1 foreground color limited to first 8 colors of the palette; other 2 are global for entire screen, but may be any of 16 colors.
 
* '''Extended Color Mode'''
** Enables a total of 4 background colors which can be any of the 16 palette colors.
** Limits character set to only first 64 characters (no PETSCII graphics or reverse characters.)
 
* '''Programmable Character Mode'''
** Works with any of the modes described above.
** Exception is that font data comes from data in RAM.
 
* '''Standard High Resolution Bit Mapped Mode'''
** 320 x 200 pixel resolution.
** Single foreground color per 8x8 pixel cell.
** Single background color per 8x8 pixel cell.
** Foreground and background color can be any of the 16 color palette.
** Color information stored in character screen RAM, ''not'' color RAM.
 
* '''Multicolor Hi-res Bit Mapped Mode'''
** 160 x 200 pixel resolution.
** Each 4x8 cell can have 3 foreground colors and 1 global background color.
** Color information for foreground colors is stored in character screen RAM as well as color RAM (12 bits of color information).
 
 
====Explanation of Program====
 
{| class="wikitable"
!Lines
!Description
|-
|10-25
|Clear the screen, switch to lower-case mode, set the basic border, background, and foreground colors, including the extended and multicolors.
|-
|30
|Check to see if we've run this routine before by examining the first two bytes of our reserved graphics area. If we have, skip it. (It does take some time to complete.)
|-
|35
|Tell BASIC to limit its RAM usage to a new top-end of 8K. The following 8K (8192 to 16384) will be reserved for graphics data to be used by the VIC-II.
|-
|40
|Let the user know we're initializing.
|-
|45
|The contents of the character ROM are not normally visible to the CPU and must be switched through the I/O port of the CPU. However, this will also make certain interrupt functions running in the background fail, so interrupts must be turned off by stopping the interrupt timer on CIA 2 (first <code>POKE</code> in line 45) before switching the ROM in (second <code>POKE</code> in line 45).
|-
|50
|Initialize part of the graphics area by copying all 4K of character ROM into the reserved graphics area.
|-
|55
|Switch out the ROM since we are done with it, and restart the interrupt timer.
|-
|60-115
|Modify a few characters to be custom designed (defined in <code>DATA</code> statements), and then define the rest of the reserved graphics memory with high-resolution lines (line 65), as well as a specific bit pattern that will help illustrate the high resolution multi-color mode (line 70).
|-
|480-810
|This section goes through each of the modes. Activation of the modes is called as a subroutine, and some video modes are actually a combination of discrete video modes.
|-
|1000-1020
|A subroutine to print some demonstration text to the screen to illustrate the variety of the various text modes. On lines 1011 and 1013, <code>chr$(160)</code> is the same as <code>SHIFT-SPACE</code> for the spaces between letters, which is distinctly different from a regular <code>SPACE</code> character (<code>CHR$(32)</code>).
|-
|1050-1065
|A subroutine to put a variety of color definition into the high-resolution bit map modes.
|-
|1100-1430
|These subroutines are the methods for switching certain discrete video modes on and off. This is done by specifically modifying the various registers in the VIC-II chip. Most of these are then combined to achieve other video modes.
|-
|9000-9020
|Finally, a generic "wait for keypress" routine.
|}
 
 
====Program Listing====
 
<lang gwbasic>10 rem video modes - c64
15 rem rosetta code
20 print chr$(147);chr$(14):poke 53280,0:poke 53281,0:poke 646,1
25 poke 53282,2:poke 53283,11:poke 53284,9:rem set extended and multi colors
30 if peek(12288)=60 and peek(12289)=102 then goto 100
35 poke 52,32:poke 56,32:clr
40 print "Initializing - Please wait..."
45 poke 56334,peek(56334) and 254:poke1,peek(1) and 251
50 for i=0 to 4096:poke i+12288,peek(i+53248):next
55 poke1,peek(1) or 4:poke56334,peek(56334) or 1
60 for i=0 to 31:read d:poke 15368+i,d:next i
65 x=0:for i=8192 to 10239:poke i,2^x:x=(x+1) and 7:next
70 for i=10240 to 12287:poke i,228:next
100 data 60,66,165,129,165,153,66,60
105 data 60,66,165,129,153,165,66,60
110 data 245,245,245,245,10,10,10,10
115 data 10,10,10,10,245,245,245,245
480 print chr$(147);"Demonstration of Video Modes"
485 print
490 print "The video modes described at Rosetta ";
495 print "Code will be demonstrated in order. ";
500 print "Simply press a key to advance to the";
505 print "next video mode.";
510 print
515 print "See rosettacode.org for description."
520 print
525 print "Press any key to begin."
530 gosub 9010
600 print chr$(147);"Standard Character Mode"
605 print " - ROM Characters"
610 print:gosub 1000:print:gosub 9000:print chr$(147)
615 gosub 1210
620 print chr$(147);"Multicolor Character Mode"
625 print " - ROM Characters"
630 print:gosub 1000:print:gosub 9000:print chr$(147)
635 gosub 1220
640 gosub 1310
645 print chr$(147);"Extended Color Character Mode"
650 print " - ROM Characters"
655 print:gosub 1000:print:gosub 9000:print chr$(147)
660 gosub 1320
665 gosub 1100
670 print chr$(147);"Standard Character Mode"
675 print " - Programmed Characters"
680 print:gosub 1000:print:gosub 9000:print chr$(147)
685 gosub 1210
690 print chr$(147);"Multicolor Character Mode"
695 print " - Programmed Characters"
700 print:gosub 1000:print:gosub 9000:print chr$(147)
705 gosub 1220
710 gosub 1310
715 print chr$(147);"Extended Color Character Mode"
720 print " - Programmed Characters"
725 print:gosub 1000:print:gosub 9000:print chr$(147)
730 gosub 1320
735 print chr$(147);"The next screen will be the"
740 print "High Resolution Bit Map Mode"
745 print
750 gosub 9000
755 gosub 1430:gosub 1410
760 print:gosub 1050:print:gosub 9010:print chr$(147)
765 gosub 1420:gosub 1120
770 print chr$(147);"The next screen will be the"
775 print "Multicolor High Resolution Bit Map Mode"
780 print
785 gosub 9000
790 gosub 1430:gosub 1410:gosub 1210
795 print:gosub 1050:print:gosub 9010:print chr$(147)
800 gosub 1420:gosub 1220:gosub 1120
805 print chr$(147);"End of demonstration."
810 end
1000 rem put some characters up for demo
1005 for i=0 to 15:poke 646,i
1010 print" a b c d ";
1011 print chr$(160);"A";chr$(160);"B";chr$(160);"C";chr$(160);"D";chr$(160);
1012 print chr$(18);" a b c d ";
1013 print chr$(160);"A";chr$(160);"B";chr$(160);"C";chr$(160);"D";chr$(160);
1014 print chr$(146)
1015 next i:poke 646,1
1020 return
1050 rem show color variety for hi-res modes
1051 print chr$(147)
1055 for i=0 to 255:poke 1024+i,i:poke 55296+i,1:next
1060 for i=0 to 255:poke 1280+i,i:poke 55552+i,int(rnd(1)*16):next
1065 return
1100 rem programmable character mode
1110 poke 53272,(peek(53272) and 240)+14:return:rem on
1120 poke 53272,(peek(53272) and 240)+6:return:rem off
1200 rem multicolor mode
1210 poke 53270,peek(53270) or 16:return:rem on
1220 poke 53270,peek(53270) and 239:return:rem off
1300 rem extended color mode
1310 poke 53265,peek(53265) or 64:return:rem on
1320 poke 53265,peek(53265) and 191:return:rem off
1400 rem hi res mode
1410 poke 53265,(peek(53265) or 32):return:rem on
1420 poke 53265,(peek(53265) and 223):return:rem off
1430 poke 53272,peek(53272) or 8:return:rem place bitmap at 8192
9000 print "Press any key for next screen.";
9010 get k$:if k$="" then 9010
9020 return</lang>
 
=={{header|ERRE}}==
113

edits