-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprint.s
202 lines (160 loc) · 4.41 KB
/
print.s
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
;
; This is a simple display module
; called by the C part of the program
;
;
; We define the adress of the TEXT screen.
;
#define DISPLAY_ADRESS $BB80
;
; We use a table of bytes to avoid the multiplication
; by 40. We could have used a multiplication routine
; but introducing table accessing is not a bad thing.
; In order to speed up things, we precompute the real
; adress of each start of line. Each table takes only
; 28 bytes, even if it looks impressive at first glance.
;
; This table contains lower 8 bits of the adress
ScreenAdressLow
.byt <(DISPLAY_ADRESS+40*0)
.byt <(DISPLAY_ADRESS+40*1)
.byt <(DISPLAY_ADRESS+40*2)
.byt <(DISPLAY_ADRESS+40*3)
.byt <(DISPLAY_ADRESS+40*4)
.byt <(DISPLAY_ADRESS+40*5)
.byt <(DISPLAY_ADRESS+40*6)
.byt <(DISPLAY_ADRESS+40*7) ; 00000001 [00011000]=low address
.byt <(DISPLAY_ADRESS+40*8)
.byt <(DISPLAY_ADRESS+40*9)
.byt <(DISPLAY_ADRESS+40*10)
.byt <(DISPLAY_ADRESS+40*11)
.byt <(DISPLAY_ADRESS+40*12)
.byt <(DISPLAY_ADRESS+40*13)
.byt <(DISPLAY_ADRESS+40*14)
.byt <(DISPLAY_ADRESS+40*15)
.byt <(DISPLAY_ADRESS+40*16)
.byt <(DISPLAY_ADRESS+40*17)
.byt <(DISPLAY_ADRESS+40*18)
.byt <(DISPLAY_ADRESS+40*19)
.byt <(DISPLAY_ADRESS+40*20)
.byt <(DISPLAY_ADRESS+40*21)
.byt <(DISPLAY_ADRESS+40*22)
.byt <(DISPLAY_ADRESS+40*23)
.byt <(DISPLAY_ADRESS+40*24)
.byt <(DISPLAY_ADRESS+40*25)
.byt <(DISPLAY_ADRESS+40*26)
.byt <(DISPLAY_ADRESS+40*27)
; This table contains hight 8 bits of the adress
ScreenAdressHigh
.byt >(DISPLAY_ADRESS+40*0)
.byt >(DISPLAY_ADRESS+40*1)
.byt >(DISPLAY_ADRESS+40*2)
.byt >(DISPLAY_ADRESS+40*3)
.byt >(DISPLAY_ADRESS+40*4)
.byt >(DISPLAY_ADRESS+40*5)
.byt >(DISPLAY_ADRESS+40*6)
.byt >(DISPLAY_ADRESS+40*7) ; high address =[00000001]0001100
.byt >(DISPLAY_ADRESS+40*8)
.byt >(DISPLAY_ADRESS+40*9)
.byt >(DISPLAY_ADRESS+40*10)
.byt >(DISPLAY_ADRESS+40*11)
.byt >(DISPLAY_ADRESS+40*12)
.byt >(DISPLAY_ADRESS+40*13)
.byt >(DISPLAY_ADRESS+40*14)
.byt >(DISPLAY_ADRESS+40*15)
.byt >(DISPLAY_ADRESS+40*16)
.byt >(DISPLAY_ADRESS+40*17)
.byt >(DISPLAY_ADRESS+40*18)
.byt >(DISPLAY_ADRESS+40*19)
.byt >(DISPLAY_ADRESS+40*20)
.byt >(DISPLAY_ADRESS+40*21)
.byt >(DISPLAY_ADRESS+40*22)
.byt >(DISPLAY_ADRESS+40*23)
.byt >(DISPLAY_ADRESS+40*24)
.byt >(DISPLAY_ADRESS+40*25)
.byt >(DISPLAY_ADRESS+40*26)
.byt >(DISPLAY_ADRESS+40*27)
;
; The message and display position will be read from the stack.
; sp+0 => X coordinate
; sp+2 => Y coordinate
; sp+4 => Adress of the message to display
;
_AdvancedPrint
; Initialise display adress
; this uses self-modifying code
; (the $0123 is replaced by display adress)
; The idea is to get the Y position from the stack,
; and use it as an index in the two adress tables.
; We also need to add the value of the X position,
; also taken from the stack to the resulting value.
ldy #2
lda (sp),y ; Access Y coordinate
tax
lda ScreenAdressLow,x ; Get the LOW part of the screen adress
clc ; Clear the carry (because we will do an addition after)
ldy #0
adc (sp),y ; Add X coordinate
sta write+1
lda ScreenAdressHigh,x ; Get the HIGH part of the screen adress
adc #0 ; Eventually add the carry to complete the 16 bits addition
sta write+2
; Initialise message adress using the stack parameter
; this uses self-modifying code
; (the $0123 is replaced by message adress)
ldy #4
lda (sp),y
sta read+1
iny
lda (sp),y
sta read+2
; Start at the first character
ldx #0
loop_char
; Read the character, exit if it's a 0
read
lda $0123,x
beq end_loop_char
; Write the character on screen
write
sta $0123,x
; Next character, and loop
inx
jmp loop_char
; Finished !
end_loop_char
rts
; sp [0] sound_adr_low
; sp [1] sound_adr_high
; sp [2] sound volume
_SoundEffect
sta $A000,65; for debugging
ldy #0 ; load low part of address
lda(sp),y
sta read_s+1
ldy #1 ; load high part of address
lda(sp),y
sta read_s+2
ldx #13 ; sound byte number = 14
clc
suite
read_s
lda $1234,x
sta sound_table,x
dex
bne suite
;ldy #2 ; load sound volume
;lda(sp),y
;ldy #8
;sta sound_table,y
;ldy #9
;sta sound_table,y
;ldy #10
;sta sound_table,y
ldx #<sound_table
ldy #>sound_table
jmp $FA86
rts
array_adr .dsb 2
sound_table
.byt 0,0,0,0,0,0,0,0,0,0,0,0,0,0