; test TIM8T as a loop counter ; Written by Omegamatrix processor 6502 VSYNC = $00 VBLANK = $01 WSYNC = $02 NUSIZ0 = $04 NUSIZ1 = $05 COLUP0 = $06 COLUP1 = $07 COLUBK = $09 CTRLPF = $0A RESP0 = $10 RESP1 = $11 GRP0 = $1B GRP1 = $1C HMP0 = $20 HMP1 = $21 VDELP0 = $25 VDELP1 = $26 HMOVE = $2A INTIM = $0284 TIM8T = $0295 TIM64T = $0296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; USER CONSTANTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; TIME_OVERSCAN = 27 TIME_VBLANK = $31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; RAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SEG.U Variables ORG $80 digits ds 6 topGfxPtrs ds 12 botGfxPtrs ds 12 frameCounter ds 1 loopCount ds 1 tempGfx ds 1 loopCountBuffer ds 8 tempSP ds 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; MAIN PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SEG Code ORG $F000 START: cld ldx #0 txa .loopClear: dex txs pha bne .loopClear ;one time initializations... sta WSYNC ;--------------------------------------- sta CTRLPF ;3 @3 lda #$0F ;2 @5 white sta COLUP0 ;3 @8 sta COLUP1 ;3 @11 sta VDELP0 ;3 @14 delay sta VDELP1 ;3 @17 lda #$03 ;2 @19 sta NUSIZ0 ;3 @22 3 copies close sta NUSIZ1 ;3 @25 lda #$B0 ;2 @27 right 5 sta HMP0 ;3 @30 lda #$C0 ;2 @32 right 4 sta HMP1 ;3 @35 sta RESP0 ;3 @38 sta RESP1 ;3 @41 sta WSYNC ;3 @76 ;--------------------------------------- sta HMOVE lda #$C6 sta COLUBK lda #0 sta digits lda #1 sta digits+1 lda #2 sta digits+2 lda #3 sta digits+3 lda #4 sta digits+4 lda #5 sta digits+5 lda #>Zero sta topGfxPtrs+1 sta topGfxPtrs+3 sta topGfxPtrs+5 sta topGfxPtrs+7 sta topGfxPtrs+9 sta topGfxPtrs+11 lda #>LineOneGfx_A sta botGfxPtrs+1 sta botGfxPtrs+3 sta botGfxPtrs+5 sta botGfxPtrs+7 sta botGfxPtrs+9 sta botGfxPtrs+11 ; fill loop count buffer with 6,5,4,3,2,1,0,-1 ldx #7 ldy #-1 .loopFill: sty loopCountBuffer,x iny dex bpl .loopFill ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Vsync ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MainLoop: lda #$0E .loopVsync: sta WSYNC ;--------------------------------------- sta VSYNC lsr bne .loopVsync lda #TIME_VBLANK sta TIM64T ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; scroll digits left ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; lda frameCounter and #$07 bne .skipScroll ldy #5 .updateDigits: ldx digits,Y inx cpx #18 bcc .digitUpdate ldx #0 .digitUpdate: stx digits,Y dey bpl .updateDigits .skipScroll: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; load all low pointers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ldy digits+5 lda StandardNumTab,Y sta topGfxPtrs+10 lda FasterNumTab,Y sta botGfxPtrs+10 ldy digits+4 lda StandardNumTab,Y sta topGfxPtrs+8 lda FasterNumTab,Y sta botGfxPtrs+8 ldy digits+3 lda StandardNumTab,Y sta topGfxPtrs+6 lda FasterNumTab,Y sta botGfxPtrs+6 ldy digits+2 lda StandardNumTab,Y sta topGfxPtrs+4 lda FasterNumTab,Y sta botGfxPtrs+4 ldy digits+1 lda StandardNumTab,Y sta topGfxPtrs+2 lda FasterNumTab,Y sta botGfxPtrs+2 ldy digits lda StandardNumTab,Y sta topGfxPtrs lda FasterNumTab,Y sta botGfxPtrs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; finish Vblank ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .waitVblank: lda INTIM bne .waitVblank sta WSYNC ;--------------------------------------- sta VBLANK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; top lines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ldy #76 .loopTop: sta WSYNC ;--------------------------------------- dey bne .loopTop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; standard 48 bit display ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ldy #7 sty loopCount .loopStandard48bit: lda (topGfxPtrs+10),Y ;5 @69 sta tempGfx ;3 @72 sta WSYNC ;3 ;--------------------------------------- lda (topGfxPtrs),Y ;5 @5 sta GRP0 ;3 @8 lda (topGfxPtrs+2),Y ;5 @13 sta GRP1 ;3 @16 lda (topGfxPtrs+4),Y ;5 @21 sta GRP0 ;3 @24 lax (topGfxPtrs+8),Y ;5 @29 lda (topGfxPtrs+6),Y ;5 @34 ldy tempGfx ;3 @37 nop ;2 @39 8 free cycles in loop nop ;2 @41 sta GRP1 ;3 @44 stx GRP0 ;3 @47 sty GRP1 ;3 @50 sta GRP0 ;3 @53 dec loopCount ;5 @58 ldy loopCount ;3 @61 bpl .loopStandard48bit ;2³ @63/64 iny sty GRP0 sty GRP1 sty GRP0 sty GRP1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; medium 48 bit display ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sta WSYNC sta WSYNC sta WSYNC tsx stx tempSP ldx #loopCountBuffer-1 txs ldy #7 .loopMedium48bit: lda (topGfxPtrs+10),Y ;5 @67 sta tempGfx ;3 @70 sta WSYNC ;3 ;--------------------------------------- lda (topGfxPtrs),Y ;5 @5 sta GRP0 ;3 @8 lda (topGfxPtrs+2),Y ;5 @13 sta GRP1 ;3 @16 lda (topGfxPtrs+4),Y ;5 @21 sta GRP0 ;3 @24 lax (topGfxPtrs+8),Y ;5 @29 lda (topGfxPtrs+6),Y ;5 @34 ldy tempGfx ;3 @37 nop ;2 @39 10 free cycles in loop nop ;2 @41 sta GRP1 ;3 @44 stx GRP0 ;3 @47 sty GRP1 ;3 @50 sta GRP0 ;3 @53 pla ;4 @57 tay ;2 @59 bpl .loopMedium48bit ;2³ @61/62 iny sty GRP0 sty GRP1 sty GRP0 sty GRP1 ldx tempSP txs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; faster 48 bit display ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sta WSYNC sta WSYNC sta WSYNC ;--------------------------------------- dec $2E ;5 @5 dec $2E ;5 @10 dec $2E ;5 @15 dec $2E ;5 @20 dec $2E ;5 @25 dec $2E ;5 @30 dec $2E ;5 @35 dec $2E ;5 @40 dec $2E ;5 @45 nop ;2 @47 nop ;2 @49 nop ;2 @51 ldy #