]> git.sur5r.net Git - cc65/blob - libsrc/osic1p/bootstrap.s
2a501b980ca5967e097f30ffae5ad5fa05384c02
[cc65] / libsrc / osic1p / bootstrap.s
1 ;
2 ; 2015-03-08, Greg King
3 ;
4
5 ; When you want to create a program with the alternate file format,
6 ; add "-u __BOOT__" to the cl65/ld65 command line.  Then, the linker
7 ; will import this symbol name; and, link this module at the front
8 ; of your program file.
9 ;
10         .export         __BOOT__:abs = 1
11
12         .import         __RAM_START__, __RAM_SIZE__, __BSS_RUN__
13
14 ; ------------------------------------------------------------------------
15
16 load_addr       :=      __RAM_START__
17 load_size       =       __BSS_RUN__ - __RAM_START__
18 ram_top         :=      __RAM_START__ + __RAM_SIZE__
19
20         .segment        "BOOT"
21
22 ; If you want to change how this bootstrap loader works, then:
23 ; 1. edit this assembly source code,
24 ; 2. define the constant ASM (uncomment the line below),
25 ; 3. assemble this file (and, make a listing of that assembly),
26 ; 4. copy the listing's hex codes into the .byte lines below (notice that most
27 ;    of the strings are followed by CR; it's required by the OS65V monitor)
28 ;    (be sure to match the listing's lines against the .byte lines),
29 ; 5. undefine ASM (recomment the line),
30 ; 6. assemble this file, again,
31 ; 7. and, add the object file to "osic1p.lib".
32
33 ;ASM = 1
34
35 .ifdef ASM
36
37         .include        "osic1p.inc"
38         .macpack        generic
39
40 load            :=      $08             ; private variables
41 count           :=      $0A
42
43 GETCHAR         :=      $FFBF           ; gets one character from ACIA
44
45 FIRSTVISC       =       $85             ; Offset of first visible character in video RAM
46 LINEDIST        =       $20             ; Offset in video RAM between two lines
47
48         ldy     #<$0000
49         lda     #<load_addr
50         ldx     #>load_addr
51         sta     load
52         stx     load+1
53         lda     #<load_size
54         eor     #$FF
55         sta     count                   ; store (-size - 1)
56         lda     #>load_size
57         eor     #$FF
58         sta     count+1
59
60 L1:     inc     count                   ; pre-count one's-complement upwards
61         bnz     L2
62         inc     count+1
63         bze     L3
64 L2:     jsr     GETCHAR                 ; (doesn't change .Y)
65         sta     (load),y
66
67 ; Show that the file is being loaded by rotating an arrow on the screen.
68 ;
69         tya
70         lsr     a
71         lsr     a
72         and     #8 - 1
73         ora     #$10                    ; eight arrow characters
74         sta     SCRNBASE + FIRSTVISC + 2 * LINEDIST + 11
75
76         iny
77         bnz     L1
78         inc     load+1
79         bnz     L1                      ; branch always
80
81 L3:     jmp     load_addr
82
83 .else
84
85 .mac    hex1    h
86         .lobytes        ((h) & $0F) + (((h) & $0F) > 9) * 7 + '0'
87 .endmac
88
89 .mac    hex2    h
90         hex1    (h) >> 4
91         hex1    (h) >> 0
92 .endmac
93
94 .mac    hex4    h
95         hex2    >(h)
96         hex2    <(h)
97 .endmac
98
99 CR      =       $0D
100
101         .byte   CR, CR
102         .byte   "."                     ; set an address
103         hex4    ram_top                 ; put loader where stack will sit
104         .byte   "/"                     ; write bytes into RAM
105
106 ; ASCII-coded hexadecimal translation of the above assembly code.
107 ; It was copied from the assembler listing.
108
109         .byte   "A0", CR, "00", CR
110         .byte   "A9", CR
111         hex2    <load_addr
112         .byte   CR, "A2", CR
113         hex2    >load_addr
114         .byte   CR, "85", CR, "08", CR
115         .byte   "86", CR, "09", CR
116         .byte   "A9", CR
117         hex2    <load_size
118         .byte   CR, "49", CR, "FF", CR
119         .byte   "85", CR, "0A", CR
120         .byte   "A9", CR
121         hex2    >load_size
122         .byte   CR, "49", CR, "FF", CR
123         .byte   "85", CR, "0B", CR
124
125         .byte   "E6", CR, "0A", CR
126         .byte   "D0", CR, "04", CR
127         .byte   "E6", CR, "0B", CR
128         .byte   "F0", CR, "16", CR
129         .byte   "20", CR, "BF", CR, "FF", CR
130         .byte   "91", CR, "08", CR
131
132         .byte   "98", CR
133         .byte   "4A", CR
134         .byte   "4A", CR
135         .byte   "29", CR, "07", CR
136         .byte   "09", CR, "10", CR
137         .byte   "8D", CR, "D0", CR, "D0", CR
138
139         .byte   "C8", CR
140         .byte   "D0", CR, "E6", CR
141         .byte   "E6", CR, "09", CR
142         .byte   "D0", CR, "E2", CR
143
144         .byte   "4C", CR
145         hex2    <load_addr
146         .byte   CR
147         hex2    >load_addr
148
149         .byte   CR, "."
150         hex4    ram_top
151         .byte   "G"                     ; go to address
152
153 .endif