Pending change to $ D012 (C64 assembler)

I encountered several problems while playing with asm on a C64 emulated machine.

What I want to do is check if the "N" key on the keyboard is pressed, then the program should wait for the change to the address $ D012 to appear. Now I don’t understand how I can “wait” for a change to appear? Can anyone tell me what it is?

Checking that the N button on the keyboard is pressed is simple - just use the FFE4 (input) and FFD2 (output) routines.

I do not ask you to do anything for me, but if I can get some quick information about how D012 works and how I can “wait” for a change, I would be very grateful.

Thanks in advance!

+7
assembly c64 6502
source share
2 answers

$d012 contains the current raster line.

If you only need to wait until the case changes, then wait until the next raster line, you can make a simple wait:

 lda $d012 ;load the current raster line into the accumulator cmp $d012 ;check if it has changed beq *-3 ;if not, jump back and check again 

change

If you want to wait for several raster lines, for example 3:

 lda $d012 clc ;make sure carry is clear adc #$03 ;add lines to wait cmp $d012 bne *-3 ;check *until* we're at the target raster line 
+4
source share

You can respond to changes in $d012 using the IRQ raster handler. I will lay out a couple of features from my game code, because it can be hairy to make it work if you use the wrong combination of spells. It should also give you enough material for Google.

In particular, you may need to set your int handler to $0314 , as well as mention the code, in which case your IRQ handler will be bound using its own default handlers, and you need to skip the pha ... pha bit at the beginning of your handler. This can be useful if you need to use some of its input / output code.

 ;;; ----------------------------------------------------------------------------- ;;; install raster interrupt handler ;;; ----------------------------------------------------------------------------- sei ; turn off interrupts ldx #1 ; enable raster interrupts stx $d01a lda #<int_handler ; set raster interrupt vector ldx #>int_handler sta $fffe stx $ffff ldy #$f0 ; set scanline on which to trigger interrupt sty $d012 lda $d011 ; scanline hi bit and #%01111111 sta $d011 lda #$35 ; disable kernal and BASIC memory ($e000 - $ffff) sta $01 asl $d019 ; acknowledge VIC interrupts cli loop_pro_semper jmp loop_pro_semper 

Then you process these interrupts as follows:

 ;;; ----------------------------------------------------------------------------- ;;; raster IRQ handler ;;; ----------------------------------------------------------------------------- int_handler pha ; needed if our raster int handler is set in fffe instead of 0314 txa pha tya pha ; ... do your stuff here ... 
+2
source share

All Articles