Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FastLED6502.s65 « extras « FastLED-master « Библиотеки - github.com/AlexGyver/Arduino_Ambilight.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3d1a4fe68fe6bb12ff79e2a5a70adbb86dc51357 (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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/////////////////////////////////
//
//    FastLED6502
//    by Mark Kriegsman
//
// Device driver and animation 
// library for connecting addressable 
// LED strips to an Apple II.
// The full "FastLED" library is
// available for Arduino and related
// microcontrollers.
//
/////////////////////////////////
//
// HOST COMPATIBILITY:
// Apples with 16-pin DIP "game ports"
// are fully supported; Apples with only
// 9-pin "game ports" are NOT supported.
//
//   Apple ][ fully supported
//	 Apple ][+ fully supported
//	 Apple //e fully supported
//
//	 Apple //c and //c+ NOT supported
//    as they lack the required 16-pin
//    DIP game port for digital I/O.
//   
//	 Apple //gs: 
//    motherboard game port IS supported
//    back panel connector NOT supported
//    See Notes section below.
//
// C64, PET, VIC-20, Atari400/800, 
// NES, SYM, KIM-1, and other 6502
// systems are NOT supported at this
// time, but porting should be
// relatively easy for someone familiar
// with each target platform.
//
//
// LED STRIP COMPATIBILITY:
// In general, "four-wire" (clocked) 
// LED strips can be supported, but
// "three-wire" (clockless) LED strips
// cannot be supported.
//
//   APA102 tested & working
//	 Adafruit DotStar tested & working
//	 LPD8806 should work (untested)
//	 WS2801 should work (untested)
//
// WS2811/WS2812/NeoPixel can NOT work
// due to timing incompatibilities,
// namely that the 1MHz Apple is far
// too slow to drive them correctly.
//
//
// USAGE - HARDWARE:
// Connect an external power source to
// +5 and GND on the LED strip.
// Connect GND on the LED strip to GND
// on the game port connector (pin 8)
// Connect DATA IN on the LED strip to
// pin 12, 13, or 14 on the game port.
// Connect CLOCK IN on the LED strip to
// pin 5 (preferred), 12, 13, or 14 on
// the game port. Note: Apple //gs users
// cannot use pin 5.
//
//
// USAGE - SOFTWARE:
// At build time provide definitions for
//   CHIPSET, DATA_PIN, CLOCK_PIN,
//   NUM_LEDS, & BRIGHTNESS.
// Inside "Setup":
//	 Store LED count into
//     FastLED_NumPixels,
//	 Store brightness into
//     FastLED_Brightness
// Inside "Loop":
//	 Update the leds array, found in
//     ledsR, ledsG, and ledsB
//	 Call FastLED_Show
//   Jump back to top of "Loop"
//
//
// REFERENCE:
// FastLED_Show:
//   display led array on LED strip
// FastLED_FillBlack: 
//   fill led array to black
// FastLED_FillSolid_RGB_AXY: 
//   fill led array with RGB color
// FastLED_FillSolid_Hue_X: 
//   fill led array with solid HSV Hue
// FastLED_Random8: 
//   return a pseudorandom number in A
// FastLED_FillRainbow_XY:
//   fill led array with HSV rainbow
//   starting at hue X, incrementing by
//   huedelta Y each pixel.
// FastLED_SetHue_XY:
//   set pixel Y to HSV hue X
// FastLED_Beat8:
//   takes a speed increment in A, and
//   returns a triangle wave in A.
//
//
// NOTES:
// For speed and size, there IS some
//   self-modifying code in this
//   library, so it cannot be burned
//   into ROM without modification.
// Brightness control only works on
//   APA102 at this point.
// Pin 15 is currently used as a
//   'frame start' signal for protocol
//   diagnostics - makes frames more 
//   visible with an oscilloscope.
// If Pin 5 is specified for the CLOCK
//   output pin, FastLED6502 will
//   automatically use the high speed
//   C040STROBE signal for clock.  Note
//   that the Apple //gs lacks this
//   signal, even on the motherboard
//   game port.
// The Apple joystick/mouse port on the
//   rear of the //c, //c+, and //gs
//   can NOT be used for LED connections
//   because it lacks the necessary
//   digital output pins.
// This library can drive 100 LED pixels
//   at more than 30 frames per second.
//
//
// VERSION HISTORY
// 	2015-02-07 - first version, by MEK
//	  assembled with xa65
//      www.floodgap.com/retrotech/xa/


/////////////////////////////////
//
// ENTRY POINT
//

FastLED_Entry
		jsr FastLED_FillBlack
		jmp Setup


/////////////////////////////////
//
// FASTLED6502 GLOBALS
//

FastLED_NumPixels   	.byt NUM_LEDS
FastLED_Brightness 		.byt BRIGHTNESS

FastLED_RandomState		.byt 17
FastLED_BeatState		.byt 0


/////////////////////////////////
//
// API FUNCTIONS
//

FastLED_FillBlack
		lda FastLED_NumPixels
		pha
		lda #255
		sta FastLED_NumPixels
		lda #0
		tax
		tay
		jsr FastLED_FillSolid_RGB_AXY
		jsr FastLED_Show
		pla
		sta FastLED_NumPixels
		rts


FastLED_FillRainbow_XY
		sty rbHueDelta
		ldy #0
FR1
		lda FastLED_RainbowR,x
		sta ledsR,y
		lda FastLED_RainbowG,x
		sta ledsG,y
		lda FastLED_RainbowB,x
		sta ledsB,y
	
		txa
		clc
		adc rbHueDelta
		tax
	
		iny
		cpy FastLED_NumPixels
		bne FR1
		rts
	
rbHueDelta	.byt 0


FastLED_SetHue_XY
		lda FastLED_RainbowR,x
		sta ledsR,y
		lda FastLED_RainbowG,x
		sta ledsG,y
		lda FastLED_RainbowB,x
		sta ledsB,y
		rts		
	
	
FastLED_FillSolid_RGB_AXY
		sta ledsR
		stx ledsG
		sty ledsB
		ldy #0
FillSolidRGBAXY1
		lda ledsR
		sta ledsR,y
		lda ledsG
		sta ledsG,y
		lda ledsB
		sta ledsB,y
		iny
		cpy FastLED_NumPixels
		bne FillSolidRGBAXY1
		rts

FastLED_FillSolid_Hue_X
		ldy #0
FillSolidHX1
		lda FastLED_RainbowR,x
		sta ledsR,y
		lda FastLED_RainbowG,x
		sta ledsG,y
		lda FastLED_RainbowB,x
		sta ledsB,y
		iny
		cpy FastLED_NumPixels
		bne FillSolidHX1
		rts


; NOTE: USES SELF-MODIFYING CODE
FastLED_Random8
		inc Random8GetLo
		bne Random8Get
		inc Random8GetHi
		bne Random8Get
		lda #$F8
		sta Random8GetHi
		lda #03
		sta Random8GetLo
Random8Get 
Random8GetLo = Random8Get + 1
Random8GetHi = Random8Get + 2
		lda $F803
		adc FastLED_RandomState
		sta FastLED_RandomState
		rts


FastLED_Beat8
		clc
		adc FastLED_BeatState
		sta FastLED_BeatState
		bit FastLED_BeatState
		bmi FastLED_Beat8Neg
		asl
		rts		
FastLED_Beat8Neg
		lda #$ff
		sec
		sbc FastLED_BeatState
		sbc FastLED_BeatState
		rts


FastLED_Show
		jmp CHIPSET

		
/////////////////////////////////
//
// HARDWARE INTERFACING
//

PINOFF_BASE	=	PIN15OFF
PINON_BASE	=	PIN15ON

#define PINON(P) PINON_BASE+((15-P)*2)
#define PINOFF(P) PINOFF_BASE+((15-P)*2)

DATAOFF = PINOFF(DATA_PIN)
DATAON  = PINON(DATA_PIN)
CLKOFF  = PINOFF(CLOCK_PIN)
CLKON   = PINON(CLOCK_PIN)

// Special handling if CLOCK_PIN
// is 5: the C040STROBE line.
#if CLOCK_PIN = 5
#define CLOCK_ON 	bit PIN5STROBE
#define CLOCK_OFF
#else
#define CLOCK_ON 	bit CLKON
#define CLOCK_OFF	bit CLKOFF
#endif

FRAMEON		= PINON(15)
FRAMEOFF	= PINOFF(15)

/////////////////////////////////
APA102
		bit FRAMEON
		jsr FastLED_Send00
		jsr FastLED_Send00
		jsr FastLED_Send00
		jsr FastLED_Send00

		lda FastLED_Brightness
		lsr
		lsr
		lsr
		ora #$E0
		tax
	
		ldy FastLED_NumPixels
APA102PX	
		txa
		jsr FastLED_SendA
		lda ledsB,y
		jsr FastLED_SendA
		lda ledsG,y
		jsr FastLED_SendA
		lda ledsR,y
		jsr FastLED_SendA
		dey
		bne APA102PX

		lda FastLED_NumPixels
		lsr
		lsr
		lsr
		lsr
		lsr
		lsr
		tay
		iny
APA102CL
		jsr FastLED_SendFF
		jsr FastLED_Send00
		jsr FastLED_Send00
		jsr FastLED_Send00
		dey
		bne APA102CL
		bit FRAMEOFF
		rts

/////////////////////////////////
LPD8806
		bit FRAMEON
		ldy FastLED_NumPixels
LPD8806PX	
		lda ledsG,y
		lsr
		ora #$80
		jsr FastLED_SendA
		lda ledsR,y
		lsr
		ora #$80
		jsr FastLED_SendA
		lda ledsB,y
		lsr
		ora #$80
		jsr FastLED_SendA
		dey
		bne LPD8806PX

		bit FRAMEOFF
		rts


/////////////////////////////////
WS2801
		bit FRAMEON
		ldy FastLED_NumPixels
WS2801PX	
		lda ledsG,y
		jsr FastLED_SendA
		lda ledsR,y
		jsr FastLED_SendA
		lda ledsB,y
		jsr FastLED_SendA
		dey
		bne WS2801PX

		bit FRAMEOFF
		rts


/////////////////////////////////
FastLED_SendFF
		bit DATAON
		jmp FastLED_SendXX
		;
FastLED_Send00
		bit DATAOFF	
		;
FastLED_SendXX
		CLOCK_ON
		CLOCK_OFF
		CLOCK_ON
		CLOCK_OFF
	
		CLOCK_ON
		CLOCK_OFF
		CLOCK_ON
		CLOCK_OFF
	
		CLOCK_ON
		CLOCK_OFF
		CLOCK_ON
		CLOCK_OFF
	
		CLOCK_ON
		CLOCK_OFF
		CLOCK_ON
		CLOCK_OFF
	
		rts

FastLED_SendA	
		cmp #0
		beq FastLED_Send00
		cmp #$FF
		beq FastLED_SendFF

		asl
		bcc S0x0
S0x1	bit DATAON
		bcs S0xK
S0x0    bit DATAOFF
S0xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S1x0
S1x1	bit DATAON
		bcs S1xK
S1x0    bit DATAOFF
S1xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S2x0
S2x1	bit DATAON
		bcs S2xK
S2x0    bit DATAOFF
S2xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S3x0
S3x1	bit DATAON
		bcs S3xK
S3x0    bit DATAOFF
S3xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S4x0
S4x1	bit DATAON
		bcs S4xK
S4x0    bit DATAOFF
S4xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S5x0
S5x1	bit DATAON
		bcs S5xK
S5x0    bit DATAOFF
S5xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S6x0
S6x1	bit DATAON
		bcs S6xK
S6x0    bit DATAOFF
S6xK	CLOCK_ON
		CLOCK_OFF

		asl
		bcc S7x0
S7x1	bit DATAON
		bcs S7xK
S7x0    bit DATAOFF
S7xK	CLOCK_ON
		CLOCK_OFF

		rts


/////////////////////////////////
//
// Force page allignment for speed
// for leds array and Rainbow table
//
		.dsb 256-(* & $FF),0


/////////////////////////////////
//
// LED ARRAY
//

ledsR	.dsb 256,0 
ledsG	.dsb 256,0
ledsB	.dsb 256,0
		
/////////////////////////////////
//
// HSV RAINBOW DEFINITION
//
// Generated directly from FastLED.
//

FastLED_RainbowR
	.byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
	.byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
	.byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
	.byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
	.byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
	.byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
	.byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
	.byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
	.byt $AB,$A6,$A1,$9C,$96,$91,$8C,$86
	.byt $81,$7C,$76,$71,$6C,$66,$61,$5C
	.byt $56,$51,$4C,$47,$41,$3C,$37,$31
	.byt $2C,$27,$21,$1C,$17,$11,$0C,$07
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$02,$05,$07,$0A,$0D,$0F,$12
	.byt $15,$17,$1A,$1D,$1F,$22,$25,$27
	.byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
	.byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
	.byt $55,$57,$5A,$5C,$5F,$62,$64,$67
	.byt $6A,$6C,$6F,$72,$74,$77,$7A,$7C
	.byt $7F,$82,$84,$87,$8A,$8C,$8F,$92
	.byt $94,$97,$9A,$9C,$9F,$A2,$A4,$A7
	.byt $AB,$AD,$B0,$B2,$B5,$B8,$BA,$BD
	.byt $C0,$C2,$C5,$C8,$CA,$CD,$D0,$D2
	.byt $D5,$D8,$DA,$DD,$E0,$E2,$E5,$E8
	.byt $EA,$ED,$F0,$F2,$F5,$F8,$FA,$FD
FastLED_RainbowG
	.byt $00,$02,$05,$07,$0A,$0D,$0F,$12
	.byt $15,$17,$1A,$1D,$1F,$22,$25,$27
	.byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
	.byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
	.byt $55,$57,$5A,$5C,$5F,$62,$64,$67
	.byt $6A,$6C,$6F,$72,$74,$77,$7A,$7C
	.byt $7F,$82,$84,$87,$8A,$8C,$8F,$92
	.byt $94,$97,$9A,$9C,$9F,$A2,$A4,$A7
	.byt $AB,$AD,$B0,$B2,$B5,$B8,$BA,$BD
	.byt $C0,$C2,$C5,$C8,$CA,$CD,$D0,$D2
	.byt $D5,$D8,$DA,$DD,$E0,$E2,$E5,$E8
	.byt $EA,$ED,$F0,$F2,$F5,$F8,$FA,$FD
	.byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
	.byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
	.byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
	.byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
	.byt $AB,$A6,$A1,$9C,$96,$91,$8C,$86
	.byt $81,$7C,$76,$71,$6C,$66,$61,$5C
	.byt $56,$51,$4C,$47,$41,$3C,$37,$31
	.byt $2C,$27,$21,$1C,$17,$11,$0C,$07
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
FastLED_RainbowB
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$00,$00,$00,$00,$00,$00,$00
	.byt $00,$02,$05,$07,$0A,$0D,$0F,$12
	.byt $15,$17,$1A,$1D,$1F,$22,$25,$27
	.byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
	.byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
	.byt $55,$5A,$5F,$64,$6A,$6F,$74,$7A
	.byt $7F,$84,$8A,$8F,$94,$9A,$9F,$A4
	.byt $AA,$AF,$B4,$B9,$BF,$C4,$C9,$CF
	.byt $D4,$D9,$DF,$E4,$E9,$EF,$F4,$F9
	.byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
	.byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
	.byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
	.byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
	.byt $AB,$A9,$A6,$A4,$A1,$9E,$9C,$99
	.byt $96,$94,$91,$8E,$8C,$89,$86,$84
	.byt $81,$7E,$7C,$79,$76,$74,$71,$6E
	.byt $6C,$69,$66,$64,$61,$5E,$5C,$59
	.byt $55,$53,$50,$4E,$4B,$48,$46,$43
	.byt $40,$3E,$3B,$38,$36,$33,$30,$2E
	.byt $2B,$28,$26,$23,$20,$1E,$1B,$18
	.byt $16,$13,$10,$0E,$0B,$08,$06,$03