读入内存和公司(6502)

Pet*_*ter 0 6502

对不起,如果问题似乎是"太基本".我是一名68K ASM编码器,但有一位朋友让我一瞥6502代码.我们有一个指向数据字符串的指针:

 my_ptr ds 2
Run Code Online (Sandbox Code Playgroud)

使用以下代码设置此指针:

ldx sound_channel_busy
bne .abc_set_score1   ; at bottom of code
sta my_ptr   ; fill the pointer
Run Code Online (Sandbox Code Playgroud)

读取数据完成

lda (my_ptr),y    ; my_ptr + offset
Run Code Online (Sandbox Code Playgroud)

但正如我在6502 doc中看到的那样,y是一个字节.因此,使用超过255个字节的数据字符串是不可能的(我们想要读取10.000字节或更多的字符串.我建议我的朋友这样做:

1)将一个指针设置为"基础",将一个指针设置为我们在阅读时将要包含的临时指针

 my_ptr ds 2
 my_ptr_tmp ds 2
Run Code Online (Sandbox Code Playgroud)

2)用以下内容初始化:

ldx sound_channel_busy
bne .abc_set_score1
sta my_ptr
sta my_ptr_tmp  ; Duplicate
Run Code Online (Sandbox Code Playgroud)

3)然后阅读使用:

  lda (my_ptr_tmp)   ; Read to acumulator
  inc my_ptr_tmp     ; One more on adress pointer
Run Code Online (Sandbox Code Playgroud)

但它不起作用,因为我的朋友是C开发者,我们没有调试器......不容易.在68K这似乎是合乎逻辑的,但在6502?

非常感谢你的帮助

Jer*_*myP 6

6502非常有限.

y表单用于访问由零页面指针指向的数组元素,x表单用于访问零页面内存中的向量表.

要设置指针:

    lda #<pointer ; The low byte of the 16 bit address pointer is loaded into A
    sta my_ptr
    lda #>pointer ; the high byte of the pointer
    sta my_ptr+1
    ldy #0        ; zero the y register
Run Code Online (Sandbox Code Playgroud)

访问指针

loopStart:
    lda (my_ptr),y
Run Code Online (Sandbox Code Playgroud)

假设C样式字符串具有空终止符

    beq loopExit  ; previous LDA sets the S and Z flags.
Run Code Online (Sandbox Code Playgroud)

增加指针

    iny           ; Increment y
    bne loopStart
    inc my_ptr+1
    jmp loopStart
Run Code Online (Sandbox Code Playgroud)

您也可以将Y保持为0并递增低字节和两个零页面位置,但是INC my_ptrINY采用五个周期而不是两个周期慢得多.

编辑

如果您有一个长度,而不是空终止字符串,则需要稍微修改它.一种方法是计算你已完成的字节数并与长度进行比较.使用上面的算法,Y是计数,如果长度<256,那么我们可以做的是存储计数的高字节

; first set up my_ptr, same as before.
; 
    lda #<pointer ; The low byte of the 16 bit address pointer is loaded into A
    sta my_ptr
    lda #>pointer ; the high byte of the pointer
    sta my_ptr+1
;
;   Set up the counter
;
    ldx #0        ; set up x for the count
    ldy #0        ; Set up y for the count/loop
;
;   A common trick with compiling while loops is to put the test at the end of the loop and jump to it immediately. 
;  This means you don't have to reverse the logic of the loop condition.
;
    jmp loopTest  ; Omit this if you definitely need to go round the loop at least once
loopStart:
    lda (my_ptr),y    ; Get the byte
;
;   Do what you need to do here
;
;   Increment the counter
;
    iny           ; Increment y
    bne loopTest
    inx
    inc my_ptr+1
loopTest:
    cpy length    ; Compare the low byte of length to the count
    bne loopStart
    cpx length+1  ; Compare the high byte of length to the count
    bne loopStart
Run Code Online (Sandbox Code Playgroud)