neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

PROC + ASM noob problem #118

Closed frenchfaso closed 4 years ago

frenchfaso commented 4 years ago

Hy there, thanks for this beautiful language, I'm really enjoying the gentle approach to asm that it enables! I'm trying to write a proc in asm that changes border and/or background color like this:

proc change_color(addr, col!) asm " lda {self}.col sta {self}.addr " endproc

for i! = 0 to 15 call change_color(53280, i!) call change_color(53281, i!) for t = 0 to 10000 rem slow down a bit... next t next i!

it compiles without errors and it also runs without problems, but neither color does change! If I put the address directly in the asm part, it works:

asm " lda {self}.col sta 53280 sta 53281 "

I'm surely missing something here... Thanks for your help!

neilsf commented 4 years ago

Hi. The problem here is that {self}.addr refers to the variable addr, not to the value that it holds. You'll need indirect addressing, something like this (not tested but I think you'll get the idea):

proc change_color(addr, col!)
asm "
  ; move the value of addr to the zeropage
  ; note R0 is a ZP address that is safe to use here
  lda {self}.addr
  sta R0
  lda {self}.addr + 1
  sta R0 + 1
  ; move col! to A
  lda {self}.col
  ldy #0
  sta (R0),y
"
endproc

Good luck!

frenchfaso commented 4 years ago

Thank you! that did the trick, seems like I have plenty to learn about 6510 ML :-)