back

by masswerk·1y ago·view on hn ↗
BASIC is about 1000 times slower, so there's no way we could do this in realtime. Moreover, as mentioned in the article, the original PET 2001 suffers from bus conflicts when the CPU and the video circuitry access the video memory at the same time, because of slow SRAM, which is just the same speed as the CPU. To avoid this, the BASIC used by these earlier models prints only during the vertical blanking interval (V-BLANK), when video is off. This is only about a quarter of the duty cycle, where PRINT can actually happen, slowing this down to a fraction of what BASIC could theoretically achieve.

Let's do some nerdy numbers: ;-)

We may try rendering this to static slides and store them as strings in DATA statements. At 16 cols and 16 rows, this is 256 bytes per frame and there are 100 of them (the current map width), which makes 25 KB. We'll also need memory for the overhead of this as BASIC lines, which is 2 bytes for the line number in binary, another two bytes for the link to the location of the next line in memory (a 16-bit pointer), 1 for the "DATA" token, and a zero-byte as the line delimiter (EOL), which makes 6 bytes per BASIC line. And we'll need another two bytes for the enclosing quotes per string, and one for a separating comma (if we put more then one string in a given line).

Assuming we store 3 strings in a line (of max 80 characters), this makes a total of 533.3 × (6 + 3 × 18 + 2) = 33,064 bytes (or 32.29 KB), the memory requirement to store just the DATA lines. – So there's no way to fit this into a machine, which maxes out at 32K in its most luxurious memory configuration (or 16K for the original PET 2001).

1 comments
Wow I didn't expect an author response!! Nice article, and it helps fulfill the weekly quota for 6502 articles on HN.

Well, I've never tried programming a PET before, but here is my cheap BASIC imitation which I tried in a web emulator:

    10 PRINT CHR$(147):A$=CHR$(19)
    20 B$="    ****    "
    30 C$="  **    **  "
    40 D$(0)=" ***     ** "
    50 D$(1)=" ** *    **"
    60 D$(2)=" **  *   **"
    70 D$(3)=" **   *  **"
    80 D$(4)=" **    * **"
    90 D$(5)=" **     ***"
    100 A=0
    110 FOR I=1 to 10000
    120 PRINT A$:PRINT B$:PRINT C$:PRINT D$(A)
    130 PRINT C$:PRINT B$
    140 A=A+1:IF A>5 THEN A=0
    150 NEXT I
In the emulator it seems to get around 10FPS with an 11x5 character matrix, but it may be possible to do better.
Well, here's a more realistic test, reading and printing 16 × 16 slides from DATA statements. With BASIC 2.0 more like 1.5 fps… :-)

BASIC 2.0 (slow PRINT): https://masswerk.at/pet/?prg=hn-globe-slides-test&rom=2

BASIC 4.0 (faster PRINT): https://masswerk.at/pet/?prg=hn-globe-slides-test&rom=4

The main part of the program is:

  10 PRINT CHR$(147)
  20 FOR F=0 TO 16
  30 PRINT CHR$(19);:FOR R=0 TO 15
  40 READ A$:PRINT TAB(12)A$:NEXT
  50 NEXT
  60 RESTORE:GOTO 20