Merge pull request #1709 from karrika/atari7800clock
[Atari7800] clock()
This commit is contained in:
commit
84dba7f6ae
6 changed files with 208 additions and 4 deletions
|
@ -10,7 +10,7 @@ SYMBOLS {
|
||||||
__ENCRYPT_BOTTOM__: value = $ff7a, type = export;
|
__ENCRYPT_BOTTOM__: value = $ff7a, type = export;
|
||||||
__ENCRYPT_SIZE__: value = $80, type = export;
|
__ENCRYPT_SIZE__: value = $80, type = export;
|
||||||
__MEMORY_TOP__: value = __ENCRYPT_BOTTOM__, type = export;
|
__MEMORY_TOP__: value = __ENCRYPT_BOTTOM__, type = export;
|
||||||
__INIT_SIZE__: value = 69, type = export;
|
__INIT_SIZE__: value = 121, type = export;
|
||||||
__MEMORY_INIT__: value = __MEMORY_TOP__ - __INIT_SIZE__, type = export;
|
__MEMORY_INIT__: value = __MEMORY_TOP__ - __INIT_SIZE__, type = export;
|
||||||
__MEMORY_BOTTOM__: value = $10000 - __CARTSIZE__, type = weak;
|
__MEMORY_BOTTOM__: value = $10000 - __CARTSIZE__, type = weak;
|
||||||
__FREE_ROM_SIZE__: value = __MEMORY_INIT__ - __MEMORY_BOTTOM__, type = export;
|
__FREE_ROM_SIZE__: value = __MEMORY_INIT__ - __MEMORY_BOTTOM__, type = export;
|
||||||
|
|
69
libsrc/atari7800/clock.s
Normal file
69
libsrc/atari7800/clock.s
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
;
|
||||||
|
; 2022-03-15, Karri Kaksonen
|
||||||
|
;
|
||||||
|
; clock_t clock (void);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _clock, clock_count
|
||||||
|
.interruptor update_clock, 2 ; (low priority)
|
||||||
|
.constructor init_clock
|
||||||
|
|
||||||
|
.import sreg: zp
|
||||||
|
.import _zonecounter
|
||||||
|
.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
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------------
|
||||||
|
; 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
|
||||||
|
|
34
libsrc/atari7800/clocks_per_sec.s
Normal file
34
libsrc/atari7800/clocks_per_sec.s
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
;
|
||||||
|
; 2022-03-15, Karri Kaksonen
|
||||||
|
;
|
||||||
|
; clock_t _clocks_per_sec (void);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export __clocks_per_sec
|
||||||
|
|
||||||
|
.import sreg: zp
|
||||||
|
.import _paldetected
|
||||||
|
.include "atari7800.inc"
|
||||||
|
|
||||||
|
.macpack generic
|
||||||
|
|
||||||
|
.code
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------------
|
||||||
|
; 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
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
.import __RAM3_START__, __RAM3_SIZE__
|
.import __RAM3_START__, __RAM3_SIZE__
|
||||||
.import initlib, donelib
|
.import initlib, donelib
|
||||||
.import zerobss, copydata
|
.import zerobss, copydata
|
||||||
|
.import IRQStub
|
||||||
.import push0, _main
|
.import push0, _main
|
||||||
|
.include "atari7800.inc"
|
||||||
.include "zeropage.inc"
|
.include "zeropage.inc"
|
||||||
|
|
||||||
INPTCTRL = $01
|
INPTCTRL = $01
|
||||||
OFFSET = $38
|
|
||||||
CTRL = $3c
|
|
||||||
|
|
||||||
.segment "STARTUP"
|
.segment "STARTUP"
|
||||||
start:
|
start:
|
||||||
|
@ -50,7 +50,7 @@ _exit:
|
||||||
|
|
||||||
NMIHandler:
|
NMIHandler:
|
||||||
inc _zonecounter
|
inc _zonecounter
|
||||||
rti
|
jmp IRQStub
|
||||||
|
|
||||||
IRQHandler:
|
IRQHandler:
|
||||||
rti
|
rti
|
||||||
|
|
65
libsrc/atari7800/get_tv.s
Normal file
65
libsrc/atari7800/get_tv.s
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
;
|
||||||
|
; Karri Kaksonen, 2022-03-25
|
||||||
|
;
|
||||||
|
; unsigned char get_tv (void)
|
||||||
|
;
|
||||||
|
.include "atari7800.inc"
|
||||||
|
.include "get_tv.inc"
|
||||||
|
.export _get_tv
|
||||||
|
.export _paldetected
|
||||||
|
|
||||||
|
.segment "DATA"
|
||||||
|
|
||||||
|
_paldetected:
|
||||||
|
.byte $FF
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------
|
||||||
|
; unsigned char get_tv (void)
|
||||||
|
; ---------------------------------------------------------------
|
||||||
|
|
||||||
|
.segment "CODE"
|
||||||
|
|
||||||
|
.proc _get_tv: near
|
||||||
|
|
||||||
|
.segment "CODE"
|
||||||
|
|
||||||
|
ldx #$00
|
||||||
|
lda #$FF
|
||||||
|
cmp _paldetected
|
||||||
|
bne L8
|
||||||
|
L1: lda MSTAT
|
||||||
|
and #$80
|
||||||
|
bne L1
|
||||||
|
L2: lda MSTAT
|
||||||
|
and #$80
|
||||||
|
beq L2
|
||||||
|
L3: lda MSTAT
|
||||||
|
and #$80
|
||||||
|
bne L3
|
||||||
|
lda #$00
|
||||||
|
sta M0001
|
||||||
|
jmp L5
|
||||||
|
L4: sta MWSYNC
|
||||||
|
sta MWSYNC
|
||||||
|
dec M0001
|
||||||
|
L5: lda MSTAT
|
||||||
|
and #$80
|
||||||
|
beq L4
|
||||||
|
lda M0001
|
||||||
|
cmp #$78
|
||||||
|
bcc L6
|
||||||
|
lda #TV::NTSC
|
||||||
|
jmp L7
|
||||||
|
L6: lda #TV::PAL
|
||||||
|
L7: sta _paldetected
|
||||||
|
ldx #$00
|
||||||
|
L8: lda _paldetected
|
||||||
|
rts
|
||||||
|
|
||||||
|
.segment "BSS"
|
||||||
|
|
||||||
|
M0001:
|
||||||
|
.res 1,$00
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
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…
Add table
Reference in a new issue