Search code examples
assemblyc64

C64 assembly store memory address and increase it


I learn now KickAss assembler for C64, but i'm never learnd any asm or 8 bit computing before. I want to print big ascii banner (numbers). I want to store the "$0400" address in the memory and when i'm increased the line number i need to increase it by 36 (because the sceen is 40 char width so i want to jump ti next line), but my problem is this is a 2 byte number so i can't just add to it. This demo is works "fine" except the line increasing because i dont know that.

So what i'm need:

  1. How can i store a 2 byte memory address in a memory?
  2. How can i increase the memory address and store back (2 byte)?
  3. How can i store a value to the new address (2 byte and index registers is just one)?

Thx a lot guys!

BasicUpstart2(main)

*=$1000

currentLine:
    .byte 00

main:
        printNumber(num5)
        rts


num5:   .byte $E0, $E0, $E0, $E0, $00     // XXXX(null)
        .byte $E0, $20, $20, $20, $00     // X   (null)
        .byte $E0, $20, $20, $20, $00     // X   (null)
        .byte $E0, $E0, $E0, $E0, $00     // XXXX(null)
        .byte $20, $20, $20, $E0, $00     //    X(null)
        .byte $20, $20, $20, $E0, $00     //    X(null)
        .byte $E0, $E0, $E0, $E0, $00     // XXXX(null)


.macro printNumber(numberLabel)
{
    ldx #0
    lda #0
    
    lda #0
    
loop:
    lda numberLabel,x
    beq checkNextline
    sta $0400,x
    inx
    jmp loop
checkNextline: 
    inx
    inc currentLine
    lda currentLine
    cmp #7    
    beq done
    jmp loop
done:
}


// Expected output:

XXXX
X
X
XXXX
   X
   X
XXXX

// Current output:
XXXXX   X   XXXX   X   XXXXX


(where the X is the $E0 petscii char)

Solution

  • clc
    lda LowByte    ; Load the lower byte
    adc #LowValue  ; Add the desired value
    sta LowByte    ; Write back the lowbyte
    lda HiByte     ; No load hi byte
    adc #HiValue   ; Add the value.
    sta HiByte