/[projet1]/public/oric/demos/assembly_2002/player.s
Defence Force logotype

Contents of /public/oric/demos/assembly_2002/player.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 473 - (show annotations)
Fri Apr 29 22:00:16 2011 UTC (8 years, 9 months ago) by dbug
File size: 8123 byte(s)
Added the Assembly 2002 demo, it's very messy, need some cleanup, but well
1
2
3 ;
4 ; Time/Synchronisation 6502 assembly library
5 ; (c) 1996 Micka¬Čl POINTIER (Dbug from NeXT)
6 ;
7 ; Time value is 16 bits coded, so the maximum value is:
8 ; 65536 100th of a second
9 ; 655 seconds
10 ; 10 minutes
11 ;
12
13
14 #define MUSIC_START _music_data
15
16
17 _HexTable
18 .asc "0123456789ABCDEF"
19
20
21 ; 21 minutes max (65536/50)
22 _CurrentSync
23 .word 0
24
25 _CurrentSyncCopy
26 .word 0
27
28 _LastSync
29 .word 0
30
31 _VblFlag
32 .byt 2
33
34 ;
35 ; Increment by one every 50th of a second
36 ;
37 _TimeIrqHandler
38 pha
39
40 dec _VblFlag
41 bne irq_end
42 lda #2
43 sta _VblFlag
44
45 inc _CurrentSync
46 bne irq_end
47 inc _CurrentSync+1
48 irq_end
49
50 pla
51 rts
52
53
54 ;
55 ; Come back only when there is at least one 50th of a second between two calls
56 ;
57 _VSync
58 sei
59 lda _CurrentSync
60 sta _CurrentSyncCopy
61 lda _CurrentSync+1
62 sta _CurrentSyncCopy+1
63 cli
64
65 ;
66 ; Increment current VBL value
67 ;
68 inc _LastSync
69 bne sync_end
70 inc _LastSync+1
71 sync_end
72
73
74
75 sync_loop
76 ; Copy VBL counter
77 sei
78 lda _CurrentSync
79 sta _CurrentSyncCopy
80 lda _CurrentSync+1
81 sta _CurrentSyncCopy+1
82 cli
83
84 lda _CurrentSyncCopy+1
85 cmp _LastSync+1
86 bcc sync_loop
87
88 lda _CurrentSyncCopy
89 cmp _LastSync
90 bcc sync_loop
91
92 rts
93
94
95
96
97
98
99
100 #define VIA_1 $30f
101 #define VIA_2 $30c
102
103
104
105 _PsgControl .byt 0
106 _PsgData .byt 0
107
108 _PsgVbl
109 .byt 0
110
111
112 _PsgPlay
113 lda _PsgVbl
114 sta psg_play_read+1
115 lda #>_PlayerBuffer
116 sta psg_play_read+2
117
118 lda #0
119 sta _PsgControl
120 ldy #14
121 sei
122 psg_play_loop
123
124 psg_play_read
125 ldx _PlayerBuffer
126 lda _PsgControl
127
128 sta VIA_1
129 txa
130
131 pha
132 lda VIA_2
133 ora #$EE ; $EE 238 11101110
134 sta VIA_2
135
136 and #$11 ; $11 17 00010001
137 ora #$CC ; $CC 204 11001100
138 sta VIA_2
139
140 tax
141 pla
142 sta VIA_1
143 txa
144 ora #$EC ; $EC 236 11101100
145 sta VIA_2
146
147 and #$11 ; $11 17 00010001
148 ora #$CC ; $CC 204 11001100
149 sta VIA_2
150
151 inc _PsgControl
152 inc psg_play_read+2
153 dey
154 bne psg_play_loop
155 cli
156
157 rts
158
159
160
161
162
163 ;
164 ; Size in bits of each PSG register
165 ;
166 _PlayerRegBits
167 ; Chanel A Frequency
168 .byt 8
169 .byt 4
170
171 ; Chanel B Frequency
172 .byt 8
173 .byt 4
174
175 ; Chanel C Frequency
176 .byt 8
177 .byt 4
178
179 ; Chanel sound generator
180 .byt 5
181
182 ; select
183 .byt 8
184
185 ; Volume A,B,C
186 .byt 5
187 .byt 5
188 .byt 5
189
190 ; Wave period
191 .byt 8
192 .byt 8
193
194 ; Wave form
195 .byt 8
196
197
198
199
200
201 ;
202 ; Current PSG values during unpacking
203 ;
204 _PlayerRegValues
205 .dsb 14
206
207 _PlayerRegCurrentValue
208 .byt 0
209
210
211 #define REGS 14
212 #define FRAG 128
213 #define OFFNUM 14
214 #define OFFHALF 7
215
216
217
218
219 ;
220 ; Allign the following data on a 256 bytes
221 ; boundary in order to optimise the accessing
222 ; code.
223 ;
224 .dsb 256-(*&255)
225
226 ;
227 ; Unpacking buffer.
228 ; A big, huge, one
229 ;
230 _PlayerBuffer
231 .dsb 256*14
232
233 _PlayerVbl
234 .word 0
235
236 _PlayerVblRow
237 .byt 0
238
239 _PlayerRegister
240 .byt 0
241
242 _PlayerRegPointer
243 .byt 0
244
245 _PlayerUnpackCount
246 .byt 0
247
248 _ReadBitResult
249 .byt 0
250
251 CurrentMask
252 .byt 0
253
254 CurrentByte
255 .byt 0
256
257 _MusicRowCount
258 .word 0
259
260
261 _PlayerInit
262 ; 2 first bytes represent the number of rows
263 lda MUSIC_START
264 sta _MusicRowCount
265 lda MUSIC_START+1
266 sta _MusicRowCount+1
267
268 ; Then the music itself
269 lda #<(MUSIC_START+2)
270 sta ptr_music+1
271 lda #>(MUSIC_START+2)
272 sta ptr_music+2
273
274 lda #0
275
276 ; Clear all data
277
278 sta _ReadBitResult
279
280 sta CurrentMask
281 sta CurrentByte
282
283 sta _PlayerVbl
284 sta _PlayerVbl+1
285
286 sta _PlayerVblRow
287
288 sta _PlayerRegCurrentValue
289
290 ldx #14
291 loop_init
292 dex
293 sta _PlayerRegValues,x
294 bne loop_init
295 rts
296
297
298
299 ;
300 ; Initialise X with the number of bits to read
301 ; Y is not modifier
302 ; A is saved and restored..
303 ;
304 _ReadBits
305 ;
306 ; save regs
307 ;
308 pha
309
310 ;
311 ; initialise result to 0
312 ;
313 lda #0
314 sta _ReadBitResult
315
316 ;
317 ; loop X (parameter) time
318 ;
319 loop_read_bits
320
321 ;
322 ; shift result left
323 ;
324 asl _ReadBitResult
325
326 ;
327 ; check for reload
328 ;
329 lda CurrentMask
330 bne no_reload
331
332 ;
333 ; reset mask
334 ;
335 lda #128
336 sta CurrentMask
337
338 ;
339 ; fetch a new byte, and
340 ; increment the adress.
341 ;
342 ptr_music
343 lda MUSIC_START+2
344 sta CurrentByte
345
346 inc ptr_music+1
347 bne no_wrap
348 inc ptr_music+2
349 no_wrap
350
351 no_reload
352
353
354 lda CurrentByte
355 and CurrentMask
356 beq skip_bit
357 inc _ReadBitResult
358 skip_bit
359
360 ;
361 ; shift mask right
362 ;
363 lsr CurrentMask
364
365 ;
366 ; next one
367 ;
368 dex
369 bne loop_read_bits
370
371 ;
372 ; restore regs
373 ;
374 pla
375 rts
376
377
378
379
380
381
382
383 _PlayerUnpackBlock
384 ;
385 ; Init loop
386 ;
387 lda #>_PlayerBuffer
388 sta _PlayerRegPointer
389
390 ldx #0
391 stx _PlayerRegister
392 player_unpack_block_loop
393 ;
394 ; Unpack that register
395 ;
396 jsr _PlayerUnpackRegister2
397
398 ;
399 ; Next register
400 ;
401 ldx _PlayerRegister
402 inx
403 stx _PlayerRegister
404 cpx #REGS
405 bne player_unpack_block_loop
406 rts
407
408
409
410
411 _PlayerUnpackRegister
412 lda #>_PlayerBuffer
413 clc
414 adc _PlayerRegister
415 sta _PlayerRegPointer
416 _PlayerUnpackRegister2
417 ;
418 ; Init register bit count and current value
419 ;
420 ldx _PlayerRegister
421 lda _PlayerRegValues,x
422 sta _PlayerRegCurrentValue
423
424
425 ;
426 ; Check if it's packed or not
427 ; and call adequate routine...
428 ;
429 ldx #1
430 jsr _ReadBits
431 ldx _ReadBitResult
432 bne _PlayerCopyPacked
433
434 ;
435 ; No change
436 ;
437 ;_PlayerCopyUnchanged
438 lda _PlayerVbl
439 sta player_copy_unchanged_write+1
440 lda _PlayerRegPointer ; highpart of buffer adress + register number
441 sta player_copy_unchanged_write+2
442
443 ldx #FRAG ; 128 iterations
444 lda _PlayerRegCurrentValue ; Value to write
445
446 player_copy_unchanged_loop
447 dex
448 player_copy_unchanged_write
449 sta _PlayerBuffer,x
450 bne player_copy_unchanged_loop
451
452 jmp player_main_return
453
454 player_main_return
455
456
457 ;
458 ; Write back register current value
459 ;
460 ldx _PlayerRegister
461 lda _PlayerRegCurrentValue
462 sta _PlayerRegValues,x
463
464 ;
465 ; Next register buffer
466 ;
467 inc _PlayerRegPointer
468 rts
469
470
471
472
473
474
475
476 _PlayerCopyPacked
477 lda _PlayerVbl ; either 0 or 128...
478 sta _PlayerVblRow
479
480 player_copy_packed_loop
481 ;
482 ; Check packing method
483 ;
484 ldx #1
485 jsr _ReadBits
486
487 ;
488 ; Call adequate method
489 ;
490 ldx _ReadBitResult
491 bne PlayerNotCopyLast
492
493 ;
494 ; Copy last value
495 ; PlayerCopyLast
496 ;
497 lda _PlayerRegPointer ; highpart of buffer adress + register number
498 sta player_copy_last+2
499
500 ldx _PlayerVblRow ; Value between 00 and 7f
501 lda _PlayerRegCurrentValue ; Value to copy
502 player_copy_last
503 sta _PlayerBuffer,x
504
505 inc _PlayerVblRow
506
507 player_return
508
509 ;
510 ; Check end of loop
511 ;
512 lda _PlayerVblRow
513 and #127
514 bne player_copy_packed_loop
515
516 jmp player_main_return
517
518
519 PlayerNotCopyLast
520 ;
521 ; Check packing method
522 ;
523 ldx #1
524 jsr _ReadBits
525
526 ;
527 ; Call adequate method
528 ;
529 ldx _ReadBitResult
530 beq PlayerCopyOffset
531
532 PlayerReadNew
533 ;
534 ; Read new register value (variable bit count)
535 ;
536 ldx _PlayerRegister
537 lda _PlayerRegBits,x
538 tax
539 jsr _ReadBits
540 ldx _ReadBitResult
541 stx _PlayerRegCurrentValue
542
543 ;
544 ; Copy to stream
545 ;
546 lda _PlayerRegPointer ; highpart of buffer adress + register number
547 sta player_read_new+2
548
549 ldx _PlayerVblRow ; Value between 00 and 7f
550 lda _PlayerRegCurrentValue ; New value to write
551 player_read_new
552 sta _PlayerBuffer,x
553
554 inc _PlayerVblRow
555 jmp player_return
556
557
558
559
560 PlayerCopyOffset
561 ldx #OFFHALF
562 jsr _ReadBits ; Read Offset (0 to 127)
563
564 lda _PlayerRegPointer ; highpart of buffer adress + register number
565 sta player_copy_offset_write+2 ; Write adress
566 sta player_copy_offset_read+2 ; Read adress
567
568 ;
569 ; Compute wrap around offset...
570 ;
571 lda _PlayerVblRow ; between 0 and 255
572 clc
573 adc _ReadBitResult ; + Offset Between 00 and 7f
574 sec
575 sbc #128 ; -128
576 tay
577
578 ;
579 ; Read count (7 bits)
580 ;
581 ldx #OFFHALF
582 jsr _ReadBits
583
584 inc _ReadBitResult ; 1 to 128
585
586 lda _ReadBitResult
587 clc
588 adc _PlayerVblRow
589 sta _PlayerUnpackCount
590
591
592 ldx _PlayerVblRow
593
594 player_copy_offset_loop
595
596 player_copy_offset_read
597 lda _PlayerBuffer,y ; Y for reading
598 iny
599
600 player_copy_offset_write
601 sta _PlayerBuffer,x ; X for writing
602
603 inc _PlayerVblRow
604
605 inx
606 cpx _PlayerUnpackCount
607 bne player_copy_offset_loop
608
609 sta _PlayerRegCurrentValue
610
611 jmp player_return
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632

  ViewVC Help
Powered by ViewVC 1.1.26