diff --git a/cfg/atari7800.cfg b/cfg/atari7800.cfg index 562dd3857..4d20ab0d9 100644 --- a/cfg/atari7800.cfg +++ b/cfg/atari7800.cfg @@ -10,7 +10,7 @@ SYMBOLS { __ENCRYPT_BOTTOM__: value = $ff7a, type = export; __ENCRYPT_SIZE__: value = $80, 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_BOTTOM__: value = $10000 - __CARTSIZE__, type = weak; __FREE_ROM_SIZE__: value = __MEMORY_INIT__ - __MEMORY_BOTTOM__, type = export; diff --git a/libsrc/atari7800/clock.s b/libsrc/atari7800/clock.s new file mode 100644 index 000000000..3b259cfcf --- /dev/null +++ b/libsrc/atari7800/clock.s @@ -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 + diff --git a/libsrc/atari7800/clocks_per_sec.s b/libsrc/atari7800/clocks_per_sec.s new file mode 100644 index 000000000..dc09c4396 --- /dev/null +++ b/libsrc/atari7800/clocks_per_sec.s @@ -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 + diff --git a/libsrc/atari7800/crt0.s b/libsrc/atari7800/crt0.s index 3d53abfa8..d7cf307ee 100644 --- a/libsrc/atari7800/crt0.s +++ b/libsrc/atari7800/crt0.s @@ -5,12 +5,12 @@ .import __RAM3_START__, __RAM3_SIZE__ .import initlib, donelib .import zerobss, copydata + .import IRQStub .import push0, _main + .include "atari7800.inc" .include "zeropage.inc" INPTCTRL = $01 -OFFSET = $38 -CTRL = $3c .segment "STARTUP" start: @@ -50,7 +50,7 @@ _exit: NMIHandler: inc _zonecounter - rti + jmp IRQStub IRQHandler: rti diff --git a/libsrc/atari7800/get_tv.s b/libsrc/atari7800/get_tv.s new file mode 100644 index 000000000..3eb94d54d --- /dev/null +++ b/libsrc/atari7800/get_tv.s @@ -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 + diff --git a/libsrc/atari7800/irq.s b/libsrc/atari7800/irq.s new file mode 100644 index 000000000..ed315a1b7 --- /dev/null +++ b/libsrc/atari7800/irq.s @@ -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 +