2020-09-20 21:49:36 +00:00
|
|
|
%import syslib
|
|
|
|
%import textio
|
2022-04-12 21:58:19 +00:00
|
|
|
%import math
|
2020-08-21 14:53:56 +00:00
|
|
|
|
2020-10-01 22:34:12 +00:00
|
|
|
; converted from plasma test program for cc65.
|
|
|
|
; which is (w)2001 by groepaz/hitmen
|
|
|
|
;
|
|
|
|
; Cleanup and porting to C by Ullrich von Bassewitz.
|
2023-09-04 18:19:04 +00:00
|
|
|
; See https://github.com/cc65/cc65/tree/master/samples/cbm/plasma.c
|
|
|
|
;
|
2023-09-04 22:23:50 +00:00
|
|
|
; Optimized and Converted to prog8 by Irmen de Jong.
|
2020-08-21 14:53:56 +00:00
|
|
|
|
2020-11-03 20:31:08 +00:00
|
|
|
|
2020-08-21 14:53:56 +00:00
|
|
|
main {
|
|
|
|
const uword SCREEN1 = $E000
|
|
|
|
const uword SCREEN2 = $E400
|
|
|
|
const uword CHARSET = $E800
|
|
|
|
|
|
|
|
const ubyte PAGE1 = ((SCREEN1 >> 6) & $F0) | ((CHARSET >> 10) & $0E)
|
|
|
|
const ubyte PAGE2 = ((SCREEN2 >> 6) & $F0) | ((CHARSET >> 10) & $0E)
|
|
|
|
|
|
|
|
sub start() {
|
2020-08-29 22:15:18 +00:00
|
|
|
txt.color(1)
|
2022-04-02 15:53:24 +00:00
|
|
|
txt.clear_screen()
|
2023-09-04 18:19:04 +00:00
|
|
|
txt.print("creating charset...\n\nwhile running, press key to stop.\n\n")
|
2020-08-21 14:53:56 +00:00
|
|
|
makechar()
|
|
|
|
|
|
|
|
ubyte block = c64.CIA2PRA
|
2023-09-04 18:19:04 +00:00
|
|
|
ubyte v = c64.VMCSB
|
2020-08-21 14:53:56 +00:00
|
|
|
c64.CIA2PRA = (block & $FC) | (lsb(SCREEN1 >> 14) ^ $03)
|
|
|
|
|
2023-09-04 18:19:04 +00:00
|
|
|
uword frames = 0
|
|
|
|
cbm.SETTIM(0,0,0)
|
|
|
|
|
|
|
|
while cbm.GETIN()==0 {
|
2020-08-21 14:53:56 +00:00
|
|
|
doplasma(SCREEN1)
|
|
|
|
c64.VMCSB = PAGE1
|
|
|
|
doplasma(SCREEN2)
|
|
|
|
c64.VMCSB = PAGE2
|
2023-09-04 18:19:04 +00:00
|
|
|
frames += 2
|
2020-08-21 14:53:56 +00:00
|
|
|
}
|
2020-08-21 15:44:44 +00:00
|
|
|
|
2023-09-04 18:19:04 +00:00
|
|
|
uword jiffies = cbm.RDTIM16()
|
|
|
|
|
|
|
|
; restore screen and displays stats
|
|
|
|
c64.VMCSB = v
|
|
|
|
c64.CIA2PRA = block
|
|
|
|
txt.print("time in jiffies: ")
|
|
|
|
txt.print_uw(jiffies)
|
|
|
|
txt.print("\nframes: ")
|
|
|
|
txt.print_uw(frames)
|
|
|
|
uword fps = (frames*60)/jiffies
|
|
|
|
txt.print("\nfps: ")
|
|
|
|
txt.print_uw(fps)
|
|
|
|
txt.print("\ndone!\n")
|
|
|
|
repeat {
|
|
|
|
}
|
2020-08-21 14:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
; several variables outside of doplasma to make them retain their value
|
|
|
|
ubyte c1A
|
|
|
|
ubyte c1B
|
|
|
|
ubyte c2A
|
|
|
|
ubyte c2B
|
|
|
|
|
2023-09-04 18:19:04 +00:00
|
|
|
sub doplasma(uword @zp screen) {
|
2020-08-21 14:53:56 +00:00
|
|
|
ubyte[40] xbuf
|
|
|
|
ubyte[25] ybuf
|
|
|
|
ubyte c1a = c1A
|
|
|
|
ubyte c1b = c1B
|
|
|
|
ubyte c2a = c2A
|
|
|
|
ubyte c2b = c2B
|
2020-08-21 15:44:44 +00:00
|
|
|
ubyte @zp x
|
|
|
|
ubyte @zp y
|
2020-08-21 14:53:56 +00:00
|
|
|
|
2023-09-04 22:23:50 +00:00
|
|
|
for y in 0 to 24 {
|
2022-04-12 21:58:19 +00:00
|
|
|
ybuf[y] = math.sin8u(c1a) + math.sin8u(c1b)
|
2020-08-21 14:53:56 +00:00
|
|
|
c1a += 4
|
|
|
|
c1b += 9
|
|
|
|
}
|
|
|
|
c1A += 3
|
|
|
|
c1B -= 5
|
2023-09-04 22:23:50 +00:00
|
|
|
for x in 0 to 39 {
|
2022-04-12 21:58:19 +00:00
|
|
|
xbuf[x] = math.sin8u(c2a) + math.sin8u(c2b)
|
2020-08-21 14:53:56 +00:00
|
|
|
c2a += 3
|
|
|
|
c2b += 7
|
|
|
|
}
|
|
|
|
c2A += 2
|
|
|
|
c2B -= 3
|
2020-09-30 17:57:16 +00:00
|
|
|
|
2023-09-04 19:07:49 +00:00
|
|
|
for y in 0 to 24 {
|
2023-09-04 22:23:50 +00:00
|
|
|
ubyte @zp @shared yvalue = ybuf[y]
|
2023-09-04 19:07:49 +00:00
|
|
|
for x in 0 to 39 {
|
2023-09-04 22:23:50 +00:00
|
|
|
; @(screen+x) = xbuf[x] + yvalue
|
2023-09-04 19:07:49 +00:00
|
|
|
; max optimized asm is this: (achieving ~21 fps on the C64):
|
2023-09-04 22:23:50 +00:00
|
|
|
%asm {{
|
|
|
|
lda p8_yvalue
|
|
|
|
ldy p8_x
|
|
|
|
clc
|
|
|
|
adc p8_xbuf,y
|
|
|
|
sta (p8_screen),y
|
|
|
|
}}
|
2021-01-23 14:52:27 +00:00
|
|
|
}
|
|
|
|
screen += 40
|
2020-08-21 14:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub makechar() {
|
|
|
|
ubyte[8] bittab = [ $01, $02, $04, $08, $10, $20, $40, $80 ]
|
|
|
|
ubyte c
|
|
|
|
for c in 0 to 255 {
|
2023-09-04 18:19:04 +00:00
|
|
|
ubyte @zp s = math.sin8u(c) ; chance
|
2020-08-21 14:53:56 +00:00
|
|
|
ubyte i
|
2023-09-04 18:19:04 +00:00
|
|
|
; for all the pixels in the 8x8 character grid, determine (with a rnd chance) if they should be on or off
|
2020-08-21 14:53:56 +00:00
|
|
|
for i in 0 to 7 {
|
|
|
|
ubyte b=0
|
|
|
|
ubyte @zp ii
|
|
|
|
for ii in 0 to 7 {
|
2023-09-04 18:19:04 +00:00
|
|
|
if math.rnd() > s
|
2020-08-21 14:53:56 +00:00
|
|
|
b |= bittab[ii]
|
|
|
|
}
|
2020-09-19 21:23:32 +00:00
|
|
|
@(CHARSET + i + c*$0008) = b
|
2020-08-21 14:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|