Skip to content

Instantly share code, notes, and snippets.

@JimmyDansbo
Last active April 15, 2024 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimmyDansbo/bbbf8d9da8916d995af689248a266d9a to your computer and use it in GitHub Desktop.
Save JimmyDansbo/bbbf8d9da8916d995af689248a266d9a to your computer and use it in GitHub Desktop.
Small program to show the difference in speed on the Commander X16 with different clock speeds. Result is the amount of increments that were possible within VERA 60Hz interrupt cycle. Build with cl65 -t cx16 -o X16SPEED.PRG x16speed.asm
.segment "STARTUP"
.segment "INIT"
.segment "ONCE"
.segment "CODE"
IRQVECTOR = $0314
VERA_IEN = $9F26
VERA_ISR = $9F27
CHROUT = $FFD2
count = $30 ; $30-$31 used for counter
irq_trigged = $32 ; Var to indicate when irq has happened
oldhandler = $33 ; Holding address of original irq handler
setup:
stz count ; Ensure our count variable is zero
stz count+1
stz irq_trigged ; Ensure trigger variable is zero
; Save original interrupt vector address
lda IRQVECTOR
sta oldhandler
lda IRQVECTOR+1
sta oldhandler+1
; Install new interrupt handler
sei
lda #<vera_tick
sta IRQVECTOR
lda #>vera_tick
sta IRQVECTOR+1
cli
; Wait for an interrupt to ensure that we start the timing at
; the beginning of an interrupt
firstwait:
wai
lda irq_trigged
beq firstwait
stz irq_trigged
; Now we do as many counts as we can until next interrupt
timing:
inc count+1
bne :+
inc count
: lda irq_trigged
beq timing
; Uninstall interrupt handler
sei ; Disable interrupts
lda oldhandler
sta IRQVECTOR
lda oldhandler+1
sta IRQVECTOR+1
cli ; Enable interrupts
; Below this point, the oldhandler variable is
; reused as zeropage pointer to strings
; First part of the message: COUNTED TO $
lda #<counted
sta oldhandler
lda #>counted
sta oldhandler+1
jsr printstr
; Print the actual count as hexadecimal number
lda count
jsr printhex
lda count+1
jsr printhex
; Second part of the message: - MOST LIKELY RUNNING AT
lda #<likely
sta oldhandler
lda #>likely
sta oldhandler+1
jsr printstr
; High byte of the counter have the following values on all systems
; that I have tested (Emulator, CX16 PR board, OtterX & Community Board)
; @ 2 MHz - $08
; @ 4 MHz - $11
; @ 8 MHz - $24
lda count
cmp #$20
bcs @do8 ; If highbyte of counter is >= $20 then 8 Mhz or more
cmp #$10
bcs @do4 ; If highbyte of counter is >= $10 then 4 MHz
@do2: lda #$32 ; Otherwise, 2 MHz
bra @endstr
@do4: lda #$34
bra @endstr
@do8: lda #$38
@endstr:
jsr CHROUT ; Write the calculated MHz number
; Last part of the message: MHZ
lda #<mhz
sta oldhandler
lda #>mhz
sta oldhandler+1
jmp printstr
; Ensure irq_trigged is non-zero when irq happens
vera_tick:
lda VERA_ISR
and #1 ; Is this VSYNC?
beq :+ ; if not, end
sta irq_trigged
: jmp (oldhandler)
; Print the content of .A as hexnumber
printhex:
pha
lsr
lsr
lsr
lsr
jsr prhex
pla
prhex:
and #$0F
ora #$30
cmp #$3A
bcc doprint
adc #6
doprint:
jmp CHROUT
; Print a zero terminated string pointed to by oldhandler
printstr:
ldy #0
: lda (oldhandler),y
beq @end
jsr CHROUT
iny
bra :-
@end: rts
counted:.asciiz "counted to: $"
likely: .asciiz " - most likely running at "
mhz: .asciiz " mhz"
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment