base:8x8-plasma-effect-switch
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:8x8-plasma-effect-switch [2015-04-17 04:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 8x8 Plasma / Speedcode / Effect Switching ====== | ||
+ | |||
+ | < | ||
+ | // | ||
+ | // 8x8 Plasma Crap w/ Runtime Generated Speedcode + Effect Switching | ||
+ | // For Codebase64 | ||
+ | // By Cruzer/CML 2009 | ||
+ | // Asm: KickAss 3.1 | ||
+ | // | ||
+ | // memory... | ||
+ | .var plasmaCnt = $02 | ||
+ | .var add = $04 | ||
+ | .var codePnt = $05 | ||
+ | .var xPos = $07 | ||
+ | .var yPos = $08 | ||
+ | .var screen = $0400 | ||
+ | .var basic = $0801 | ||
+ | .var sine64 = $1000 | ||
+ | .var sine128 = $1200 | ||
+ | .var colorTable = $1400 | ||
+ | .var bitmap = $2000 | ||
+ | .var code = $4000 | ||
+ | .var plasmer = $5000 | ||
+ | // | ||
+ | .pc = sine64 " | ||
+ | .for (var i=0; i<$200; i++) | ||
+ | .by 32 + 32 * sin(i/ | ||
+ | .pc = sine128 " | ||
+ | .for (var i=0; i<$200; i++) | ||
+ | .by 64 + 64 * sin(i/ | ||
+ | // | ||
+ | .pc = $0801 " | ||
+ | : | ||
+ | // | ||
+ | .pc = code " | ||
+ | jmp start | ||
+ | // | ||
+ | .var width = 40 | ||
+ | .var height = 25 | ||
+ | // | ||
+ | plasmaParams: | ||
+ | sineSpreadX: | ||
+ | sineSpreadY: | ||
+ | colorSpreadX: | ||
+ | colorSpreadY: | ||
+ | realtimeSpread0: | ||
+ | realtimeSpread1: | ||
+ | sineSpeeds: | ||
+ | addSpeed: | ||
+ | colors: | ||
+ | |||
+ | .var paramLen = * - plasmaParams | ||
+ | |||
+ | //List of effects to switch between... | ||
+ | paramList: | ||
+ | |||
+ | !sineSpreadX: | ||
+ | !sineSpreadY: | ||
+ | !colorSpreadX: | ||
+ | !colorSpreadY: | ||
+ | !realtimeSpread0: | ||
+ | !realtimeSpread1: | ||
+ | !sineSpeeds: | ||
+ | !addSpeed: | ||
+ | !colors: | ||
+ | |||
+ | !sineSpreadX: | ||
+ | !sineSpreadY: | ||
+ | !colorSpreadX: | ||
+ | !colorSpreadY: | ||
+ | !realtimeSpread0: | ||
+ | !realtimeSpread1: | ||
+ | !sineSpeeds: | ||
+ | !addSpeed: | ||
+ | !colors: | ||
+ | |||
+ | !sineSpreadX: | ||
+ | !sineSpreadY: | ||
+ | !colorSpreadX: | ||
+ | !colorSpreadY: | ||
+ | !realtimeSpread0: | ||
+ | !realtimeSpread1: | ||
+ | !sineSpeeds: | ||
+ | !addSpeed: | ||
+ | !colors: | ||
+ | |||
+ | .var numFx = [* - paramList] | ||
+ | // | ||
+ | start: | ||
+ | jsr init | ||
+ | // | ||
+ | mainLoop: | ||
+ | lda #$00 | ||
+ | sta $d020 | ||
+ | lda #$44 | ||
+ | !: cmp $d012 | ||
+ | bne !- | ||
+ | |||
+ | lda plasmaCnt+0 | ||
+ | clc | ||
+ | adc sineSpeeds+0 | ||
+ | sta plasmaCnt+0 | ||
+ | lda plasmaCnt+1 | ||
+ | clc | ||
+ | adc sineSpeeds+1 | ||
+ | sta plasmaCnt+1 | ||
+ | lda add | ||
+ | clc | ||
+ | adc addSpeed | ||
+ | anc #$3f | ||
+ | sta add | ||
+ | |||
+ | jsr plasmer | ||
+ | jsr fxControl | ||
+ | jmp mainLoop | ||
+ | |||
+ | // | ||
+ | fxControl: | ||
+ | //count down to next effect | ||
+ | inc fxTimer | ||
+ | lda fxTimer | ||
+ | cmp #$70 | ||
+ | beq !next+ | ||
+ | rts | ||
+ | !next: | ||
+ | lda #$2b //turn off screen while initing effect | ||
+ | sta $d011 | ||
+ | lda #$00 | ||
+ | sta fxTimer | ||
+ | ldx effect | ||
+ | inx | ||
+ | cpx #numFx | ||
+ | bne !+ | ||
+ | ldx #0 | ||
+ | !: stx effect | ||
+ | |||
+ | jsr fetchParams | ||
+ | jsr generateSpeedcode | ||
+ | jsr generateColorTable | ||
+ | |||
+ | lda #$42 | ||
+ | !: cmp $d012 | ||
+ | bne !- | ||
+ | lda # | ||
+ | sta $d011 | ||
+ | |||
+ | rts | ||
+ | fxTimer: | ||
+ | .by 0 | ||
+ | effect: | ||
+ | .by 0 | ||
+ | mulParamLen: | ||
+ | .fill numFx, paramLen*i | ||
+ | // | ||
+ | fetchParams: | ||
+ | ldx effect | ||
+ | ldy mulParamLen, | ||
+ | ldx #0 | ||
+ | !: lda paramList,y | ||
+ | sta plasmaParams, | ||
+ | iny | ||
+ | inx | ||
+ | cpx #paramLen | ||
+ | bne !- | ||
+ | rts | ||
+ | // | ||
+ | init: | ||
+ | sei | ||
+ | jsr fetchParams | ||
+ | jsr generateSpeedcode | ||
+ | jsr generateColorTable | ||
+ | jsr fillBitmap | ||
+ | jsr initVic | ||
+ | rts | ||
+ | // | ||
+ | fillBitmap: | ||
+ | ldx #0 | ||
+ | ldy #$1f | ||
+ | |||
+ | lda #%01010101 | ||
+ | !: sta bitmap,x | ||
+ | eor #%11111111 | ||
+ | inx | ||
+ | bne !- | ||
+ | inc !- +2 | ||
+ | dey | ||
+ | bpl !- | ||
+ | rts | ||
+ | // | ||
+ | initVic: | ||
+ | lda #$3b | ||
+ | sta $d011 | ||
+ | lda #$18 | ||
+ | sta $d018 | ||
+ | rts | ||
+ | // | ||
+ | generateColorTable: | ||
+ | |||
+ | ldx #0 | ||
+ | !loop: | ||
+ | txa | ||
+ | asl | ||
+ | asl | ||
+ | asl | ||
+ | bcc !+ | ||
+ | eor #$ff | ||
+ | !: lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | tay | ||
+ | lda colors,y | ||
+ | sta colorTable, | ||
+ | sta colorTable+$100, | ||
+ | inx | ||
+ | bne !loop- | ||
+ | rts | ||
+ | // | ||
+ | // Generates the plasmer speedcode by modifying and copying two different chunks of code to | ||
+ | // memory. One for every start of a char line (lineInitSrc) and one for every char in that line | ||
+ | // (plasmerSrc) | ||
+ | |||
+ | generateSpeedcode: | ||
+ | { | ||
+ | //get length of the source chunks | ||
+ | .var lineInitLength = _lineInitSrc - lineInitSrc | ||
+ | .var plasmerLength = _plasmerSrc - plasmerSrc | ||
+ | |||
+ | //set destination pointer... | ||
+ | lda #< | ||
+ | sta codePnt+0 | ||
+ | lda #> | ||
+ | sta codePnt+1 | ||
+ | |||
+ | //init adrs etc... | ||
+ | lda #<screen | ||
+ | sta pScr+1 | ||
+ | lda #>screen | ||
+ | sta pScr+2 | ||
+ | lda #0 | ||
+ | sta lSine0+1 | ||
+ | sta lSine1+1 | ||
+ | sta pSineY | ||
+ | sta pColorY | ||
+ | |||
+ | //start looping through all char lines... | ||
+ | lda #0 | ||
+ | sta yPos | ||
+ | yLoop: | ||
+ | //copy the line-init chunk to memory... | ||
+ | ldy #0 | ||
+ | !: lda lineInitSrc, | ||
+ | sta (codePnt),y | ||
+ | iny | ||
+ | cpy # | ||
+ | bne !- | ||
+ | jsr addCodePnt | ||
+ | |||
+ | //init plasmer source for the current line... | ||
+ | lda pSineY | ||
+ | sta pSine+1 | ||
+ | lda pColorY | ||
+ | sta pColor+1 | ||
+ | |||
+ | //start looping through all chars at the current y-position... | ||
+ | lda #0 | ||
+ | sta xPos | ||
+ | xLoop: | ||
+ | //copy the plasmer chunk for the current char... | ||
+ | ldy #0 | ||
+ | !: lda plasmerSrc, | ||
+ | sta (codePnt),y | ||
+ | iny | ||
+ | cpy # | ||
+ | bne !- | ||
+ | jsr addCodePnt | ||
+ | |||
+ | //update load/store addresses in plasmer source... | ||
+ | inc pScr+1 | ||
+ | bne !+ | ||
+ | inc pScr+2 | ||
+ | !: lda pSine+1 | ||
+ | clc | ||
+ | adc sineSpreadX | ||
+ | sta pSine+1 | ||
+ | lda pColor+1 | ||
+ | clc | ||
+ | adc colorSpreadX | ||
+ | sta pColor+1 | ||
+ | |||
+ | //next char... | ||
+ | inc xPos | ||
+ | lda xPos | ||
+ | cmp #width | ||
+ | bne xLoop | ||
+ | |||
+ | //update line init routine for the next line... | ||
+ | lda lSine0+1 | ||
+ | clc | ||
+ | adc # | ||
+ | sta lSine0+1 | ||
+ | lda lSine1+1 | ||
+ | clc | ||
+ | adc # | ||
+ | sta lSine1+1 | ||
+ | |||
+ | //update plasmer params for the next line... | ||
+ | lda pSineY | ||
+ | clc | ||
+ | adc sineSpreadY | ||
+ | sta pSineY | ||
+ | lda pColorY | ||
+ | clc | ||
+ | adc colorSpreadY | ||
+ | sta pColorY | ||
+ | |||
+ | //next y-pos... | ||
+ | inc yPos | ||
+ | lda yPos | ||
+ | cmp #height | ||
+ | beq !+ | ||
+ | jmp yLoop | ||
+ | !: | ||
+ | //add the final " | ||
+ | ldy #0 | ||
+ | lda #RTS | ||
+ | sta (codePnt), | ||
+ | rts | ||
+ | |||
+ | //the source chunks... | ||
+ | |||
+ | lineInitSrc: | ||
+ | ldx plasmaCnt+0 | ||
+ | ldy plasmaCnt+1 | ||
+ | clc | ||
+ | lSine0: lda sine128,x | ||
+ | lSine1: adc sine64,y | ||
+ | tax | ||
+ | _lineInitSrc: | ||
+ | |||
+ | plasmerSrc: | ||
+ | pSine: lda sine64,x | ||
+ | adc add | ||
+ | tay | ||
+ | pColor: lda colorTable, | ||
+ | pScr: sta screen | ||
+ | _plasmerSrc: | ||
+ | |||
+ | } | ||
+ | |||
+ | pSineY: .by 0 | ||
+ | pColorY:.by 0 | ||
+ | |||
+ | //increment codePnt with the value of the y-reg... | ||
+ | addCodePnt: | ||
+ | tya | ||
+ | clc | ||
+ | adc codePnt+0 | ||
+ | sta codePnt+0 | ||
+ | bcc !+ | ||
+ | inc codePnt+1 | ||
+ | !: | ||
+ | rts | ||
+ | // | ||
+ | </ | ||
base/8x8-plasma-effect-switch.txt · Last modified: 2015-04-17 04:30 by 127.0.0.1