aboutsummaryrefslogtreecommitdiff
path: root/crt0_5200.s
blob: 5210ec1a898dc32b8adf37f23a82e314b413d88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
;
; Startup code for cc65 (Atari5200 version)
;
; Christian Groessler (chris@groessler.org), 2014

; modified for taipan, to work as a diagnostic cart.
; contains code adapted from the 5200 OS ROM.

        .export         _exit, start
        .export         __STARTUP__ : absolute = 1      ; Mark as startup
        .import         __RAM_START__, __RAM_SIZE__
        .import         __RESERVED_MEMORY__

        .import         initlib, donelib, callmain
        .import         zerobss, copydata

        .include        "zeropage.inc"
        .include        "atari5200.inc"

;;; start of (slightly modified) OS ROM code. the OS calls us with
;;; interrupts disabled, decimal mode cleared, with the stack pointer
;;; set to $FF. Since this is a diagnostic cart, we have to init the
;;; hardware and set up the interrupt vector table at $0200 (the OS
;;; doesn't do it for us, like it would for a non-diag cart).

;;; This code is based on Dan Boris's commented disassembly of the 4-port
;;; 5200 BIOS, retrieved from <http://atarihq.com/danb/files/5200BIOS.txt>.

;;; I've copied just the initialization code, minus the logo/copyright
;;; screen, and modified it to work with either OS revision.

;;; Everything I've read tells me that the 4-port OS will work on a 2-port
;;; machine (the hardware changes don't break compatibility), so the code
;;; here comes from the 4-port OS.

; I've gone to a lot of trouble to get the vectors and display list
; set up correctly for either ROM revision... but the display list, at
; least, was really a waste of time: conio is going to set up a GR.1
; display list... at least until I modify it to use GR.0 instead.

start:
 ldx #0
 txa
@clrloop:
 sta  POKEY,x   ;Clear POKEY registers
 sta  GTIA,x   ;Clear GTIA registers
 sta  ANTIC,x   ;Clear ANTIC registers
 sta  $00,x   ;Clear zero page
 inx
 bne  @clrloop
 lda  #$F8
 sta  CHBASE   ;Set Character base to $F800

; determine which OS revision we're running under. This affects
; the locations of the vector table and display list in the ROM,
; and is probably the reason a few published 5200 games are
; incompatible with the Rev A ROM.
; rev A has $07 at $fee5, original OS has $61. If there are other
; OS revisions out there in the wild, this code will likely fail
; on them.

 lda #$fe
 sta $fb
; sta $fd
; sta $ff
 lda $fee5
 cmp #$07
 beq @rev_a

 ; set up $fa to point to vector table,
 ; $fc to point to display list start,
 ; $fe to point to DL end.

 ; old OS:
 lda #$95
 sta $fa
; lda #$c8
; sta $fc
; lda #$cf
; sta $fe
 bne @copy_vectors

@rev_a:
 lda #$ab
 sta $fa
; lda #$de
; sta $fc
; lda #$e5
; sta $fe

@copy_vectors:
 ldy  #$0B
@cploop:
 lda  ($fa),y
 sta  VIMIRQ,y   ;Copy vectors to vector table
 dey
 bpl  @cploop

 lda  #$3C   ;Set pointer to $3C00
 sta  $12
 lda  #$00
 sta  $11

 ldx  #$0C
 tay
@vecloop:
 sta  ($11),y
 dey
 bne  @vecloop
 dec  $12
 dex
 bpl  @vecloop

;;; taipan doesn't need the OS-provided display list.
;;; conio init will set up a GR.1 DL (at least, until
;;; I modify it to the GR.0 that taipan needs)
;Build display list
; lda  #$0D   ;Antic mode 13
; ldx  #$4D
;@dl13loop:
; sta  $2007,x   ;write to display list
; dex
; bpl  @dl13loop
;
; ldy  #$06   ;Copy start of display list
;@dlloop:
; lda  ($fc),y
; sta  $2000,y
; dey
; bpl  @dlloop
;
; ldy  #$04   ;Copy end of display list
;@dlendloop:
; lda  ($fe),y
; sta  $2055,y
; dey
; bpl  @dlendloop
;
; lda  #$00   ;Set Display List pointer to $2000
; sta  $05
; lda  #$20
; sta  $06

 lda  #$22   ;Set DMACTL, dlist on/normal background
 sta  SDMCTL

 lda  #$C0
 sta  NMIEN  ;Enable DLI and VBI
 lda  #$02
 sta  SKCTL  ;Enable Keyboard scanning

 .out .sprintf("%d bytes", * - start)
;;; end of OS ROM code, rest of file is standard 5200 crt0.s.

; Clear the BSS data.

        jsr     zerobss

; Initialize the data.
        jsr     copydata

; Set up the stack.

        lda     #<(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
        sta     sp
        lda     #>(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
        sta     sp+1            ; Set argument stack ptr

; Call the module constructors.

        jsr     initlib

; Push the command-line arguments; and, call main().

        jsr     callmain

; Call the module destructors. This is also the exit() entry.

_exit:  jsr     donelib         ; Run module destructors

; A 5200 program isn't supposed to exit.

halt:   jmp halt