mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 00:29:31 +00:00
Add irq handling, PAL/NTSC detection and clock()
This commit is contained in:
parent
d099df0533
commit
76fae9da82
89
libsrc/atari7800/clock.s
Normal file
89
libsrc/atari7800/clock.s
Normal file
@ -0,0 +1,89 @@
|
||||
;
|
||||
; 2022-03-15, Karri Kaksonen
|
||||
;
|
||||
; clock_t clock (void);
|
||||
; clock_t _clocks_per_sec (void);
|
||||
;
|
||||
|
||||
.export _clock, __clocks_per_sec, clock_count
|
||||
.interruptor update_clock, 2 ; (low priority)
|
||||
.constructor init_clock
|
||||
|
||||
.import sreg: zp
|
||||
.import _zonecounter
|
||||
.import _paldetected
|
||||
.include "atari7800.inc"
|
||||
|
||||
.macpack generic
|
||||
|
||||
.code
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Read the clock counter.
|
||||
;
|
||||
.proc _clock
|
||||
|
||||
lda #0
|
||||
sta sreg+1 ; Promote 24 bits up to 32 bits
|
||||
lda clock_count+2
|
||||
sta sreg
|
||||
ldx clock_count+1
|
||||
lda clock_count
|
||||
|
||||
rts
|
||||
.endproc
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Return the number of clock ticks in one second.
|
||||
;
|
||||
.proc __clocks_per_sec
|
||||
|
||||
lda #0
|
||||
tax
|
||||
sta sreg ; return 32 bits
|
||||
sta sreg+1
|
||||
lda _paldetected
|
||||
bne pal
|
||||
lda #60 ; NTSC - 60Hz
|
||||
rts
|
||||
pal:
|
||||
lda #50 ; PAL - 50Hz
|
||||
rts
|
||||
.endproc
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; This interrupt handler increments a 24-bit counter at every video
|
||||
; vertical-blanking time.
|
||||
; Update the clock only on interrupt while the drawing on screen is on
|
||||
; _zonecounter == 1 (from 1st visible scanline to last visible scanline)
|
||||
;
|
||||
update_clock:
|
||||
lda _zonecounter
|
||||
and #01
|
||||
beq @L1
|
||||
inc clock_count
|
||||
bne @L1
|
||||
inc clock_count+1
|
||||
bne @L1
|
||||
inc clock_count+2
|
||||
@L1: ;clc ; General interrupt was not reset
|
||||
rts
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Set time to zero at startup
|
||||
;
|
||||
.segment "ONCE"
|
||||
init_clock:
|
||||
lda #0
|
||||
sta clock_count+2
|
||||
sta clock_count+1
|
||||
sta clock_count
|
||||
rts
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Store time in 3 bytes
|
||||
;
|
||||
.bss
|
||||
clock_count:
|
||||
.res 3
|
||||
|
36
libsrc/atari7800/irq.s
Normal file
36
libsrc/atari7800/irq.s
Normal file
@ -0,0 +1,36 @@
|
||||
;
|
||||
; IRQ handling (Atari 7800 version)
|
||||
;
|
||||
|
||||
.export initirq, doneirq, IRQStub
|
||||
|
||||
.import __INTERRUPTOR_COUNT__, callirq
|
||||
|
||||
.include "atari7800.inc"
|
||||
|
||||
.code
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
initirq:
|
||||
doneirq:
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
IRQStub:
|
||||
cld ; Just to be sure
|
||||
pha
|
||||
lda #<(__INTERRUPTOR_COUNT__ * 2)
|
||||
beq @L1
|
||||
txa
|
||||
pha
|
||||
tya
|
||||
pha
|
||||
jsr callirq ; Call the functions
|
||||
pla
|
||||
tay
|
||||
pla
|
||||
tax
|
||||
@L1: pla
|
||||
rti
|
||||
|
Loading…
Reference in New Issue
Block a user