aboutsummaryrefslogtreecommitdiff
path: root/loadscreen.dasm
blob: e623d09d75e5ca5af5f5d5c7e86d06c544966ae8 (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

; 20070524 bkw: DASM source for GR.2 "LOADING..." screen.
; Object code is intended to be prepended to some other object
; file, so it uses INITAD rather than RUNAD.

; WARNING: if you modify this file such that the object code changes,
; make sure you edit cart2bin.c and correct the offset for the title
; screen text! As long as you don't change anything after the "loading"
; label, this won't be a problem.

 processor 6502

 include "equates.inc"

 seg.u ZP
 org $80

 if * > $ff
   echo "Zero page vars have overrun into the stack! * =", *
   err
 else
   echo *-$80, "bytes of zero page used,", $ff-*, "remain"
 endif

 seg CODE

LOAD_ADDR = $6000 ; load at 24K
origin = LOAD_ADDR-6;
 org origin ; make room for 6-byte header

; 2-byte Atari executable header:
 byte $FF, $FF ; let DOS know it's a binary load file

; start of first segment

; 4-byte segment header:
 word LOAD_ADDR ; Load address
 word endbin-1 ; Last byte to load

; Rest of segment contains code and data
pagesize byte 0   ; cart2bin will fill this in with the size of
                  ; the cart image code, in pages.
main:

; set RAMTOP to 28K, call GR.2, store "LOADING..." in screen RAM,
; then set RAMTOP back to original value.

 lda RAMTOP
 cmp #$C0     ; do we have 48K?
 bcs ram_ok

 ldx #0       ; no! print error message...
 lda #9
 sta ICCOM
 lda #<ram_msg
 sta ICBAL
 lda #>ram_msg
 sta ICBAH
 lda #ram_msg_len
 sta ICBLL
 stx ICBLH
 jsr CIOV
hang bcs hang ; spin forever

ram_msg byte "Need at least 48K to run this.", $9B
ram_msg_len = *-ram_msg+1

ram_ok
 ;sec          ; carry already set by cmp above!
 sbc pagesize  ; adjust RAMTOP to make room for the converted cart image
 pha           ; save old RAMTOP value on stack

 lda #$70      ; set RAMTOP to $7000 (28K). Later on we do GRAPHICS 2,
 sta RAMTOP    ; which will cause the DL and screen RAM to go here.

 ldx #$60      ; CLOSE #6 first
 lda #12       ; Command 12=CLOSE
 sta ICCOM,x
 jsr CIOV      ; call CIO, ignore any error

 ;ldx #$60     ; set up IOCB #6 for CIO GRAPHICS command
 lda #3        ; Command 3=OPEN
 sta ICCOM,x
 lda #12       ; 12=R/W access
 sta ICAX1,x
 lda #2        ; GR. mode 2
 sta ICAX2,x
 lda #<s_dev   ; S: device
 sta ICBAL,x
 lda #>s_dev
 sta ICBAH,x
 lda #s_dev_len
 sta ICBLL,x
 lda #0
 sta ICBLH,x
 jsr CIOV      ; call CIO

 lda #5        ; POSITION 5,5
 sta ROWCRS
 sta COLCRS
 lda #0
 sta COLCRS+1

 sta ICBLH,x   ; PRINT #6;"LOADING...
; ldx #$60
 lda #9        ; Command 9 = CIO "put record"
 sta ICCOM,x
 lda #<loading
 sta ICBAL,x
 lda #>loading
 sta ICBAH,x
 lda #loading_len
 sta ICBLL,x
 jsr CIOV      ; call CIO

; ldx #$60     ; CLOSE #6
 lda #12       ; Command 12=CLOSE
 sta ICCOM,x
 jsr CIOV      ; call CIO, ignore any error

 pla           ; get adjusted RAMTOP value
 sta RAMTOP

 rts           ; end of init routine, return control to DOS

s_dev byte "S:"
s_dev_len equ *-s_dev+1

; WARNING: if you change any code/data below this line, you'll probably need
; to change the offset in cart2bin.c as well.
loading byte "  LOADING"
        ds 6
title   ds 20      ; cart2bin will fill in these 20 bytes with the filename
        byte $9B   ; (or title, if -t is used)
loading_len equ *-loading+1

endbin ; end of first segment

 echo "Code is", *-origin+1, "bytes"

; start of second segment (which loads at INITAD, to tell DOS
; where to start running the init code loaded in segment 1)

 ; 4-byte segment header:
 word INITAD    ; load address (loading into INITAD lets our code run)
 word INITAD+1  ; Last byte to load

 ; Segment data contains 2 bytes (the actual run address)
 word main     ; the 2 bytes to stuff into RUNAD

 ; That's all, folks!
 echo "Title offset: loadscreen_bin_len - ", *-title