rdoetjes / c64

c64 assembly course
10 stars 2 forks source link

Something is wrong with offset to lower half of character #13

Open Gavin-Williams opened 1 year ago

Gavin-Williams commented 1 year ago

@ line 109 lesson 7, you have...

adc #127

That is wrong, you must add 128 to access the lower half of the character, given the character map you provided. For example...

Top A : index = 1 Btm A: index = 129

So it should be

adc #128

So the question is then, why does it work with 127 in your program. Well, I don't yet know, but when I tried implementing the scrolling text, I have this test code that draws the letter A 5 times...

    ScrollText:
    ldx #0          // screen index
    ldy textOffset  // text index

    // write character
    !:
    lda textMessage, y
    sta Screen.CharacterMap, x
    adc #128  
    sta Screen.CharacterMap + 40, x

    // inc screen index and escape if end of line reached
    inx
    cpx #5
    bne !-

    rts // debug

I get... AAAA BAAA

I found that the first character drawn is incorrect with 128, but the following characters are correct. I just can't see what's wrong, but I'm certain that you have to add 128 and not 127.

Here's a simplified program that tries to write 5 letter A's but has the incorrect bottom A in the first position.

https://1drv.ms/u/s!AhbcRtciy6_0jeAmUN9SrI6uQa3rfQ?e=O2rkGT

Gavin-Williams commented 1 year ago

So for my code, and this took me so long to work out. I had to put clc (clear carry flag) before calling adc #128. I don't know why the carry flag is set. But it interferes with the add in this case I guess.

rdoetjes commented 1 year ago

Yes for each add or sub instruction you will respectively beed to clear or set the carry flag.This is peculiarity of the 6502. This his tripped me up many times too. Especially because you get inconsistent behavior there are times it works but also times it fails. Very hard to debug indeed. But again you got there and this is the true learning experience. Taking the subject matter and wrangling with it. I’m curious to see what you are making. Send it over once it’s done. Always fun to see what people create.Cheer,RaySent from my iPhoneOn 14 May 2023, at 05:56, Gavin Williams @.***> wrote: So for my code, and this took me so long to work out. I had to put clc (clear carry flag) before calling adc #128. I don't know why the carry flag is set. But it interferes with the add in this case I guess.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>