Subversion Repositories Krakow BASIC

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 nishi 1
;
2
; Startup code for cc65 (C64 version)
3
;
4
 
5
	.export		_exit
6
        .export         __STARTUP__ : absolute = 1      ; Mark as startup
7
	.import		initlib, donelib, callirq
8
       	.import	       	zerobss
9
	.import	     	callmain, pushax
10
        .import         RESTOR, BSOUT, CLRCH
11
	.import	       	__INTERRUPTOR_COUNT__
12
	.import		__RAM_START__, __RAM_SIZE__	; Linker generated
13
 
14
	.import		_cgetc, _puts, _memcpy
15
 
16
	.import		__DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
17
 
18
        .include        "zeropage.inc"
19
	.include     	"c64.inc"
20
 
21
 
22
.segment	"HEADERDATA"
23
 
24
HeaderB:
25
@magic:
26
	;.byt	"C64  CARTRIDGE  "
27
	.byt	$43,$36,$34,$20, $43,$41,$52,$54
28
	.byt	$52,$49,$44,$47, $45,$20,$20,$20
29
@headelen:
30
	.byt	$00,$00,$00,$40
31
@ver:
32
	.byt	$01,$00
33
@carttye:
34
	.byt	$00,$00
35
@EXROM:
36
	.byt	$01
37
@GAME:
38
	.byt	$01
39
@reserved1:
40
	.byt	$00,$00,$00,$00,$00,$00
41
@Name:	;You put the name of the cartridge here.
42
	.byt	"TEST CODE"
43
 
44
 
45
.segment	"CHIP0"
46
ChipB:
47
@magic:
48
	.byt	$43,$48,$49,$50 ;"CHIP"
49
@size:
50
	.byt	$00,$00,$20,$10	;Use for 8k carridge
51
	;.byt	$00,$00,$40,$10	;Use for 16k carridge
52
@chiptype:	;ROM
53
	.byt	$00,$00
54
@bank:
55
	.word	$0000
56
@start:
57
	.byt	$80,$00
58
@size2:
59
	.byt	$40,$00
60
 
61
.segment	"STARTUP"
62
	.word	startup		;Cold start
63
	.word	$FEBC		;Warm start, default calls NMI exit.
64
	.byt	$C3,$C2,$CD,$38,$30 ;magic to identify cartridge
65
 
66
startup:
67
	jsr	$FF84		;Init. I/O
68
	jsr	$FF87		;Init. RAM
69
	jsr	$FF8A		;Restore vectors
70
	jsr	$FF81		;Init. screen
71
 
72
; Switch to second charset
73
 
74
	lda	#14
75
	jsr	BSOUT
76
 
77
; Clear the BSS data
78
 
79
	jsr	zerobss
80
 
81
	lda    	#<(__RAM_START__ + __RAM_SIZE__)
82
	sta	sp
83
	lda	#>(__RAM_START__ + __RAM_SIZE__)
84
       	sta	sp+1   		; Set argument stack ptr
85
 
86
; If we have IRQ functions, chain our stub into the IRQ vector
87
 
88
;        lda     #<__INTERRUPTOR_COUNT__
89
;      	beq	NoIRQ1
90
;      	lda	IRQVec
91
;       	ldx	IRQVec+1
92
;      	sta	IRQInd+1
93
;      	stx	IRQInd+2
94
;      	lda	#<IRQStub
95
;      	ldx	#>IRQStub
96
;      	sei
97
;      	sta	IRQVec
98
;      	stx	IRQVec+1
99
;      	cli
100
 
101
; Call module constructors
102
 
103
 
104
NoIRQ1:
105
	lda	#<__DATA_RUN__
106
	ldx	#>__DATA_RUN__
107
	jsr	pushax
108
	lda	#<__DATA_LOAD__
109
	ldx	#>__DATA_LOAD__
110
	jsr	pushax
111
	lda	#<__DATA_SIZE__
112
	ldx	#>__DATA_SIZE__
113
	jsr	_memcpy
114
 
115
 
116
	jsr	initlib
117
 
118
; Push arguments and call main
119
;ra:
120
;	inc	$D021
121
;	jmp	ra
122
 
123
 
124
        jsr     callmain
125
 
126
; Back from main (This is also the _exit entry). Run module destructors
127
 
128
_exit:  jsr	donelib
129
 
130
 
131
; Reset the IRQ vector if we chained it.
132
 
133
;        ;pha  			; Save the return code on stack
134
;	lda     #<__INTERRUPTOR_COUNT__
135
;	beq	NoIRQ2
136
;	lda	IRQInd+1
137
;	ldx	IRQInd+2
138
;	sei
139
;	sta	IRQVec
140
;	stx	IRQVec+1
141
;	cli
142
 
143
 
144
NoIRQ2:	
145
	lda	#<exitmsg
146
	ldx	#>exitmsg
147
	jsr	_puts
148
	jsr	_cgetc
149
	jmp	64738		;Kernal reset address as best I know it.
150
 
151
.rodata
152
exitmsg:
153
	.byt	"Your program has ended.  Press any key",13,"to continue...",0
154