require'vcs' TIM_OVERSCAN = 50 -- TIM64T, 3200 cycles = ~ 42 scanlines TIM_VBLANK = 61 -- TIM64T, 3904 cycles = ~ 51 scanlines TIM_KERNEL = 17 -- T1024T, 17408 cycles = ~229 scanlines location(0xf000, 0xffff) section{'vectors', org=0xfffc} dc.w start,start local kernel = function() -- add a dummy instruction to collect cycle count and binary size local kernel_cycles,kernel_size table.insert(section_current.instructions, { bin=function() kernel_cycles=cycles kernel_size=size end }) samepage ldx#0xd0 @_loop sta WSYNC stx COLUBK dex bne _loop end -- and get the delta (cycles are counted without taking any branch) table.insert(section_current.instructions, { bin=function() print('kernel cycles: ', cycles-kernel_cycles, 'kernel size: ', size-kernel_size) end }) end local wait = function() local l=label() lda INTIM bne l end @@start -- clear zeropage cld ldx#0 txa @_clear dex txs pha bne _clear @main -- overscan sta WSYNC lda#2 sta VBLANK lda#TIM_OVERSCAN sta TIM64T wait() -- vblank lda#0b1110 @_vsync sta WSYNC sta VSYNC lsr bne _vsync lda#2 sta VBLANK lda#TIM_VBLANK sta TIM64T wait() sta WSYNC sta VBLANK -- kernel lda#TIM_KERNEL sta T1024T kernel() wait() jmp main ; writebin(filename..'.bin') writesym(filename..'.sym') print(stats)