2

I'm new to assembler programming for the C64 and I have a question about the procedure for saving and loading memory areas. I am concerned with the following:

lda #$01
sta $0400

Puts the letter A to the top left on the screen

ldx #$00
lda #$01
sta $0400, x

with this I can use x register as an counter and can compare how often I will use a loop.

But now I have a 16-Bit calculate (Screen start address plus xxx) and store the result inside a memory address like $4000 und $4001. How can I use this value as the new screen address to print out the letter a on the calculated area on the screen?

Paul R
  • 208,748
  • 37
  • 389
  • 560
DiscMix
  • 31
  • 2
  • Use the `(indirect),Y` addressing mode. For example, `sta ($10),y` (where $10 is the address where you've stored the base address). – Michael Sep 20 '20 at 11:23
  • Thanks for fast feedback, but what is y? When value is $18 in memory adress $4000 and value is $05 in memory address $4001 (18 05 > $0518 > Dez: 1304 = the screen address) how to use it: ldx #$00 //for loop lda #$01 //for letter a sta ($4000),y ?? – DiscMix Sep 20 '20 at 12:12
  • Y is the register Y. And the 16-bit address must be stored in zeropage memory (i.e. somewhere in the $00-$FF range). – Michael Sep 20 '20 at 12:13
  • I know that y is the y register ;) but what value must be y when I should use (indirect),y? – DiscMix Sep 20 '20 at 12:17
  • Whatever you need it to be to get the effective address that you want. I'm not really sure what you're asking. – Michael Sep 20 '20 at 12:30

1 Answers1

1

OK, now I understand the meaning of (indirect),Y My solution looks now like this:

.var lines = $28       //40 characters
.var currentPos = $fd  //save screen address

calcLine:  
ldx #$05               //counter 5 backward
ldy #$00               //Sets carry to 0
lda #lines             //A=40 
asl                    //A=80 

calc:
clc 
adc #lines             //A=120 (or $78 in hex) 
bcc next               //If carry, then increase
iny

next:
dex
cpx #$00
bne calc
sta currentPos     //If carry, then increase 
sty currentPos+1   //Save value if carry

//add screen start address ($0400)
clc
lda currentPos+1
adc #$04
sta currentPos+1

lda #$42    //the sign

sta (currentPos),y 
DiscMix
  • 31
  • 2