English 中文(简体)
我如何在6502届大会上发言?
原标题:How do I make a timer in Assembly 6502?

我为一场游戏而工作,它要求第二次减员60次,但我不知道如何从60秒中缩减,因为记忆的更新速度非常快。

这里是我尝试的:

.proc timer
PHP
PHA
TXA
PHA
TYA
PHA

LDA #60
STA $0000

Loop:
    DEC $0000
    LDA $0000
    BEQ TimerDone
DelayLoop:
    LDX #$FF
InnerLoop:
    DEX
    BNE InnerLoop
    JMP Loop
TimerDone:
    
PLA
TAY
PLA
TAX
PLA
PLP
RTS
.endproc   

事实是,在一开始游戏时,它立即在记忆器中达到0,因此它只是迅速更新。 是否有办法造成某种拖延,这种拖延是第二次或甚至微秒?

问题回答

You ve got is right. You have to use a loop. What you can do to make it take longer is to add NOP operations.

652年的时间安排非常具体。 假设你没有超速的现代版本,你可以非常准确。 预计这些指示将确切使用其指定时间。 例如,<代码>DEX + BNE 休息时间为6个周期,最后步骤为5个(如果不进行,分行时间为1个较宽的周期),而分行时间为1个多周期,目的地为单独的一页,常设仲裁法院高分位数则增减。

So now you need to find a document with the CPU instructions and the number of cycles each take.

如果你有24小时,你可以读一下你的锁,并利用这一价值知道你何时做。 否则,6502年就没有违约。 它必须是某种类型的I/O。

                             Cycles
    LDA #60
    STA $0000
Loop:
    DEC $0000                6
    BEQ TimerDone            2 (3 when $0000=0)
DelayLoop:
    LDX #$00                 2
InnerLoop:
    LDY #$00                 2
InnerInnerLoop:
    DEY                      2
    BNE InnerInnerLoop       3 (2 when Y=0)
    DEX                      2
    BNE InnerLoop            3 (2 when X=0)
    JMP Loop                 3
TimerDone:

So, the InnerInnerLoop takes (2 + 3) × 255 + 2 + 2 (last time branch is not taken so 1 less cycle) = 1,284 cycles

As a result the InnerLoop does (2 + 1,284 + 2 + 3) × 255 + (2 + 1,284 + 2 + 2) = 330,495 cycles.

最后,<代码>Loop (6 + 2 + 330,495 + 3) × 601 + 1 = 19,830,361的周期。

If you have a 6502 that runs at 1MHz, then that loop would take about 19.8 seconds. If it runs at 5Mhz, then it will take 19.8 ÷ 5 ≈ 3.97 seconds.

页: 1 如Nick Westgate在一份评论中所说,如果书面文件将产生59个频率。 相反,你可以(1) 移动<条码>。 <代码>JMP以JMP替换为BNE;或(2)使用LDA #61,以获得60个版本。


Note: a while back, I created an Apple II simulator that runs on x86/amd64 computers. My main problem was the clock. I did not work on that part. So it goes dead fast compared to the good old Apple II. So hopefully you run your code on real hardware. Otherwise, your pause will work only if the emulator properly emulates the duration of a cycle.





相关问题
List of suspected Malicious patterns

I am doing an anti-virus project by disassembling its code and analyzing it. So I want a list of the Suspected Malicious pattern codes, so I can observe which is suspected and which is not? So I want ...

Prefetch for Intel Core 2 Duo

Has anyone had experience using prefetch instructions for the Core 2 Duo processor? I ve been using the (standard?) prefetch set (prefetchnta, prefetcht1, etc) with success for a series of P4 ...

How are mutex and lock structures implemented?

I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions ...

Installing GNU Assembler in OSX

No matter how hard I google, I can t seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac. I know I can use gcc -c (Apple Clang on a Mac) to assemble .s ...

8086 assembler,INT 16,2

I got stuck at this thing,I want to see if right shift button has been pressed,so I have this assambler code: mov ah,2 int 16h ;calling INT 16,2 - Read Keyboard Flags interrupt mov ah,...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签