]> git.sur5r.net Git - cc65/blob - libsrc/creativision/crt0.s
Merge pull request #61 from greg-king5/make
[cc65] / libsrc / creativision / crt0.s
1 ;
2 ; Startup code for cc65 (CreatiVision version)
3 ;
4
5         .export         _exit
6         .export         __STARTUP__ : absolute = 1      ; Mark as startup
7         .import         zerobss, copydata
8         .import         initlib, donelib, callmain
9         .import         __VECTORS_LOAD__, __VECTORS_RUN__, __VECTORS_SIZE__
10         .import         __ZP_LAST__, __STACKSIZE__, __RAM_START__
11
12         .include        "zeropage.inc"
13
14 ; ------------------------------------------------------------------------
15
16 entry:
17         ; Init the CPU
18         sei
19         cld
20
21         ; Copy the IRQ vectors
22         ldx     #<__VECTORS_SIZE__ - 1
23 :       lda     __VECTORS_LOAD__,x
24         sta     __VECTORS_RUN__,x
25         dex
26         bpl     :-
27
28         ; Setup the CPU stack ptr
29         ldx     #<__RAM_START__ - 1
30         txs
31
32         ; Start interrupts
33         cli
34
35         ; Clear the BSS data
36         jsr     zerobss
37
38         ; Copy data from ROM to RAM
39         jsr     copydata
40
41         ; Setup the argument stack ptr
42         lda     #<(__ZP_LAST__ + __STACKSIZE__)
43         ldx     #>(__ZP_LAST__ + __STACKSIZE__)
44         sta     sp
45         stx     sp+1
46
47         ; Call module constructors
48         jsr     initlib
49
50         ; Call main()
51         jsr     callmain
52
53         ; Call module destructors. This is also the _exit entry.
54 _exit:  jsr     donelib
55
56         ; TODO: Replace with some sort of reset
57 loop:   jmp loop
58
59 ; ------------------------------------------------------------------------
60 ; Define the IRQ vectors.
61
62 .segment        "VECTORS"
63
64 irq1:   jmp     $FF3F
65 irq2:   jmp     $FF52
66
67 ; ------------------------------------------------------------------------
68 ; Define CART setup values for BIOS.
69
70 .segment        "SETUP"
71
72         ; BIOS Jump Start
73         ; This is where the entry point of the program needs to be
74         .addr   entry
75         .addr   irq2
76
77         .res    4
78
79         ; VDP Setup
80         ; This sets to Graphics Mode 1
81         .byte   $00             ; Register 0
82         .byte   $C0             ; Register 1 16K RAM, Active Display, Mode 1
83         .byte   $04             ; Register 2 Name Table at $1000 - $12FF
84         .byte   $60             ; Register 3 Colour Table at $1800 - $181F
85         .byte   $00             ; Register 4 Pattern Table at $0000 - $07FF
86         .byte   $10             ; Register 5 Sprite Attribute at $0800 - $087F
87         .byte   $01             ; Register 6 Sprite Pattern
88         .byte   $F1             ; Register 7 Text colour Foreground / background
89
90         .res    4
91
92         ; BIOS Vector after NMI or RESET
93         ; Keeping with retail cartridges, we jump back to BIOS ROM and have it
94         ; setup zeropage etc, and show the Creativision logo and copyright.
95         .addr $F808
96
97         ; BIOS Short Interrupt Handler
98         ; Vectored from BIOS ROM:FE2C. This should contain a pointer to the user's
99         ; BIOS interrupt handler.
100         .addr irq1
101
102 ; ------------------------------------------------------------------------