1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 02:29:52 +00:00

Separate machine detection from crt0 and put it in get_tv

This commit is contained in:
Karri Kaksonen 2022-03-25 14:44:54 +02:00
parent 4c3120b935
commit 8d0b0e6ffc
2 changed files with 53 additions and 43 deletions

View File

@ -1,5 +1,4 @@
.export _zonecounter .export _zonecounter
.export _paldetected
.export __STARTUP__ : absolute = 1 .export __STARTUP__ : absolute = 1
.export _exit .export _exit
.import __ROM_START__ .import __ROM_START__
@ -39,29 +38,6 @@ start:
jsr zerobss jsr zerobss
jsr initlib 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) ; Call main program (pass empty command line)
jsr push0 ; argc jsr push0 ; argc
jsr push0 ; argv jsr push0 ; argv
@ -82,9 +58,6 @@ IRQHandler:
.segment "DATA" .segment "DATA"
_zonecounter: _zonecounter:
.byte 0 .byte 0
_paldetected:
.byte 0 ; 0 = NTSC, 1 = PAL
.segment "ENCRYPTION" .segment "ENCRYPTION"
.res 126, $ff ; Reserved for encryption .res 126, $ff ; Reserved for encryption

View File

@ -1,26 +1,63 @@
; ;
; Stefan Haubenthal, 2007-01-21 ; Karri Kaksonen, 2022-03-25
; ;
; unsigned char get_tv (void); ; unsigned char get_tv (void)
; /* Return the video mode the machine is using */
; ;
.include "atari7800.inc" .include "atari7800.inc"
.include "get_tv.inc" .export _get_tv
.importzp tmp1, tmp2
.import _paldetected
;-------------------------------------------------------------------------- .segment "DATA"
; _get_tv
.proc _get_tv _paldetected:
.byte $FF
lda _paldetected ; ---------------------------------------------------------------
beq ntsc ; unsigned char get_tv (void)
lda #TV::PAL ; ---------------------------------------------------------------
rts
ntsc: .segment "CODE"
lda #TV::NTSC
.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 rts
.segment "BSS"
M0001:
.res 1,$00
.endproc .endproc