Marrin

The Monster Trivia Converter

Oct 27th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.96 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>The Trivia Monster Converter</title>
  7. </head>
  8. <body style="width: 50em; margin: 2em;">
  9.  
  10.     <noscript style="color: red;"><strong>Attention:</strong> The converter
  11.     needs JavaScript enabled.</noscript>
  12.  
  13.     <h1>The Trivia Monster Converter</h1>
  14.  
  15.     <p>Converter for question files of the game „The Trivia Monster“ by Paul
  16.     Norman, published 1984 by Cosmi, for the C64.</p>
  17.  
  18.     <p>The program displays general hints for the answers while loading the main
  19.     program:</p>
  20.  
  21. <pre>
  22.     HINTS FOR ANSWERING QUESTIONS:
  23.  
  24.     DO NOT USE 'THE' IN YOUR ANSWERS
  25.     UNLESS IT IS A BOOK OR FILM TITLE.
  26.     SPELL ALL NUMBER ANSWERS AND HYPHENATE
  27.     TWO-DIGIT NUMBERS. UNLESS OTHERWISE
  28.     INDICATED BY (NO.)
  29.     USE FULL NAMES AS COMMONLY KNOWN
  30.     UNLESS THE QUESTION ASKS FOR (LST.NM)
  31.     OR IF ONLY LAST NAMES ARE IN USED TRIVIA
  32. </pre>
  33.  
  34.     <p>So it makes sense to write the questions and answers accordingly.</p>
  35.  
  36.     <h2>Example of an entry</h2>
  37.  
  38. <pre>
  39.     2AWHAT IS THE BEST, MOST SELLING HOME
  40.     COMPUTER OF ALL TIMES?
  41.     COMMODORE SIXTY-FOUR
  42. </pre>
  43.  
  44.     <p>Lines are max. 40&nbsp;characters long.  Three lines per entry.</p>
  45.  
  46.     <p><code>2</code> is the category.  Followed by a character between
  47.     <code>A</code> and <code>C</code> which I don't know the meaning of yet.
  48.     Then follows the question in the first two lines.  And finally the answer in
  49.     the last line.</p>
  50.  
  51.     <p>Each file has 135&nbsp;entries with three lines each = 135&centerdot;3 =
  52.     405&nbsp;lines in total.</p>
  53.  
  54.     <h2>Categories</h2>
  55.     <p>
  56.         <ol>
  57.             <li>Science</li>
  58.             <li>History</li>
  59.             <li>Sports</li>
  60.             <li>Grabbag</li>
  61.             <li>The Arts</li>
  62.             <li>Showbizz</li>
  63.         </ol>
  64.     </p>
  65.  
  66.     <h2>Converter</h2>
  67.  
  68.     <p>Enter/copy 405 lines of ASCII text in the expected format.  Upper or
  69.     lower case doesn't matter, it ends up being upper case after the
  70.     conversion.</p>
  71.  
  72.     <p>
  73.         <textarea id="text" cols="40" rows="25" placeholder="Questions and Answers&hellip;">
  74.         </textarea>
  75.         <button onclick="convert()">Convert</button>
  76.     </p>
  77.     <hr>
  78.  
  79.     <small>Version 0.1 &bullet; &copy; 2026 by BlackJack/Civitas &bullet; HTML5
  80.     & Vanilla JS</small>
  81.  
  82.    <script>
  83.        const START_ADDRESS = 0x6000;
  84.         const END_ADDRESS = 0x9F80;
  85.         const ENTRY_COUNT = 135;
  86.         const LINES_PER_ENTRY = 3;
  87.         const LINE_COUNT = ENTRY_COUNT * LINES_PER_ENTRY;
  88.  
  89.         function convert() {
  90.             let lines = document.getElementById("text").value.trim().split("\n");
  91.             if (lines.length != LINE_COUNT) {
  92.                 alert(`Expected ${LINE_COUNT} lines, got ${lines.length} instead!`);
  93.                 return;
  94.             }
  95.  
  96.             for (let i = 0; i < lines.length; i += 3) {
  97.                const line = lines[i];
  98.                const category = line[0];
  99.                if (category < 1 || category > 6) {
  100.                     alert(`Line ${i + 1}: Unexpected category: ${category}!`);
  101.                     return;
  102.                 }
  103.                 // TODO: Check unkown second character.
  104.             }
  105.  
  106.             lines = lines.map((line) => line.trim());
  107.             for (let i = 0; i < lines.length; i++) {
  108.                const line = lines[i];
  109.                if (line.length > 40) {
  110.                     alert(`Line ${i + 1}: length limit exceeded: ${line.length}.`);
  111.                     return;
  112.                 }
  113.             }
  114.  
  115.             const data = (new Uint8Array(END_ADDRESS - START_ADDRESS + 2)).fill(32);
  116.             data[0] = START_ADDRESS % 256;
  117.             data[1] = Math.floor(START_ADDRESS / 256);
  118.             const encoder = new TextEncoder();
  119.             for (let i = 0; i < lines.length; i++) {
  120.                const line = encoder.encode(lines[i]);
  121.                for (let j = 0; j < line.length; j++) {
  122.                    let value = line[j];
  123.                    if (value >= 128) {
  124.                         alert(`Line ${i + 1}: character outside ASCII.`);
  125.                         return;
  126.                     } else if (value >= 96) {
  127.                         value -= 96;
  128.                     } else if (value >= 64) {
  129.                         value -= 64;
  130.                     }
  131.                     line[j] = value;
  132.                 }
  133.                 data.set(line, 2 + i * 40);
  134.             }
  135.  
  136.             const blob = new Blob([data], { type: "application/octet-stream" });
  137.             const url = URL.createObjectURL(blob);
  138.             const link = document.createElement("a");
  139.             link.href = url;
  140.             link.download = "1prg";
  141.             document.body.appendChild(link);
  142.             link.click();
  143.             document.body.removeChild(link);
  144.             URL.revokeObjectURL(url);
  145.         }
  146.     </script>
  147. </body>
  148. </html>
Tags: C64
Add Comment
Please, Sign In to add comment