簡體   English   中英

C64匯編存儲memory地址並增加

[英]C64 assembly store memory address and increase it

我現在學習 C64 的 KickAss 匯編程序,但我以前從未學習過任何 asm 或 8 位計算。 我想打印大的 ascii 橫幅(數字)。 我想將“$ 0400”地址存儲在 memory 中,當我增加行號時,我需要將其增加 36(因為屏幕是 40 字符寬度,所以我想跳到下一行),但我的問題是這是一個 2 字節的數字,所以我不能只添加它。 這個演示工作“很好”,除了線增加,因為我不知道。

所以我需要的是:

  1. 如何在 memory 中存儲 2 字節 memory 地址?
  2. 如何增加 memory 地址並存儲回來(2 字節)?
  3. 如何將值存儲到新地址(2 字節和索引寄存器只是一個)?

謝謝很多人!

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)
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

請記住,您可能需要在 $D800-$DBFF 更新顏色 ram。 不同的 KERNAL 版本有不同的默認值。 至少有一個版本將字符顏色設置為與背景顏色相同的顏色,因此除非更新顏色 RAM,否則字符將不可見。 另請記住,直接寫入屏幕 memory 使用不同的代碼。

添加 16 位

在使用adc ( add with carry ) 之前,您應該清除進位標志 ( 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

使用 KERNAL 函數打印到屏幕

KERNAL 有一個 PLOT function 到 position 將打印下一個字符,以及一個用於打印 PETSCII 代碼的 CHROUT。 CHROUT function 支持控制字符,因此您可以執行 CR 以獲取新行或更改 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 

請注意,PLOT function 采用 X 中的行和 Y 中的列,並且值是從零開始的:0,0 是左上角

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM