]> git.sur5r.net Git - cc65/blob - testcode/lib/gamate/audiotest.s
moved cart header into seperate file, moved nmi stub into several file, tweaked linke...
[cc65] / testcode / lib / gamate / audiotest.s
1
2 ; original audiotest.s by PeT (mess@utanet.at)
3
4         .include "gamate.inc"
5
6         .zeropage
7 addr:   .word 0
8 psa:    .word 0
9
10 .word 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 ; get out of sensitiv area
11
12 readaddr: .word 0
13 editbuffer1: .byte 0,0,0,0, 0,0,0,0 ;0,1,2,3,4,5,6,7
14 writeaddr: .word 0
15 editbuffer2: .byte 0,0,0,0, 0,0,0,0 ;8,9,$a,$b,$c,$d,$e,$f
16 cursor: .byte 0
17 controlslast: .byte 0
18 controlsedge: .byte 0
19
20 .data
21 temp_x: .byte 0
22 temp_y: .byte   0
23 temp_a: .byte 0
24 irq_count:      .byte 0
25 nmi_count:      .byte 0
26 psx:    .byte 0
27 psy:    .byte 0
28 xpos: .byte 0
29 ypos:   .byte 0
30
31         .code
32
33 chars:          .incbin "cga2.chr"
34 hex2asc:        .byte "0123456789abcdef"
35
36 ;-------------------------------------------------------------------------------
37         .export IRQStub, NMIStub
38
39 .proc   NMIStub
40         inc nmi_count
41         rts
42 .endproc
43
44 .proc   IRQStub
45         inc irq_count
46         rts
47 .endproc
48
49 ;-------------------------------------------------------------------------------
50         .export Start
51
52 .proc   Start
53         lda #>AUDIO_BASE
54         sta writeaddr+1
55         sta readaddr+1
56         lda #<AUDIO_BASE
57         sta writeaddr
58         sta readaddr
59
60         lda #$10
61         sta editbuffer1+6
62         lda #$e
63         sta editbuffer2+5
64         lda #$ff
65         sta editbuffer2+3
66         lda #$ff
67         sta editbuffer2+4
68         lda #$0f
69         sta editbuffer2
70         lda #$0f
71         sta editbuffer2+1
72         lda #$0e
73         sta editbuffer2+2
74         lda     #$38
75         sta editbuffer1+7
76
77         lda #0
78         sta     LCD_XPOS
79         sta LCD_YPOS
80         sta irq_count
81         sta cursor
82         lda #1
83         sta nmi_count
84         cli
85         lda     #LCD_MODE_INC_Y
86         sta     LCD_MODE
87
88         jsr printy
89
90         lda #1
91         sta ZP_NMI_ENABLE
92
93 loop:   
94         lda irq_count
95 loop1:
96         cmp irq_count
97         beq     loop1
98         lda irq_count
99         and #7
100         bne loop1
101
102         lda     #LCD_MODE_INC_Y
103         sta     LCD_MODE
104
105         ldx #3
106         ldy #32
107         lda irq_count
108         jsr printhex
109
110
111         lda cursor
112         ldy     #0
113         cmp #20
114         bcc firstline
115         sec
116         sbc     #20
117         ldy #24
118 firstline:
119         sta LCD_X
120         sty LCD_Y
121         lda #' '
122         jsr printsign
123 norclearcursor:
124
125         jsr inputs
126
127         lda irq_count
128         and #8
129         bne nocursor
130         lda cursor
131         ldy     #0
132         cmp #20
133         bcc firstline2
134         sec
135         sbc     #20
136         ldy #24
137 firstline2:
138         sta LCD_X
139         sty LCD_Y
140         lda #'x'
141         jsr printsign
142 nocursor:
143
144         lda     #LCD_MODE_INC_Y
145         sta     LCD_MODE
146         jsr printy
147         jmp loop
148 .endproc
149
150 .proc printy
151
152         ldy #0
153 loop1: 
154         tya
155         pha
156         asl
157         tax
158         lda readaddr,y
159         ldy #8
160         jsr printhex
161         pla
162         tay
163         iny
164         cpy #10
165         bne loop1
166
167 loop2:
168         tya
169         pha
170         tya
171         sec
172         sbc #10
173         asl
174         tax
175         lda readaddr,y
176         ldy #16
177         jsr printhex
178         pla
179         tay
180         iny
181         cpy #20
182         bne loop2
183
184         ldx #0
185         ldy #32
186         lda nmi_count
187         jsr printhex
188
189         rts
190 .endproc
191
192 ;-------------------------------------------------------------------------------
193
194 .proc inputs
195         lda controlslast
196         eor JOY_DATA
197         and controlslast
198         eor #$ff
199         sta controlsedge
200         and #JOY_DATA_UP
201         bne notup
202
203         lda cursor
204         lsr
205         tay
206         bcs uplow
207         lda readaddr,y
208         clc
209         adc #$10
210         sta readaddr,y
211         jmp notup
212 uplow:lda readaddr,y
213         clc
214         adc #1
215         sta readaddr,y
216 notup:lda controlsedge
217         and #JOY_DATA_DOWN
218         bne notdown
219         lda cursor
220         lsr
221         tay
222         bcs downlow
223         lda readaddr,y
224         sec
225         sbc #$10
226         sta readaddr,y
227         jmp notdown
228 downlow:
229         lda readaddr,y
230         sec
231         sbc #1
232         sta readaddr,y
233 notdown:lda controlsedge
234         and #JOY_DATA_LEFT
235         bne notleft
236         lda cursor
237         beq notleft
238         dec cursor
239 notleft:lda controlsedge
240         and #JOY_DATA_RIGHT
241         bne notright
242         lda cursor
243         cmp #40
244         beq notright
245         inc cursor
246 notright:lda controlsedge
247         and #JOY_DATA_START
248         bne notstart
249         lda #0
250         sta AUDIO_BASE
251         sta AUDIO_BASE+1
252         sta AUDIO_BASE+2
253         sta AUDIO_BASE+3
254         sta AUDIO_BASE+4
255         sta AUDIO_BASE+5
256         sta AUDIO_BASE+6
257         sta AUDIO_BASE+8
258         sta AUDIO_BASE+9
259         sta AUDIO_BASE+10
260         sta AUDIO_BASE+11
261         sta AUDIO_BASE+12
262         sta AUDIO_BASE+13
263         sta AUDIO_BASE+7
264 notstart:lda controlsedge
265         and #JOY_DATA_SELECT
266         bne notselect
267         lda editbuffer1
268         sta AUDIO_BASE
269         lda editbuffer1+1
270         sta AUDIO_BASE+1
271         lda editbuffer1+2
272         sta AUDIO_BASE+2
273         lda editbuffer1+3
274         sta AUDIO_BASE+3
275         lda editbuffer1+4
276         sta AUDIO_BASE+4
277         lda editbuffer1+5
278         sta AUDIO_BASE+5
279         lda editbuffer1+6
280         sta AUDIO_BASE+6
281         lda editbuffer2
282         sta AUDIO_BASE+8
283         lda editbuffer2+1
284         sta AUDIO_BASE+9
285         lda editbuffer2+2
286         sta AUDIO_BASE+10
287         lda editbuffer2+3
288         sta AUDIO_BASE+11
289         lda editbuffer2+4
290         sta AUDIO_BASE+12
291         lda editbuffer2+5
292         sta AUDIO_BASE+13
293         lda editbuffer1+7
294         sta AUDIO_BASE+7
295 notselect:lda controlsedge
296         and #JOY_DATA_FIRE_A
297         bne notbuttona
298         ldy #0
299         ldy #0
300 writea:lda editbuffer1,y
301         sta (writeaddr),y
302         iny
303         cpy     #8
304         bne writea
305 writeb:lda editbuffer2-8,y
306         sta (writeaddr),y
307         iny
308         cpy     #16
309         bne writeb
310 notbuttona:lda controlsedge
311         and #JOY_DATA_FIRE_B
312         bne notbuttonb
313         ldy #0
314 reada:lda (readaddr),y
315         sta editbuffer1,y
316         iny
317         cpy     #8
318         bne reada
319 readb:lda (readaddr),y
320         sta editbuffer2-8,y
321         iny
322         cpy     #16
323         bne readb
324 notbuttonb:
325         lda JOY_DATA
326         sta     controlslast
327         rts
328 .endproc
329
330 ;-------------------------------------------------------------------------------
331
332 .proc printstring
333         sta     psa
334         stx psa+1
335         ldx #0
336         stx     psx
337         sty psy
338 printstring2:
339         ldy     #0
340         lda     (psa),y
341         beq printstring1
342         ldx psx
343         stx     LCD_X
344         ldy psy
345         sty     LCD_Y
346         jsr printsign
347         inc psx
348         lda psa
349         clc
350         adc     #1
351         sta psa
352         lda psa+1
353         adc     #0
354         sta psa+1
355         jmp printstring2
356 printstring1:
357         rts
358 .endproc
359
360 .proc printstringy
361         sta     psa
362         stx psa+1
363 printstring2:
364         ldy     #0
365         lda     (psa),y
366         beq printstring1
367         jsr printsign
368         lda psa
369         clc
370         adc     #1
371         sta psa
372         lda psa+1
373         adc     #0
374         sta psa+1
375         jmp printstring2
376 printstring1:
377         rts
378 .endproc
379
380
381 .proc printhex
382         pha
383         lsr
384         lsr
385         lsr
386         lsr
387         and #$0f
388         stx     temp_x
389         tax
390         lda     hex2asc,x
391         ldx     temp_x
392         stx     LCD_X
393         sty     LCD_Y
394         jsr     printsign
395         pla
396         and     #$0f
397         inx
398         stx     temp_x
399         tax
400         lda     hex2asc,x
401         ldx     temp_x
402         stx     LCD_X
403         sty     LCD_Y
404         jmp printsign
405 .endproc
406
407 .proc printsign
408         sty     temp_y
409         stx     temp_x
410         sta     temp_a
411         lda temp_a
412         sta     addr
413         lda #0
414         sta addr+1
415         asl     addr
416         rol     addr+1
417         asl     addr
418         rol addr+1
419         asl addr
420         rol addr+1
421         lda addr
422         clc
423         adc     #<chars
424         sta     addr
425         lda     addr+1
426         adc     #>chars
427         sta addr+1
428         ldx     #8
429         ldy #0
430 printsign1:
431         lda     (addr),y
432         sta     LCD_DATA
433         iny
434         dex
435         bne printsign1
436         ldx     temp_x
437         ldy     temp_y
438         rts
439 .endproc
440