2
votes

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)
2
1) By using two strore instructions. 2) By utilizing the fact that adc will add the value of the operand, plus 1 if the carry flag is set.Michael

2 Answers

2
votes
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
2
votes

Remember that you might need to update the color ram at $D800-$DBFF. Different KERNAL-versions have different default values. At least one version sets the character color to the same color as the background color, so the characters will be invisible unless the color ram is updated. Also remember that writing directly to the screen memory uses different codes.

Adding 16 bits

Before using adc (add with carry) you should clear the carry flag (clc).

clc            ; Clear carry before adc
lda LowByte    ; Load the current value of LowByte
adc #LowValue  ; Add the value. Carry is set if result > 255, cleared otherwise 
sta LowByte    ; Write the result to LowByte
lda HiByte     ; Load the curent value of HiByte
adc #HiValue   ; Add the value. (use 0 if needed) The carry-flag will be used
sta HiByte     ; Write the reslt to HiByte

Using KERNAL functions to print to the screen

The KERNAL has a PLOT function to position where the next character will be printed, and a CHROUT to print a PETSCII code. The CHROUT function supports control characters, so you can do CR to get a new line or change colors.

clc            ; Clear carry to set value
ldx #row       ; Load the desired row in the X register
ldy #column    ; Load the desired column in the Y register
jsr $FFF0      : Calling KERNAL:PLOT

lda #41        ; PETSCII code to print
jsr $FFD2      ; Calling KERNAL:CHROUT 

Note that the PLOT function takes the row in X and column in Y, and that the values are zero-based: 0,0 is upper left corner