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