【问题标题】:C64 assembly store memory address and increase itC64汇编存储内存地址并增加它
【发布时间】:2021-07-06 19:46:33
【问题描述】:

我现在学习 C64 的 KickAss 汇编程序,但我以前从未学习过任何 asm 或 8 位计算。我想打印大的 ascii 横幅(数字)。我想将“$ 0400”地址存储在内存中,当我增加行号时,我需要将其增加 36(因为屏幕是 40 字符宽度,所以我想跳到下一行),但我的问题是这是一个 2 字节的数字,所以我不能只添加它。这个演示工作“很好”,除了行增加,因为我不知道。

所以我需要什么:

  1. 如何在内存中存储 2 字节内存地址?
  2. 如何增加内存地址并回存(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)

【问题讨论】:

  • 1) 通过使用两条 strore 指令。 2)利用adc将添加操作数的值,如果设置了进位标志则加1。

标签: assembly c64


【解决方案1】:
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】:

    请记住,您可能需要在 $D800-$DBFF 更新颜色 ram。不同的 KERNAL 版本有不同的默认值。至少有一个版本将字符颜色设置为与背景颜色相同的颜色,因此除非更新颜色 RAM,否则字符将不可见。另请记住,直接写入屏幕内存使用不同的代码。

    添加 16 位

    在使用adc与进位相加)之前,您应该清除进位标志(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 函数来定位下一个字符将被打印的位置,以及一个 CHROUT 来打印一个 PETSCII 代码。 CHROUT 函数支持控制字符,因此您可以通过 CR 来换行或更改颜色。

    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 函数采用 X 中的行和 Y 中的列,并且值是从零开始的:0,0 是左上角

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      相关资源
      最近更新 更多