PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

634 line
12KB

  1. /////////////////////////////////
  2. //
  3. // FastLED6502
  4. // by Mark Kriegsman
  5. //
  6. // Device driver and animation
  7. // library for connecting addressable
  8. // LED strips to an Apple II.
  9. // The full "FastLED" library is
  10. // available for Arduino and related
  11. // microcontrollers.
  12. //
  13. /////////////////////////////////
  14. //
  15. // HOST COMPATIBILITY:
  16. // Apples with 16-pin DIP "game ports"
  17. // are fully supported; Apples with only
  18. // 9-pin "game ports" are NOT supported.
  19. //
  20. // Apple ][ fully supported
  21. // Apple ][+ fully supported
  22. // Apple //e fully supported
  23. //
  24. // Apple //c and //c+ NOT supported
  25. // as they lack the required 16-pin
  26. // DIP game port for digital I/O.
  27. //
  28. // Apple //gs:
  29. // motherboard game port IS supported
  30. // back panel connector NOT supported
  31. // See Notes section below.
  32. //
  33. // C64, PET, VIC-20, Atari400/800,
  34. // NES, SYM, KIM-1, and other 6502
  35. // systems are NOT supported at this
  36. // time, but porting should be
  37. // relatively easy for someone familiar
  38. // with each target platform.
  39. //
  40. //
  41. // LED STRIP COMPATIBILITY:
  42. // In general, "four-wire" (clocked)
  43. // LED strips can be supported, but
  44. // "three-wire" (clockless) LED strips
  45. // cannot be supported.
  46. //
  47. // APA102 tested & working
  48. // Adafruit DotStar tested & working
  49. // LPD8806 should work (untested)
  50. // WS2801 should work (untested)
  51. //
  52. // WS2811/WS2812/NeoPixel can NOT work
  53. // due to timing incompatibilities,
  54. // namely that the 1MHz Apple is far
  55. // too slow to drive them correctly.
  56. //
  57. //
  58. // USAGE - HARDWARE:
  59. // Connect an external power source to
  60. // +5 and GND on the LED strip.
  61. // Connect GND on the LED strip to GND
  62. // on the game port connector (pin 8)
  63. // Connect DATA IN on the LED strip to
  64. // pin 12, 13, or 14 on the game port.
  65. // Connect CLOCK IN on the LED strip to
  66. // pin 5 (preferred), 12, 13, or 14 on
  67. // the game port. Note: Apple //gs users
  68. // cannot use pin 5.
  69. //
  70. //
  71. // USAGE - SOFTWARE:
  72. // At build time provide definitions for
  73. // CHIPSET, DATA_PIN, CLOCK_PIN,
  74. // NUM_LEDS, & BRIGHTNESS.
  75. // Inside "Setup":
  76. // Store LED count into
  77. // FastLED_NumPixels,
  78. // Store brightness into
  79. // FastLED_Brightness
  80. // Inside "Loop":
  81. // Update the leds array, found in
  82. // ledsR, ledsG, and ledsB
  83. // Call FastLED_Show
  84. // Jump back to top of "Loop"
  85. //
  86. //
  87. // REFERENCE:
  88. // FastLED_Show:
  89. // display led array on LED strip
  90. // FastLED_FillBlack:
  91. // fill led array to black
  92. // FastLED_FillSolid_RGB_AXY:
  93. // fill led array with RGB color
  94. // FastLED_FillSolid_Hue_X:
  95. // fill led array with solid HSV Hue
  96. // FastLED_Random8:
  97. // return a pseudorandom number in A
  98. // FastLED_FillRainbow_XY:
  99. // fill led array with HSV rainbow
  100. // starting at hue X, incrementing by
  101. // huedelta Y each pixel.
  102. // FastLED_SetHue_XY:
  103. // set pixel Y to HSV hue X
  104. // FastLED_Beat8:
  105. // takes a speed increment in A, and
  106. // returns a triangle wave in A.
  107. //
  108. //
  109. // NOTES:
  110. // For speed and size, there IS some
  111. // self-modifying code in this
  112. // library, so it cannot be burned
  113. // into ROM without modification.
  114. // Brightness control only works on
  115. // APA102 at this point.
  116. // Pin 15 is currently used as a
  117. // 'frame start' signal for protocol
  118. // diagnostics - makes frames more
  119. // visible with an oscilloscope.
  120. // If Pin 5 is specified for the CLOCK
  121. // output pin, FastLED6502 will
  122. // automatically use the high speed
  123. // C040STROBE signal for clock. Note
  124. // that the Apple //gs lacks this
  125. // signal, even on the motherboard
  126. // game port.
  127. // The Apple joystick/mouse port on the
  128. // rear of the //c, //c+, and //gs
  129. // can NOT be used for LED connections
  130. // because it lacks the necessary
  131. // digital output pins.
  132. // This library can drive 100 LED pixels
  133. // at more than 30 frames per second.
  134. //
  135. //
  136. // VERSION HISTORY
  137. // 2015-02-07 - first version, by MEK
  138. // assembled with xa65
  139. // www.floodgap.com/retrotech/xa/
  140. /////////////////////////////////
  141. //
  142. // ENTRY POINT
  143. //
  144. FastLED_Entry
  145. jsr FastLED_FillBlack
  146. jmp Setup
  147. /////////////////////////////////
  148. //
  149. // FASTLED6502 GLOBALS
  150. //
  151. FastLED_NumPixels .byt NUM_LEDS
  152. FastLED_Brightness .byt BRIGHTNESS
  153. FastLED_RandomState .byt 17
  154. FastLED_BeatState .byt 0
  155. /////////////////////////////////
  156. //
  157. // API FUNCTIONS
  158. //
  159. FastLED_FillBlack
  160. lda FastLED_NumPixels
  161. pha
  162. lda #255
  163. sta FastLED_NumPixels
  164. lda #0
  165. tax
  166. tay
  167. jsr FastLED_FillSolid_RGB_AXY
  168. jsr FastLED_Show
  169. pla
  170. sta FastLED_NumPixels
  171. rts
  172. FastLED_FillRainbow_XY
  173. sty rbHueDelta
  174. ldy #0
  175. FR1
  176. lda FastLED_RainbowR,x
  177. sta ledsR,y
  178. lda FastLED_RainbowG,x
  179. sta ledsG,y
  180. lda FastLED_RainbowB,x
  181. sta ledsB,y
  182. txa
  183. clc
  184. adc rbHueDelta
  185. tax
  186. iny
  187. cpy FastLED_NumPixels
  188. bne FR1
  189. rts
  190. rbHueDelta .byt 0
  191. FastLED_SetHue_XY
  192. lda FastLED_RainbowR,x
  193. sta ledsR,y
  194. lda FastLED_RainbowG,x
  195. sta ledsG,y
  196. lda FastLED_RainbowB,x
  197. sta ledsB,y
  198. rts
  199. FastLED_FillSolid_RGB_AXY
  200. sta ledsR
  201. stx ledsG
  202. sty ledsB
  203. ldy #0
  204. FillSolidRGBAXY1
  205. lda ledsR
  206. sta ledsR,y
  207. lda ledsG
  208. sta ledsG,y
  209. lda ledsB
  210. sta ledsB,y
  211. iny
  212. cpy FastLED_NumPixels
  213. bne FillSolidRGBAXY1
  214. rts
  215. FastLED_FillSolid_Hue_X
  216. ldy #0
  217. FillSolidHX1
  218. lda FastLED_RainbowR,x
  219. sta ledsR,y
  220. lda FastLED_RainbowG,x
  221. sta ledsG,y
  222. lda FastLED_RainbowB,x
  223. sta ledsB,y
  224. iny
  225. cpy FastLED_NumPixels
  226. bne FillSolidHX1
  227. rts
  228. ; NOTE: USES SELF-MODIFYING CODE
  229. FastLED_Random8
  230. inc Random8GetLo
  231. bne Random8Get
  232. inc Random8GetHi
  233. bne Random8Get
  234. lda #$F8
  235. sta Random8GetHi
  236. lda #03
  237. sta Random8GetLo
  238. Random8Get
  239. Random8GetLo = Random8Get + 1
  240. Random8GetHi = Random8Get + 2
  241. lda $F803
  242. adc FastLED_RandomState
  243. sta FastLED_RandomState
  244. rts
  245. FastLED_Beat8
  246. clc
  247. adc FastLED_BeatState
  248. sta FastLED_BeatState
  249. bit FastLED_BeatState
  250. bmi FastLED_Beat8Neg
  251. asl
  252. rts
  253. FastLED_Beat8Neg
  254. lda #$ff
  255. sec
  256. sbc FastLED_BeatState
  257. sbc FastLED_BeatState
  258. rts
  259. FastLED_Show
  260. jmp CHIPSET
  261. /////////////////////////////////
  262. //
  263. // HARDWARE INTERFACING
  264. //
  265. PINOFF_BASE = PIN15OFF
  266. PINON_BASE = PIN15ON
  267. #define PINON(P) PINON_BASE+((15-P)*2)
  268. #define PINOFF(P) PINOFF_BASE+((15-P)*2)
  269. DATAOFF = PINOFF(DATA_PIN)
  270. DATAON = PINON(DATA_PIN)
  271. CLKOFF = PINOFF(CLOCK_PIN)
  272. CLKON = PINON(CLOCK_PIN)
  273. // Special handling if CLOCK_PIN
  274. // is 5: the C040STROBE line.
  275. #if CLOCK_PIN = 5
  276. #define CLOCK_ON bit PIN5STROBE
  277. #define CLOCK_OFF
  278. #else
  279. #define CLOCK_ON bit CLKON
  280. #define CLOCK_OFF bit CLKOFF
  281. #endif
  282. FRAMEON = PINON(15)
  283. FRAMEOFF = PINOFF(15)
  284. /////////////////////////////////
  285. APA102
  286. bit FRAMEON
  287. jsr FastLED_Send00
  288. jsr FastLED_Send00
  289. jsr FastLED_Send00
  290. jsr FastLED_Send00
  291. lda FastLED_Brightness
  292. lsr
  293. lsr
  294. lsr
  295. ora #$E0
  296. tax
  297. ldy FastLED_NumPixels
  298. APA102PX
  299. txa
  300. jsr FastLED_SendA
  301. lda ledsB,y
  302. jsr FastLED_SendA
  303. lda ledsG,y
  304. jsr FastLED_SendA
  305. lda ledsR,y
  306. jsr FastLED_SendA
  307. dey
  308. bne APA102PX
  309. lda FastLED_NumPixels
  310. lsr
  311. lsr
  312. lsr
  313. lsr
  314. lsr
  315. lsr
  316. tay
  317. iny
  318. APA102CL
  319. jsr FastLED_SendFF
  320. jsr FastLED_Send00
  321. jsr FastLED_Send00
  322. jsr FastLED_Send00
  323. dey
  324. bne APA102CL
  325. bit FRAMEOFF
  326. rts
  327. /////////////////////////////////
  328. LPD8806
  329. bit FRAMEON
  330. ldy FastLED_NumPixels
  331. LPD8806PX
  332. lda ledsG,y
  333. lsr
  334. ora #$80
  335. jsr FastLED_SendA
  336. lda ledsR,y
  337. lsr
  338. ora #$80
  339. jsr FastLED_SendA
  340. lda ledsB,y
  341. lsr
  342. ora #$80
  343. jsr FastLED_SendA
  344. dey
  345. bne LPD8806PX
  346. bit FRAMEOFF
  347. rts
  348. /////////////////////////////////
  349. WS2801
  350. bit FRAMEON
  351. ldy FastLED_NumPixels
  352. WS2801PX
  353. lda ledsG,y
  354. jsr FastLED_SendA
  355. lda ledsR,y
  356. jsr FastLED_SendA
  357. lda ledsB,y
  358. jsr FastLED_SendA
  359. dey
  360. bne WS2801PX
  361. bit FRAMEOFF
  362. rts
  363. /////////////////////////////////
  364. FastLED_SendFF
  365. bit DATAON
  366. jmp FastLED_SendXX
  367. ;
  368. FastLED_Send00
  369. bit DATAOFF
  370. ;
  371. FastLED_SendXX
  372. CLOCK_ON
  373. CLOCK_OFF
  374. CLOCK_ON
  375. CLOCK_OFF
  376. CLOCK_ON
  377. CLOCK_OFF
  378. CLOCK_ON
  379. CLOCK_OFF
  380. CLOCK_ON
  381. CLOCK_OFF
  382. CLOCK_ON
  383. CLOCK_OFF
  384. CLOCK_ON
  385. CLOCK_OFF
  386. CLOCK_ON
  387. CLOCK_OFF
  388. rts
  389. FastLED_SendA
  390. cmp #0
  391. beq FastLED_Send00
  392. cmp #$FF
  393. beq FastLED_SendFF
  394. asl
  395. bcc S0x0
  396. S0x1 bit DATAON
  397. bcs S0xK
  398. S0x0 bit DATAOFF
  399. S0xK CLOCK_ON
  400. CLOCK_OFF
  401. asl
  402. bcc S1x0
  403. S1x1 bit DATAON
  404. bcs S1xK
  405. S1x0 bit DATAOFF
  406. S1xK CLOCK_ON
  407. CLOCK_OFF
  408. asl
  409. bcc S2x0
  410. S2x1 bit DATAON
  411. bcs S2xK
  412. S2x0 bit DATAOFF
  413. S2xK CLOCK_ON
  414. CLOCK_OFF
  415. asl
  416. bcc S3x0
  417. S3x1 bit DATAON
  418. bcs S3xK
  419. S3x0 bit DATAOFF
  420. S3xK CLOCK_ON
  421. CLOCK_OFF
  422. asl
  423. bcc S4x0
  424. S4x1 bit DATAON
  425. bcs S4xK
  426. S4x0 bit DATAOFF
  427. S4xK CLOCK_ON
  428. CLOCK_OFF
  429. asl
  430. bcc S5x0
  431. S5x1 bit DATAON
  432. bcs S5xK
  433. S5x0 bit DATAOFF
  434. S5xK CLOCK_ON
  435. CLOCK_OFF
  436. asl
  437. bcc S6x0
  438. S6x1 bit DATAON
  439. bcs S6xK
  440. S6x0 bit DATAOFF
  441. S6xK CLOCK_ON
  442. CLOCK_OFF
  443. asl
  444. bcc S7x0
  445. S7x1 bit DATAON
  446. bcs S7xK
  447. S7x0 bit DATAOFF
  448. S7xK CLOCK_ON
  449. CLOCK_OFF
  450. rts
  451. /////////////////////////////////
  452. //
  453. // Force page allignment for speed
  454. // for leds array and Rainbow table
  455. //
  456. .dsb 256-(* & $FF),0
  457. /////////////////////////////////
  458. //
  459. // LED ARRAY
  460. //
  461. ledsR .dsb 256,0
  462. ledsG .dsb 256,0
  463. ledsB .dsb 256,0
  464. /////////////////////////////////
  465. //
  466. // HSV RAINBOW DEFINITION
  467. //
  468. // Generated directly from FastLED.
  469. //
  470. FastLED_RainbowR
  471. .byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
  472. .byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
  473. .byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
  474. .byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
  475. .byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
  476. .byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
  477. .byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
  478. .byt $AB,$AB,$AB,$AB,$AB,$AB,$AB,$AB
  479. .byt $AB,$A6,$A1,$9C,$96,$91,$8C,$86
  480. .byt $81,$7C,$76,$71,$6C,$66,$61,$5C
  481. .byt $56,$51,$4C,$47,$41,$3C,$37,$31
  482. .byt $2C,$27,$21,$1C,$17,$11,$0C,$07
  483. .byt $00,$00,$00,$00,$00,$00,$00,$00
  484. .byt $00,$00,$00,$00,$00,$00,$00,$00
  485. .byt $00,$00,$00,$00,$00,$00,$00,$00
  486. .byt $00,$00,$00,$00,$00,$00,$00,$00
  487. .byt $00,$00,$00,$00,$00,$00,$00,$00
  488. .byt $00,$00,$00,$00,$00,$00,$00,$00
  489. .byt $00,$00,$00,$00,$00,$00,$00,$00
  490. .byt $00,$00,$00,$00,$00,$00,$00,$00
  491. .byt $00,$02,$05,$07,$0A,$0D,$0F,$12
  492. .byt $15,$17,$1A,$1D,$1F,$22,$25,$27
  493. .byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
  494. .byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
  495. .byt $55,$57,$5A,$5C,$5F,$62,$64,$67
  496. .byt $6A,$6C,$6F,$72,$74,$77,$7A,$7C
  497. .byt $7F,$82,$84,$87,$8A,$8C,$8F,$92
  498. .byt $94,$97,$9A,$9C,$9F,$A2,$A4,$A7
  499. .byt $AB,$AD,$B0,$B2,$B5,$B8,$BA,$BD
  500. .byt $C0,$C2,$C5,$C8,$CA,$CD,$D0,$D2
  501. .byt $D5,$D8,$DA,$DD,$E0,$E2,$E5,$E8
  502. .byt $EA,$ED,$F0,$F2,$F5,$F8,$FA,$FD
  503. FastLED_RainbowG
  504. .byt $00,$02,$05,$07,$0A,$0D,$0F,$12
  505. .byt $15,$17,$1A,$1D,$1F,$22,$25,$27
  506. .byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
  507. .byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
  508. .byt $55,$57,$5A,$5C,$5F,$62,$64,$67
  509. .byt $6A,$6C,$6F,$72,$74,$77,$7A,$7C
  510. .byt $7F,$82,$84,$87,$8A,$8C,$8F,$92
  511. .byt $94,$97,$9A,$9C,$9F,$A2,$A4,$A7
  512. .byt $AB,$AD,$B0,$B2,$B5,$B8,$BA,$BD
  513. .byt $C0,$C2,$C5,$C8,$CA,$CD,$D0,$D2
  514. .byt $D5,$D8,$DA,$DD,$E0,$E2,$E5,$E8
  515. .byt $EA,$ED,$F0,$F2,$F5,$F8,$FA,$FD
  516. .byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
  517. .byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
  518. .byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
  519. .byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
  520. .byt $AB,$A6,$A1,$9C,$96,$91,$8C,$86
  521. .byt $81,$7C,$76,$71,$6C,$66,$61,$5C
  522. .byt $56,$51,$4C,$47,$41,$3C,$37,$31
  523. .byt $2C,$27,$21,$1C,$17,$11,$0C,$07
  524. .byt $00,$00,$00,$00,$00,$00,$00,$00
  525. .byt $00,$00,$00,$00,$00,$00,$00,$00
  526. .byt $00,$00,$00,$00,$00,$00,$00,$00
  527. .byt $00,$00,$00,$00,$00,$00,$00,$00
  528. .byt $00,$00,$00,$00,$00,$00,$00,$00
  529. .byt $00,$00,$00,$00,$00,$00,$00,$00
  530. .byt $00,$00,$00,$00,$00,$00,$00,$00
  531. .byt $00,$00,$00,$00,$00,$00,$00,$00
  532. .byt $00,$00,$00,$00,$00,$00,$00,$00
  533. .byt $00,$00,$00,$00,$00,$00,$00,$00
  534. .byt $00,$00,$00,$00,$00,$00,$00,$00
  535. .byt $00,$00,$00,$00,$00,$00,$00,$00
  536. FastLED_RainbowB
  537. .byt $00,$00,$00,$00,$00,$00,$00,$00
  538. .byt $00,$00,$00,$00,$00,$00,$00,$00
  539. .byt $00,$00,$00,$00,$00,$00,$00,$00
  540. .byt $00,$00,$00,$00,$00,$00,$00,$00
  541. .byt $00,$00,$00,$00,$00,$00,$00,$00
  542. .byt $00,$00,$00,$00,$00,$00,$00,$00
  543. .byt $00,$00,$00,$00,$00,$00,$00,$00
  544. .byt $00,$00,$00,$00,$00,$00,$00,$00
  545. .byt $00,$00,$00,$00,$00,$00,$00,$00
  546. .byt $00,$00,$00,$00,$00,$00,$00,$00
  547. .byt $00,$00,$00,$00,$00,$00,$00,$00
  548. .byt $00,$00,$00,$00,$00,$00,$00,$00
  549. .byt $00,$02,$05,$07,$0A,$0D,$0F,$12
  550. .byt $15,$17,$1A,$1D,$1F,$22,$25,$27
  551. .byt $2A,$2D,$2F,$32,$35,$37,$3A,$3D
  552. .byt $3F,$42,$45,$47,$4A,$4D,$4F,$52
  553. .byt $55,$5A,$5F,$64,$6A,$6F,$74,$7A
  554. .byt $7F,$84,$8A,$8F,$94,$9A,$9F,$A4
  555. .byt $AA,$AF,$B4,$B9,$BF,$C4,$C9,$CF
  556. .byt $D4,$D9,$DF,$E4,$E9,$EF,$F4,$F9
  557. .byt $FF,$FD,$FA,$F8,$F5,$F2,$F0,$ED
  558. .byt $EA,$E8,$E5,$E2,$E0,$DD,$DA,$D8
  559. .byt $D5,$D2,$D0,$CD,$CA,$C8,$C5,$C2
  560. .byt $C0,$BD,$BA,$B8,$B5,$B2,$B0,$AD
  561. .byt $AB,$A9,$A6,$A4,$A1,$9E,$9C,$99
  562. .byt $96,$94,$91,$8E,$8C,$89,$86,$84
  563. .byt $81,$7E,$7C,$79,$76,$74,$71,$6E
  564. .byt $6C,$69,$66,$64,$61,$5E,$5C,$59
  565. .byt $55,$53,$50,$4E,$4B,$48,$46,$43
  566. .byt $40,$3E,$3B,$38,$36,$33,$30,$2E
  567. .byt $2B,$28,$26,$23,$20,$1E,$1B,$18
  568. .byt $16,$13,$10,$0E,$0B,$08,$06,$03