Coding a plasma effect demo on the Commodore 64 (tutorial DIY)
ฝัง
- เผยแพร่เมื่อ 28 ก.ย. 2024
- In this video, I'm trying to show you how to program a plasma demo effect in assembly and machine language on the Commodore 64.
#c64
#plasma
#6502
#commodore64
Dont forget to look at 4mat's very short but brilliant routines:
• Various plasma effects...
Music: The Alan Parsons Project - Eye in the Sky (Official Audio)
• The Alan Parsons Proje...
The code is here
PART1
* = $1000
LDA #0 ; black everywhere :)
STA $D021 ; =53281
STA $D020 ; =53280
START
; first step is to create a table with sine + cosine values
; The addition is performed on a proportionate basis
; the table is changed on every frame
LDX #64 ; 25 rows (+40 additional values)
loop
LDA sin,X
addpart
ADC cos,X ; Y can be used as index
; insofar as it's decremented
STA sinecosine,x ; new table
DEX
BPL loop
; values in sine + cos table are changed
INC loop+1 ; after each frame
DEC addpart+1
; the first 40 succesive values represent a value
; for each of the 40 columns
; The 25 following successive values represent the 25 rows
; Once the sine + cos table with the 65 values is created
; The code adds and combines them giving 1,000 different values
; values 0-39 in the table : column
; values 40-64 in the table : row
; the routine deals each column, line by line
LDX #39
PLOT
LDA sinecosine,x
;LSR
STA $10 ; address $10 in memory will be used
; to store the value used
; for each column
; row/line 0
ADC sinecosine+40 ; value for row/line 0
TAY
LDA charcode,y ; load the charcode from a table
STA $0400,x ; read and indexed with Y
; and store it in the screen memory
LDA colorcode,y ; same thing about color memory
STA $d800,x ; operation is repeated every
; 25 screen rows/lines
; row/line 1
LDA $10
ADC sinecosine+41
TAY
LDA charcode,y ; load the charcode from a table
; read and indexed with Y
STA $0400+40,x ; and store it in the screen memory
LDA colorcode,y ; same thing about color memory
STA $d800+40,x
; row/line 2
LDA $10
ADC sinecosine+42
TAY
LDA charcode,y
STA $0400+80,x
LDA colorcode,y
STA $d800+80,x
; row/line 3
LDA $10
ADC sinecosine+43
TAY
LDA charcode,y
STA $0400+120,x
LDA colorcode,y
STA $d800+120,x
; row/line 4
LDA $10
ADC sinecosine+44
TAY
LDA charcode,y
STA $0400+160,x
LDA colorcode,y
STA $d800+160,x
; row/line 5
LDA $10
ADC sinecosine+45
TAY
LDA charcode,y
STA $0400+200,x
LDA colorcode,y
STA $d800+200,x
; row/line 6
LDA $10
ADC sinecosine+46
TAY
LDA charcode,y
STA $0400+240,x
LDA colorcode,y
STA $d800+240,x
; row/line 7
LDA $10
ADC sinecosine+47
TAY
LDA charcode,y
STA $0400+280,x
LDA colorcode,y
STA $d800+280,x
; row/line 8
LDA $10
ADC sinecosine+48
TAY
LDA charcode,y
STA $0400+320,x
LDA colorcode,y
STA $d800+320,x
;row/line 9
LDA $10
ADC sinecosine+49
TAY
LDA charcode,y
STA $0400+360,x
LDA colorcode,y
STA $d800+360,x
;row/line 10
LDA $10
ADC sinecosine+50
TAY
LDA charcode,y
STA $0400+400,x
LDA colorcode,y
STA $d800+400,x
;row/line 11
LDA $10
ADC sinecosine+51
TAY
LDA charcode,y
STA $0400+440,x
LDA colorcode,y
STA $d800+440,x
;row/line 12
LDA $10
ADC sinecosine+52
TAY
LDA charcode,y
STA $0400+480,x
LDA colorcode,y
STA $d800+480,x
;row/line 13
LDA $10
ADC sinecosine+53
TAY
LDA charcode,y
STA $0400+520,x
LDA colorcode,y
STA $d800+520,x
;row/line 14
LDA $10
ADC sinecosine+54
TAY
LDA charcode,y
STA $0400+560,x
LDA colorcode,y
STA $d800+560,x
;row/line 15
LDA $10
ADC sinecosine+55
TAY
LDA charcode,y
STA $0400+600,x
LDA colorcode,y
STA $d800+600,x
;row/line 16
LDA $10
ADC sinecosine+56
TAY
LDA charcode,y
STA $0400+640,x
LDA colorcode,y
STA $d800+640,x
;row/line 17
LDA $10
ADC sinecosine+57
TAY
LDA charcode,y
STA $0400+680,x
LDA colorcode,y
STA $d800+680,x
;row/line 18
LDA $10
ADC sinecosine+58
TAY
LDA charcode,y
STA $0400+720,x
LDA colorcode,y
STA $d800+720,x
;row/line 19
LDA $10
ADC sinecosine+59
TAY
LDA charcode,y
STA $0400+760,x
LDA colorcode,y
STA $d800+760,x
;row/line 20
LDA $10
ADC sinecosine+60
TAY
LDA charcode,y
STA $0400+800,x
LDA colorcode,y
STA $d800+800,x
;row/line 21
LDA $10
ADC sinecosine+61
TAY
LDA charcode,y
STA $0400+840,x
LDA colorcode,y
STA $d800+840,x
;row/line 22
LDA $10
ADC sinecosine+62
TAY
LDA charcode,y
STA $0400+880,x
LDA colorcode,y
STA $d800+880,x
;row/line 23
LDA $10
ADC sinecosine+63
TAY
LDA charcode,y
STA $0400+920,x
LDA colorcode,y
STA $d800+920,x
;row/line 24
LDA $10
ADC sinecosine+64
TAY
LDA charcode,y
STA $0400+960,x
LDA colorcode,y
STA $d800+960,x
DEX
BMI loop_exit
JMP PLOT
loop_exit
LDY #50
@exit
DEX
BNE @exit
@exit2
DEY
BNE @exit
JMP START
ALIGN ; here the code is aligned
; so that the LB adress is at $00
charcode
DCB 16,195 ;
DCB 16,196 ; number of bytes used will determine
DCB 16,197 ; the thickness of the layers pattern
DCB 16,198 ;
DCB 16,195
DCB 16,196
DCB 16,197
DCB 16,198
DCB 16,195
DCB 16,196
DCB 16,197
DCB 16,198
DCB 16,195
DCB 16,196
DCB 16,197
DCB 16,198
ALIGN ; here the code is aligned
; so that the LB adress is at $00
colorcode
DCB 16,00
DCB 16,11
DCB 16,12
DCB 16,15
DCB 16,00
DCB 16,11
DCB 16,12
DCB 16,15
DCB 16,00
DCB 16,11
DCB 16,12
DCB 16,15
DCB 16,00
DCB 16,11
DCB 16,12
DCB 16,15
PART 2
ALIGN ; "sin 2*256" table is comprised of 512 bytes
; with values between 0 and 63
; they are based on frequency by 4 x 90 degrees
; (=2*pi, ie a full circle)
sin
BYTE 32,28,24,20,16,13,10,7,5,3,1,0,0,0,0,1
BYTE 2,4,6,9,11,15,18,22,26,30,33,37,41,45,48,52
BYTE 54,57,59,61,62,63,63,63,63,62,60,58,56,53,50,47
BYTE 43,39,35,32,28,24,20,16,13,10,7,5,3,1,0,0
BYTE 0,0,1,2,4,6,9,11,15,18,22,26,30,33,37,41
BYTE 45,48,52,54,57,59,61,62,63,63,63,63,62,60,58,56
BYTE 53,50,47,43,39,35,32,28,24,20,16,13,10,7,5,3
BYTE 1,0,0,0,0,1,2,4,6,9,11,15,18,22,26,30
BYTE 33,37,41,45,48,52,54,57,59,61,62,63,63,63,63,62
BYTE 60,58,56,53,50,47,43,39,35,32,28,24,20,16,13,10
BYTE 7,5,3,1,0,0,0,0,1,2,4,6,9,11,15,18
BYTE 22,26,30,33,37,41,45,48,52,54,57,59,61,62,63,63
BYTE 63,63,62,60,58,56,53,50,47,43,39,35,32,28,24,20
BYTE 16,13,10,7,5,3,1,0,0,0,0,1,2,4,6,9
BYTE 11,15,18,22,26,30,33,37,41,45,48,52,54,57,59,61
BYTE 62,63,63,63,63,62,60,58,56,53,50,47,43,39,35,32
BYTE 32,28,24,20,16,13,10,7,5,3,1,0,0,0,0,1
BYTE 2,4,6,9,11,15,18,22,26,30,33,37,41,45,48,52
BYTE 54,57,59,61,62,63,63,63,63,62,60,58,56,53,50,47
BYTE 43,39,35,32,28,24,20,16,13,10,7,5,3,1,0,0
BYTE 0,0,1,2,4,6,9,11,15,18,22,26,30,33,37,41
BYTE 45,48,52,54,57,59,61,62,63,63,63,63,62,60,58,56
BYTE 53,50,47,43,39,35,32,28,24,20,16,13,10,7,5,3
BYTE 1,0,0,0,0,1,2,4,6,9,11,15,18,22,26,30
BYTE 33,37,41,45,48,52,54,57,59,61,62,63,63,63,63,62
BYTE 60,58,56,53,50,47,43,39,35,32,28,24,20,16,13,10
BYTE 7,5,3,1,0,0,0,0,1,2,4,6,9,11,15,18
BYTE 22,26,30,33,37,41,45,48,52,54,57,59,61,62,63,63
BYTE 63,63,62,60,58,56,53,50,47,43,39,35,32,28,24,20
BYTE 16,13,10,7,5,3,1,0,0,0,0,1,2,4,6,9
BYTE 11,15,18,22,26,30,33,37,41,45,48,52,54,57,59,61
BYTE 62,63,63,63,63,62,60,58,56,53,50,47,43,39,35,32
ALIGN ; "cos 2*256" frequency 6 x 90 degrees (=2,5*pi)
cos
BYTE 0,0,1,4,7,11,15,20,25,31,36,42,47,51,55,59
BYTE 61,63,63,63,62,60,57,53,49,44,39,33,28,22,17,13
BYTE 8,5,2,0,0,0,1,3,5,9,13,18,23,29,34,39
BYTE 45,50,54,57,60,62,63,63,63,61,58,55,51,46,41,36
BYTE 30,25,19,14,10,6,3,1,0,0,0,2,4,7,11,16
BYTE 21,26,32,37,43,47,52,56,59,61,63,63,63,62,60,56
BYTE 53,48,43,38,32,27,22,17,12,8,5,2,0,0,0,1
BYTE 3,6,10,14,19,24,29,35,40,45,50,54,58,61,62,63
BYTE 63,62,61,58,54,50,45,40,35,29,24,19,14,10,6,3
BYTE 1,0,0,0,2,5,8,12,17,22,27,32,38,43,48,53
BYTE 56,60,62,63,63,63,61,59,56,52,48,43,37,32,26,21
BYTE 16,11,7,4,2,0,0,0,1,3,6,10,14,19,25,30
BYTE 36,41,46,51,55,58,61,63,63,63,62,60,57,54,50,45
BYTE 39,34,29,23,18,13,9,5,3,1,0,0,0,2,5,8
BYTE 13,17,22,28,33,39,44,49,53,57,60,62,63,63,63,61
BYTE 59,55,51,47,42,36,31,25,20,15,11,7,4,1,0,0
BYTE 0,0,1,4,7,11,15,20,25,31,36,42,47,51,55,59
BYTE 61,63,63,63,62,60,57,53,49,44,39,33,28,22,17,13
BYTE 8,5,2,0,0,0,1,3,5,9,13,18,23,29,34,39
BYTE 45,50,54,57,60,62,63,63,63,61,58,55,51,46,41,36
BYTE 30,25,19,14,10,6,3,1,0,0,0,2,4,7,11,16
BYTE 21,26,32,37,43,47,52,56,59,61,63,63,63,62,60,56
BYTE 53,48,43,38,32,27,22,17,12,8,5,2,0,0,0,1
BYTE 3,6,10,14,19,24,29,35,40,45,50,54,58,61,62,63
BYTE 63,62,61,58,54,50,45,40,35,29,24,19,14,10,6,3
BYTE 1,0,0,0,2,5,8,12,17,22,27,32,38,43,48,53
BYTE 56,60,62,63,63,63,61,59,56,52,48,43,37,32,26,21
BYTE 16,11,7,4,2,0,0,0,1,3,6,10,14,19,25,30
BYTE 36,41,46,51,55,58,61,63,63,63,62,60,57,54,50,45
BYTE 39,34,29,23,18,13,9,5,3,1,0,0,0,2,5,8
BYTE 13,17,22,28,33,39,44,49,53,57,60,62,63,63,63,61
BYTE 59,55,51,47,42,36,31,25,20,15,11,7,4,1,0,0
ALIGN
sinecosine
BYTE 65,0 ; max value in sinecosine is 63+63=126 (x 2 =252)
@@Commodoreretro-programming 🙏 Thank you!! You have my sub.
Great video. Thank you very much!
Nice example how to properly self modify code. :)
After cofing on C64 I thought that self modifying code is normal thing. When I started with PC, I was surprised that people don't use such tricks.
Anyway, I would like to see how people do video playback on C64.
Thank you for this video, it was a pleasure for me to change the datas (charcode & colorcode) for fun. Here's my example:
charcode
DCB 8, $ef
DCB 8, $d2
DCB 8, $c6
DCB 8, $c0
DCB 8, $C3
DCB 8, $C4
DCB 8, $C5
DCB 8, $f7
DCB 8, $ef
DCB 8, $d2
DCB 8, $c6
DCB 8, $c0
DCB 8, $C3
DCB 8, $C4
DCB 8, $C5
DCB 8, $f7
DCB 8, $ef
DCB 8, $d2
DCB 8, $c6
DCB 8, $c0
DCB 8, $C3
DCB 8, $C4
DCB 8, $C5
DCB 8, $f7
DCB 8, $ef
DCB 8, $d2
DCB 8, $c6
DCB 8, $c0
DCB 8, $C3
DCB 8, $C4
DCB 8, $C5
DCB 8, $f7
colorcode
DCB 8,$09
DCB 8,$08
DCB 8,$07
DCB 8,$01
DCB 8,$01
DCB 8,$07
DCB 8,$08
DCB 8,$09
DCB 8,$09
DCB 8,$08
DCB 8,$07
DCB 8,$01
DCB 8,$01
DCB 8,$07
DCB 8,$08
DCB 8,$09
DCB 8,$09
DCB 8,$08
DCB 8,$07
DCB 8,$01
DCB 8,$01
DCB 8,$07
DCB 8,$08
DCB 8,$09
DCB 8,$09
DCB 8,$08
DCB 8,$07
DCB 8,$01
DCB 8,$01
DCB 8,$07
DCB 8,$08
DCB 8,$09
And you ? Share your proposal here...
Merci pour l'explication détaillée, la démarche pour obtenir l'effet est très claire :)
thanks for the info. It all makes sense now when i see 1k demo
Thanks for making the video and going thru it in detail.