From 8d0b0e6ffcad7d6d63ccfc212e230d4cab484fa1 Mon Sep 17 00:00:00 2001 From: Karri Kaksonen Date: Fri, 25 Mar 2022 14:44:54 +0200 Subject: [PATCH] Separate machine detection from crt0 and put it in get_tv --- libsrc/atari7800/crt0.s | 27 --------------- libsrc/atari7800/get_tv.s | 69 ++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/libsrc/atari7800/crt0.s b/libsrc/atari7800/crt0.s index bd8a57525..d7cf307ee 100644 --- a/libsrc/atari7800/crt0.s +++ b/libsrc/atari7800/crt0.s @@ -1,5 +1,4 @@ .export _zonecounter - .export _paldetected .export __STARTUP__ : absolute = 1 .export _exit .import __ROM_START__ @@ -39,29 +38,6 @@ start: jsr zerobss jsr initlib - ; Examine machine type as we need the info early -vboff: lda MSTAT - bmi vboff -vbon: lda MSTAT - bpl vbon -vboff2: lda MSTAT - bmi vboff2 - lda #$00 - sta _paldetected - jmp mtsta -count: sta WSYNC - sta WSYNC - dec _paldetected -mtsta: lda MSTAT - bpl count - lda _paldetected - cmp #$78 - bcc mtntsc - lda #$01 - jmp mtpal -mtntsc: lda #$00 -mtpal: sta _paldetected - ; Call main program (pass empty command line) jsr push0 ; argc jsr push0 ; argv @@ -82,9 +58,6 @@ IRQHandler: .segment "DATA" _zonecounter: .byte 0 -_paldetected: - .byte 0 ; 0 = NTSC, 1 = PAL - .segment "ENCRYPTION" .res 126, $ff ; Reserved for encryption diff --git a/libsrc/atari7800/get_tv.s b/libsrc/atari7800/get_tv.s index 307a5c58d..5438b2b95 100644 --- a/libsrc/atari7800/get_tv.s +++ b/libsrc/atari7800/get_tv.s @@ -1,26 +1,63 @@ ; -; Stefan Haubenthal, 2007-01-21 +; Karri Kaksonen, 2022-03-25 ; -; unsigned char get_tv (void); -; /* Return the video mode the machine is using */ +; unsigned char get_tv (void) ; + .include "atari7800.inc" + .export _get_tv - .include "atari7800.inc" - .include "get_tv.inc" - .importzp tmp1, tmp2 - .import _paldetected +.segment "DATA" -;-------------------------------------------------------------------------- -; _get_tv +_paldetected: + .byte $FF -.proc _get_tv +; --------------------------------------------------------------- +; unsigned char get_tv (void) +; --------------------------------------------------------------- - lda _paldetected - beq ntsc - lda #TV::PAL - rts -ntsc: - lda #TV::NTSC +.segment "CODE" + +.proc _get_tv: near + +.segment "CODE" + + ldx #$00 + lda #$FF + cmp _paldetected + bne L8 +L1: lda $0028 + and #$80 + bne L1 +L2: lda $0028 + and #$80 + beq L2 +L3: lda $0028 + and #$80 + bne L3 + lda #$00 + sta M0001 + jmp L5 +L4: sta $0024 + sta $0024 + dec M0001 +L5: lda $0028 + and #$80 + beq L4 + lda M0001 + cmp #$78 + bcc L6 + lda #$00 + jmp L7 +L6: lda #$01 +L7: sta _paldetected + ldx #$00 +L8: lda _paldetected rts +.segment "BSS" + +M0001: + .res 1,$00 + .endproc +