Meneer_Jansen

Appendix B. PETSCII

Jul 3rd, 2020 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. .-----------------------------------.
  2. ( A P P E N D I X B . P E T S C I I )
  3. `-----------------------------------ยด
  4. general contents: https://pastebin.com/hmpJmurr
  5.  
  6.  
  7.  
  8. o==========o
  9. | Contents |
  10. o==========o
  11.  
  12. A. Character ROM, Character Sets
  13.  
  14. B. PETSCII, control characters and screen codes
  15. 1. PETSCII and control characters
  16. 2. Screen codes and character sets
  17.  
  18. X. References
  19.  
  20. -<>-<>-<>-<>-<>-<>-
  21.  
  22.  
  23.  
  24. o=====================================o
  25. | A. Character ROM and Character Sets |
  26. o=====================================o
  27.  
  28. Character ROM: a 4 kB chip that holds the default character's bitmaps.
  29.  
  30. The character ROM chip contains *two* Character Sets of 2 kB each. The first contains only upper case letters (used per default), the second also has lower case letters (and less graphical characters).
  31.  
  32. Only one is in use a time (you must choose between 'm). A Character Set holds 128 regular characters (letters and graphics) and 128 reversed chars (256 total = 2^8 = 8 bit; screen RAM can only hold 8 bit numbers). See [3] or appendix G in [5] for the two char. sets. One Character Set is 2 kB in size. Do the math:
  33.  
  34. One Character Set:
  35. 256 chars (regular and reversed) x (8 x 8 bits/character) =
  36. 256 x 64 bits =
  37. 256 x 8 Bytes =
  38. 2048 B = 2 kB
  39.  
  40. The second Character Set can be activated with Shift + C= (which changes case), via register D018_hex, or with PETSCII control character 0E_hex (see chapter 'PETSCII'). After switching Character Set (Shift C=) all characters on screen change.
  41.  
  42. The reverse characters in a Character Set can be activated with Ctrl + 9 (RVS ON), by setting register C7_hex or by PETSCII control character 12_hex (see chapter 'Petscii'). This probably sets an offset in the Character Set.
  43.  
  44. Realize that in Character ROM there are only 128 unique characters in a Chracter Set, the rest are the reverse ones. If one uses a custom character set in RAM (to make a game level) the screen codes from 128 to 255 are not reversed.
  45.  
  46.  
  47. o=================================================o
  48. | B. PETSCII, control characters and screen codes |
  49. o=================================================o
  50.  
  51. PETSCII is also called CBM ASCII. What is the difference between PETSCII, Control Characters, Screen Codes and a Character Set?
  52.  
  53. 1. PETSCII and control characters
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. To print characters on screen (hexadecimal) numbers are used by the kernal routine CHROUT (FFD2_hex) and by the BASIC command CHR$. Those numbers are called PETSCII code. See [1], [2] or appendix F in [5]. Some codes refer to a character (i.e. they print a letter or graphic character from character ROM on screen), some are "Control Characters" (i.e. they code for the carriage return, home, del, colors, etc.). An example is PETSCII code 0E_hex (14_dec): it changes case. The Character Set in use is changed then. Also notice that Screen RAM is not written to then since no character is printed on screen.
  56.  
  57. Try the following to print the letter A (PETSCII code 65_dec/41_hex) on screen:
  58.  
  59. PRINT CHR$(65)
  60. PRINT CHR$(14) lower case
  61. PRINT CHR$(142) upper case
  62.  
  63. There are 256 PETSCII codes (8 bit), 128 of which correspond to an actual printable non-reversed character. If you want to print the reversed characters one must set, for instance, register 00C7_hex in assembly. The control characters and 128 screen (character) codes in PETSCII do not add up to 256. Therefore some codes are duplicated [2]:
  64.  
  65. Codes 192-223 are as codes 96-127
  66. Codes 224-254 are as codes 160-190
  67. Code 255 are as code 126
  68.  
  69. A handy list of Control Characters and what they do can be found in [4].
  70.  
  71. 2. Screen codes and character sets
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. The so called Screen Code of a character is its place in a Character Set from character ROM/RAM (see [3] and appendix G in [5]). This is something different from it's (hexadecimal) PETSCII code. The Screen Code for the letter A, for instance, is nr. 1 (nr. 0 is the @ sign) and in PETSCII it's nr. 65_dec (41_hex). This is why in some programming routines the number 64 is added to the Screen Code of a letter. The Screen Code of a char is used in the BASIC command POKE and in screen RAM.
  74.  
  75. Try the following to print letter A (Screen Code 1, i.e. character 1 in Char. Set) in the upper left corner (1024_dec/400_hex is the start of screen RAM):
  76.  
  77. POKE 1024,1
  78. POKE 1024,129 :REM reverse A
  79.  
  80. One can print (reversed) characters 128 to 256 by loading 128_dec to 255_dec in screen memory (you don't have to change to reverse mode via register C7_hex).
  81.  
  82.  
  83.  
  84. o===============o
  85. | X. References |
  86. o===============o
  87.  
  88. [1] Complete Petscii table (for Assembly and CHR$):
  89. https://sta.c64.org/cbm64pet.html
  90.  
  91. [2] Condensed Petscii table (for Assembly and CHR$):
  92. https://www.c64-wiki.com/wiki/PETSCII
  93.  
  94. [3] Character set/screen codes for POKE):
  95. https://www.c64-wiki.com/wiki/Character_set
  96.  
  97. [4] Control characters (for Assembly and CHR$):
  98. https://www.c64-wiki.com/wiki/control_character
  99.  
  100. [5] "Mapping the C64", Sheldon Leemon, Compute! Publications Inc., ISBN 0-942386-23-X (1984).
  101.  
Add Comment
Please, Sign In to add comment