Jump to content
  • Advertisement
Sign in to follow this  

[Solved:] C64 Assembly Beginner Problem

This topic is 702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,


I just started to work through the great article

A c64 game in several steps (lots of 'em)


Unfortunately I already have a beginner problem in Step 2 and was sondering if

anyone here was familiar with assembly programming on the Commodore C64?

Here's my problem:

In Step 2 the author, Endurion, introduced a routine to copy an own character set

to memory. Here's a direct link to step 2:



There's some code in here which I *really* can't understand, no matter how much I try.

Here's the direct link to the zipped source: step2.zip.

Here's the code I don't understand:

!zone CopyCharSet
          ;set target address ($F000)
          lda #$00
          sta ZEROPAGE_POINTER_2
          lda #$F0
          sta ZEROPAGE_POINTER_2 + 1

          ldx #$00
          ldy #$00
          lda #0
          sta PARAM2

          lda (ZEROPAGE_POINTER_1),Y
          sta (ZEROPAGE_POINTER_2),Y
          cpx #$8
          bne .NextLine
          cpy #$00
          bne .PageBoundaryNotReached
          ;we reached the next 256 bytes, inc high byte
          inc ZEROPAGE_POINTER_1 + 1
          inc ZEROPAGE_POINTER_2 + 1


          ;only copy 254 chars to keep irq vectors intact
          inc PARAM2
          lda PARAM2
          cmp #254
          beq .CopyCharsetDone
          ldx #$00
          jmp .NextLine


          !binary "j.chr"

I think I get most of this, but what I rally can't understand is what Endurion

is doing with the X register?

He initializes the X register with 0, then under .NextLine, after copying

one byte of the character set he is copying to memory, he increases it

by one (INX). Then he compares it to #$8 (CPX #$8):

          cpx #$8
          bne .NextLine

Then, if it is NOT equal to 8 yet, he jumps right back to .NextLine

(BNE .NextLine) and copies another byte.

So effectively, he is copying the first 8 bytes, then he is continuing

after the BNE .NextLine line for the first time and does everything else.

But why?

Why do all the other checks only every 8 bytes?

He checks if he must increase the pointers after 256 bytes were copied

and he checks if he copied 254 bytes yet (not wanting to overwrite the

last two), but why do all these checks only every 8 bytes?

Everything he does with the X register makes no sense to me at all. But when

I just comment out those lines the program doesn't run as it should anymore.

It runs but the graphics look different.

Is anyone here familiar with what's going on here in this great article / series

by Endurion? I would really appreciate any help!





---------- Edit 30 Min later: -----------


I contacted Endurion about this as well and he already helped me out! :-)


I made the stupid mistake of thinking, that because a character can be

addressed, a.k.a. "represented" by a program by only one Byte (such

as in ASCII or PETSCII with 256 characters codes), that naturally, such

characters only *HAVE* one Byte (in memory) also! :blink:


It's *very* hard to make readable characters with LESS than 8 pixels on each side...! :ph34r:
So even the minimal C64 characters have 8 x 8 pixels = 8 x 8 Bits = 8 Bytes in memory.


So all the testing done by Endurion is done ONLY after he already checked

that he read ONE FULL CHARACTER = 8 Bytes(!) (not as I assumed, 1 Byte).

He then checks to see if he's read 254 CHARACTERS yet (so as not to

overwrite stuff in the destination). And, he checks to see if Y is 256 yet, which

conveniently is a multitude of 8, or rather has overflowed from 255 to 0, to see

if he must manually increase the pointers to the next possible 256 addresses

to acces (with "absolute, Y-indexed addressing)...

I think I got it now! :-)


Share this post

Link to post
Share on other sites

For good reasons, Moderators have several times discouraged and removed "Solved" from thread titles.


[Solved] has remained on this thread for a while now. Is it an oversight, inconsistency or because the thread had no discussions before OP's own self solution? 

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!