Printing Petscii Faster

https://news.ycombinator.com/rss Hits: 9
Summary

How can we display pretty PETSCII art on the C64 as quickly as possible only using BASIC?You might recall we have been steadily building a C64 Text Adventure / game engine, and as part of the last update I created a fancy PETSCII intro screen.The problem with it is it takes a long time to load. So long, in fact, that I put a “skip intro” feature into it, even though the end result is just a static piece of PETSCII art.Ideally a welcome image should be either immediately visible, or as close as possible to that, while also being attractive. Is that possible on the C64?Well, obviously, it is possible because people do it, some of the PETSCII editors even output .PRG binaries, and the option to use assembly is there if we want it too. This isn’t an assembly tutorial though, it is about C64 BASIC. Where does that leave us?Optimising the BASIC PETSCII Display LoopC64 BASIC is not the most efficient 6502 BASIC interpreter out there, but there are things you can do to speed it up, as you can see below:Result of the C64 BASIC OptimisationThat is roughly now twice as fast by my count. Certainly noticeable when side-by-side. Still not exactly flashing up on screen like it would be compiled with assembly, but it is better.How did I speed it up?First, small incremental improvements can be made by bunching up lines of code to instead be all in one line: FOR I = 0 TO 999 READ C: GET I$: IF I$ <> "" THEN RETURN POKE 1024+I,C NEXT I Becomes … FOR I = 0 TO 999 : READ C: POKE 1024+I,C : NEXT I Losing the check for a keypress also makes a small difference – Giving the C64 less to do per loop.Next, in the same pattern of giving the C64 less to do, perhaps we should ignore 32 characters as they are just blank spaces? We can put an IF in there.Surprisingly, the IF check is so slow, it is quicker to output the spaces than check for them!With and without checks for blank spacesThe final tweak we can do to this approach is remove the math. FOR I = 1024 TO 2023 : READ C: POKE I,C: NEXT I Bef...

First seen: 2025-10-15 04:41

Last seen: 2025-10-15 12:42