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