base:using_a_timer_as_an_inverted_raster_x-pos_register_method
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | base:using_a_timer_as_an_inverted_raster_x-pos_register_method [2020-01-21 20:18] (current) – New method. pararaum | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using a Timer as an Inverted Raster X-Pos Register ====== | ||
+ | Hi, I'm Hermit Soft. On CSDB I've shared my strongly optimized (shortened) CIA-timer using stable raster method. | ||
+ | Now it's here to fill the gap in Codebase64. I hope it will be useful in " | ||
+ | |||
+ | A short pre-description: | ||
+ | A raster row is 63 cycles long, and CPU can use all these cycles to do operations if no SPRITE or BADLINE fetches the actual raster-row. | ||
+ | Also important to prevent memory page-boundaries because some commands take 1 more cycle when crossing them. Use program-start address and scan-part addresses of 256 multiplies to be clear. | ||
+ | |||
+ | We do a second rasterrow-test (cmp $d012) after exactly 56 cycles. This 56 cycles builds up from the carefully programmed part between the first " | ||
+ | In this case we jump back with second " | ||
+ | |||
+ | The timer (re)starts with sta$dc0e,y which is the most strictly timed, to show 7...1 on $dc04 when using the d012 scan (B-part). It counts 9 steps like 8, | ||
+ | |||
+ | ===== Setting the CIA1-timerA to beam in the program beginning ===== | ||
+ | |||
+ | Accumulator can be any value, no need to set. | ||
+ | |||
+ | < | ||
+ | | ||
+ | sync: | ||
+ | cmp $d012 ;scan for begin rasterline (A=$11 after first return) | ||
+ | bne *-3 ;wait if not reached rasterline #$11 yet | ||
+ | ldy #8 ;the walue for cia timer fetch & for y-delay loop 2 cycles | ||
+ | sty $dc04 ;CIA Timer will count from 8,8 down to 7, | ||
+ | | ||
+ | bne *-1 ;loop needed to complete the poll-delay with 39 cycles | ||
+ | sty $dc05 ;no need Hi-byte for timer at all (or it will mess up) 4 cycles | ||
+ | sta $dc0e, | ||
+ | lda #$11 ;value for d012 scan and for timerstart in dc0e 2 cycles | ||
+ | cmp $d012 ; | ||
+ | sty $d015 ; | ||
+ | bne sync ;if line changed after 63 cycles, resyncronize it! | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ===== Example 1: Stabilizing 7 cycle jitter when using cmp $d012 ===== | ||
+ | |||
+ | < | ||
+ | scan: | ||
+ | ldx #$31 ;a good value that's not badline, in border and 1=white | ||
+ | cpx $d012 ;scan rasterline | ||
+ | bne *-3 ;wait until rasterline will be $31 | ||
+ | lda $dc04 ; | ||
+ | eor #7 ;A=7-A so jitter will be 0...6 in A | ||
+ | sta *+4 ; | ||
+ | bpl *+2 ;the jump to timer (A) dependent byte | ||
+ | cmp #$c9 ;if A=0, cmp#$c9; if A=1, cmp #$c9 again 2 cycles later | ||
+ | cmp #$c9 ;if A=2, cmp#$c9, if A=3, CMP #$EA 2 cycles later | ||
+ | bit $ea24 ;if A=4, | ||
+ | ........... | ||
+ | |||
+ | stx $d020 ;x was 1 so border is white at the stable cycle | ||
+ | sty $d020 ;y ended in 0 in sync routine, so border black after 4 cycles | ||
+ | ........... | ||
+ | If the scan happens again in the same line, that may crash the program, because DC04 won't be usable for jumptable. | ||
+ | (For this stx $d020, sty$d020 this is specially not problem because of the lucky timing. They' | ||
+ | jmp scan ;go to the raster again (or can go new raster) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Example 2: stabilizing a raster IRQ ===== | ||
+ | |||
+ | The first part (CIA setter) is also good for raster IRQ. The important thing is to do the " | ||
+ | |||
+ | < | ||
+ | irq: | ||
+ | pha | ||
+ | lda $dc04 | ||
+ | eor #7 | ||
+ | sta *+4 | ||
+ | bpl *+2 | ||
+ | lda #$a9 | ||
+ | lda #$a9 | ||
+ | lda $eaa5 | ||
+ | txa | ||
+ | pha | ||
+ | tya | ||
+ | pha | ||
+ | |||
+ | ; the rest processes in the IRQ routine | ||
+ | |||
+ | asl $d019 | ||
+ | pla | ||
+ | tay | ||
+ | pla | ||
+ | tax | ||
+ | pla | ||
+ | | ||
+ | </ | ||
+ | |||
+ | That's for now, test it, use it, or whatever you want... | ||
+ | Or you can ask questions on csdb forum for this topic: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ===== Stabilizing using a loop (work in progress) ===== | ||
+ | |||
+ | This idea by Krill is currently a work in progress, see https:// | ||
+ | |||
+ | < | ||
+ | initstabilise | ||
+ | ldx #10 ; 2 | ||
+ | - | ||
+ | bpl - ; 54 | ||
+ | nop ; 2 | ||
+ | eor $d012 - $ff,x; 5 = 63 | ||
+ | bne initstabilise; | ||
+ | |||
+ | [...]; timer setup | ||
+ | </ |
base/using_a_timer_as_an_inverted_raster_x-pos_register_method.txt · Last modified: 2020-01-21 20:18 by pararaum