Added vcs_spr48 sample.

This commit is contained in:
g012 2017-10-06 13:02:12 +02:00
parent e07c87b45d
commit f84ea4e357
4 changed files with 145 additions and 5 deletions

BIN
samples/dotbin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -58,7 +58,7 @@ do
local PERIOD = 128
local f = \x((math.sin(x*2*math.pi/PERIOD)+1)/2 * (STEP_COUNT-1))
local rotation = {}
for x=1,128 do
for x=1,PERIOD do
rotation[#rotation+1] = math.floor(math.min(f(x-1), (STEP_COUNT-1)))
end
@@logo_rotation byte(rotation)

139
samples/vcs_spr48.l65 Normal file
View File

@ -0,0 +1,139 @@
require'vcs'
mappers['2K']()
local i = 0x80
local ramk=i i=i+51
local spritestack=i i=i+31
local stackbackup=i i=i+1
local time=i i=i+2
local seed=i i=i+2
local spritepos=i i=i+1
local tmp=i
-- load the 6 sprites and the shared color palette
local img = assert(l65.image("dotbin.png"))
@@col samepage byte(linecol{image=img, y0=30, y1=0, yinc=-1}, 0, 0) end
local sp = sprite{image=img, y0=185, y1=0, yinc=-1}
for i=1,6 do
section{"spr"..i, align=256} byte(sp[i])
local c = #sp[i]
end
-- sprite anim frames offset in spr*
@@frame samepage dc.b 0,31,62,93,124,155 end
-- sprite anim palette offset
@@paloff samepage dc.b 0,0,0,2,0,0 end
-- division by 3 table: result in 6 LSB, remainder in 2 MSB
do
local t = {}
for x=0,113 do t[#t+1] = x//3 & 0x3f | x%3 << 6 end
@@div3 samepage byte(t) end
end
-- y: sprite pos
-- return result of division in x
@@slide
lda#_start>>8 pha
lax div3,y and#0x3f clc adc#_start&0xff pha
samepage
sta WSYNC
@_start
rts
for i=1,35 do dc.b 0xc9 end
dc.b 0xc5 nop
end
rts
-- y: sprite pos
@@setpos
jsr slide sleep(6) sta RESP0 sta RESP1
txa lsr lsr and#0x30 sta HMP0 adc#0x10 sta HMP1 sta WSYNC sta HMOVE
rts
-- y: frame index
@@setframe -- modify ram kernel with new palette offset and sprite frame pointers
lda#col&0xff sta tmp lda paloff,y clc adc tmp sta ramk+3
lda frame,y
local off = { 10, 15, 20, 29, 32 }
for _,o in ipairs(off) do sta ramk,o end
tsx stx tmp ldx#spritestack+30 txs
sta tmp+2 clc adc#31 sta tmp+1 ldy tmp+2 @_push lda spr4,y pha iny cpy tmp+1 bne _push
ldx tmp txs
rts
@@spritek
ldy tmp lda col,y sta COLUP1 sta COLUP0
ldx spr1,y stx GRP0 lda spr2,y sta GRP1 lda spr3,y sta GRP0
sleep(8) -- use this time to set COLUPF :)
ldx spr5,y lda spr6,y tay pla
sta GRP1 stx GRP0 sty GRP1 stx GRP0
dec tmp bpl spritek
jmp spritek_done
local kernel = function()
ldy#50 @_delay sta WSYNC dey bpl _delay
tsx stx stackbackup
lda#30 sta tmp ldy spritepos
samepage
jsr slide sleep(24)
ldx#(spritestack&0xff)-1 txs
jmp ramk
end
@spritek_done
lda#0 sta GRP0 sta GRP1 sta GRP0
ldx stackbackup txs
end
@@rand
beq _xor asl beq _nor bmi _nor
@_xor eor#0x5f
@_nor rts
@@glitch_cmphi dc.b 0xFF,0x03,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00
@@glitch_cmplo dc.b 0xFF,0x10,0xA0,0x60,0x30,0x20,0xE0,0xC0,0x90,0x60
@@glitch dc.b 4,3,2,1,0,1,2,3,4
@@sproff_cmphi dc.b 0xFF,0x03,0x03,0x02,0x01,0x00,0x00
@@sproff_cmplo dc.b 0xFF,0x40,0x10,0x80,0x20,0xA0,0x60
@@sproff dc.b 7,3,1,0,1,3,7
@@sproff_add dc.b 6,8,10,11,10,8,6
local on_vblank = function()
inc time bne _noover inc time+1 @_noover
-- frame change
lda time; and#3 bne _keep lda seed jsr rand sta seed @_keep
ldy#8 @_glitch
lda time+1 cmp glitch_cmphi,y bcc _glitchdone bne _glitchnext
lda time cmp glitch_cmplo,y bcc _glitchdone
@_glitchnext dey bne _glitch
@_glitchdone
lda glitch,y tay lda seed cpy#1 bcc _wait @_lower lsr dey bne _lower @_wait cmp#6 bcc _noreset lda#5 @_noreset
tay jsr setframe
-- position change
lda time; and#7 bne _skipmove
ldy#6 @_move
lda time+1 cmp sproff_cmphi,y bcc _stay bne _movenext
lda time cmp sproff_cmplo,y bcc _stay
@_movenext dey bne _move
@_stay
lda sproff,y sta tmp lda sproff_add,y sta tmp+1
lda seed+1 jsr rand sta seed+1; and tmp clc adc tmp+1 adc#50 sta spritepos tay jsr setpos
@_skipmove
end
@@main
init()
lda#vdel.ENABLE sta VDELP1 sta VDELP0
lda#nusiz.THREE_COPIES_CLOSE sta NUSIZ0 sta NUSIZ1
-- load kernel into RAM
ldy#50 @_loadk lda spritek,y sta ramk,y dey bpl _loadk
@doframe
overscan() vblank(on_vblank) screen(kernel) jmp doframe
;
writebin(filename..'.bin')
writesym(filename..'.sym')
print(stats)

View File

@ -383,16 +383,17 @@ image_scan = function(img, opt)
yinc=opt.yinc or 1 y0=opt.y0 or 0 y1=opt.y1 or img.height-1
if x1<x0 and xinc<0 then x0,x1=x1,x0 xinc=-xinc flipx=true end
if y1<y0 and yinc<0 then y0,y1=y1,y0 yinc=-yinc flipy=true end
assert(y1>=y0 and x1>=x0 and x1<img.width and y1<img.height, "invalid dimensions")
assert(y1>=y0 and x1>=x0 and x1<img.width and y1<img.height,
string.format("invalid dimensions: x[%d -> %d] y[%d -> %d] for img[%d, %d]", x0, x1, y0, y1, img.width, img.height))
width = 1 + (x1 - x0) // xinc
height = 1 + (y1 - y0) // yinc
for y=y0,y1,yinc do for x=x0,x1,xinc do b[#b+1] = img[y*img.width+x+1] end end
if flipx then for y=0,height-1 do for x=0,width//2-1 do
local i0, i1 = y*width+x, y*height+width-1
local i0, i1 = y*width+x+1, y*height+width
b[i0], b[i1] = b[i1], b[i0]
end end end
if flipy then for y=0,height//2-1 do for x=0,width-1 do
local i0, i1 = y*width+x, (height-1-y)*width+x
local i0, i1 = y*width+x+1, (height-1-y)*width+x+1
b[i0], b[i1] = b[i1], b[i0]
end end end
return b, width, height
@ -442,7 +443,7 @@ sprite = function(opt)
local s={} sp[#sp+1]=s
for y=0,h-1 do
local o=c*8
local e=o+7 > w and w-1 or o+7
local e=o+7 >= w and w-1 or o+7
local i,color = 7,0
for x=o,e do
if b[y*w+x+1] ~= 0 then color = color | 1<<i end