1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +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 committed by mrdudz
parent 9fbeb68b22
commit fd305c1e31
2 changed files with 53 additions and 43 deletions

View File

@ -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

View File

@ -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