mirror of
https://github.com/irmen/prog8.git
synced 2025-01-14 17:31:01 +00:00
tweak sprites module
This commit is contained in:
parent
f14ea1b3de
commit
5cd4b874ea
compiler
examples/cx16/sprites
@ -7,20 +7,19 @@
|
||||
; note: collision mask is not supported here yet.
|
||||
|
||||
sprites {
|
||||
const uword VERA_SPRITEREGS = $fc00 ; $1fc00
|
||||
const ubyte PALETTE_OFFSET = 16 ; color palette indices 16-31
|
||||
const ubyte SIZE_8 = 0
|
||||
const ubyte SIZE_16 = 1
|
||||
const ubyte SIZE_32 = 2
|
||||
const ubyte SIZE_64 = 3
|
||||
const ubyte COLORS_16 = 0
|
||||
const ubyte COLORS_256 = 128
|
||||
const uword VERA_SPRITEREGS = $fc00 ; $1fc00
|
||||
uword @zp sprite_reg
|
||||
|
||||
sub init(ubyte spritenum,
|
||||
ubyte databank, uword dataaddr,
|
||||
ubyte width_flag, ubyte height_flag,
|
||||
ubyte colors_flag) {
|
||||
ubyte colors_flag, ubyte palette_offset_idx) {
|
||||
hide(spritenum)
|
||||
cx16.VERA_DC_VIDEO |= %01000000 ; enable sprites globally
|
||||
dataaddr >>= 5
|
||||
@ -29,7 +28,15 @@ sprites {
|
||||
cx16.vpoke(1, sprite_reg, lsb(dataaddr)) ; address 12:5
|
||||
cx16.vpoke(1, sprite_reg+1, colors_flag | msb(dataaddr)) ; 4 bpp + address 16:13
|
||||
cx16.vpoke(1, sprite_reg+6, %00001100) ; z depth %11 = in front of both layers, no flips
|
||||
cx16.vpoke(1, sprite_reg+7, height_flag<<6 | width_flag<<4 | PALETTE_OFFSET>>4) ; 64x64 pixels, palette offset
|
||||
cx16.vpoke(1, sprite_reg+7, height_flag<<6 | width_flag<<4 | palette_offset_idx>>4) ; 64x64 pixels, palette offset
|
||||
}
|
||||
|
||||
sub data(ubyte spritenum, ubyte bank, uword addr) {
|
||||
addr >>= 5
|
||||
addr |= (bank as uword)<<11
|
||||
sprite_reg = VERA_SPRITEREGS + spritenum*$0008
|
||||
cx16.vpoke(1, sprite_reg, lsb(addr)) ; address 12:5
|
||||
cx16.vpoke_mask(1, sprite_reg+1, %11110000, msb(addr)) ; address 16:13
|
||||
}
|
||||
|
||||
sub pos(ubyte spritenum, word xpos, word ypos) {
|
||||
|
@ -306,7 +306,7 @@ internal class AstChecker(private val program: Program,
|
||||
if(subroutine.name in BuiltinFunctions)
|
||||
err("cannot redefine a built-in function")
|
||||
|
||||
if(subroutine.parameters.size>6 && !subroutine.isAsmSubroutine)
|
||||
if(subroutine.parameters.size>6 && !subroutine.isAsmSubroutine && !subroutine.definingBlock.isInLibrary)
|
||||
errors.warn("subroutine has a large number of parameters, this slows down code execution a lot", subroutine.position)
|
||||
|
||||
val uniqueNames = subroutine.parameters.asSequence().map { it.name }.toSet()
|
||||
|
@ -10,6 +10,7 @@ main {
|
||||
; we choose arbitrary unused vram location for sprite data: $12000
|
||||
const ubyte SPRITE_DATA_BANK = 1
|
||||
const uword SPRITE_DATA_ADDR = $2000
|
||||
const ubyte SPRITE_PALETTE_OFFSET_IDX = 16
|
||||
|
||||
sub start() {
|
||||
txt.plot(32,30)
|
||||
@ -17,11 +18,11 @@ main {
|
||||
|
||||
; load the sprite data and color palette directly into Vera ram
|
||||
void diskio.vload_raw("dragonsprite.bin", SPRITE_DATA_BANK, SPRITE_DATA_ADDR)
|
||||
void diskio.vload_raw("dragonsprite.pal", 1, $fa00 + sprites.PALETTE_OFFSET*2)
|
||||
void diskio.vload_raw("dragonsprite.pal", 1, $fa00 + SPRITE_PALETTE_OFFSET_IDX*2)
|
||||
|
||||
; initialize the dragon sprites
|
||||
sprites.init(1, SPRITE_DATA_BANK, SPRITE_DATA_ADDR, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16) ; top half of dragon
|
||||
sprites.init(2, SPRITE_DATA_BANK, SPRITE_DATA_ADDR + 64*64/2, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16) ; bottom half of dragon
|
||||
sprites.init(1, SPRITE_DATA_BANK, SPRITE_DATA_ADDR, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16, SPRITE_PALETTE_OFFSET_IDX)
|
||||
sprites.init(2, SPRITE_DATA_BANK, SPRITE_DATA_ADDR + 64*64/2, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16,SPRITE_PALETTE_OFFSET_IDX)
|
||||
|
||||
ubyte tt = 0
|
||||
word xpos = -64
|
||||
|
@ -10,6 +10,7 @@ main {
|
||||
; we choose arbitrary unused vram location for sprite data: $12000
|
||||
const ubyte SPRITE_DATA_BANK = 1
|
||||
const uword SPRITE_DATA_ADDR = $2000
|
||||
const ubyte SPRITE_PALETTE_OFFSET_IDX = 16
|
||||
|
||||
const ubyte NUM_DRAGONS = 25
|
||||
word[NUM_DRAGONS*2] xpositions
|
||||
@ -21,13 +22,13 @@ main {
|
||||
|
||||
; load the sprite data and color palette directly into Vera ram
|
||||
void diskio.vload_raw("dragonsprite.bin", SPRITE_DATA_BANK, SPRITE_DATA_ADDR)
|
||||
void diskio.vload_raw("dragonsprite.pal", 1, $fa00 + sprites.PALETTE_OFFSET*2)
|
||||
void diskio.vload_raw("dragonsprite.pal", 1, $fa00 + SPRITE_PALETTE_OFFSET_IDX*2)
|
||||
|
||||
; initialize the dragon sprites (every dragon needs 2 sprites)
|
||||
; initialize the dragon sprites (every dragon needs 2 sprites, top and bottom half)
|
||||
ubyte sprite_num
|
||||
for sprite_num in 0 to NUM_DRAGONS*2-2 step 2 {
|
||||
sprites.init(sprite_num+1, SPRITE_DATA_BANK, SPRITE_DATA_ADDR, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16) ; top half of dragon
|
||||
sprites.init(sprite_num+2, SPRITE_DATA_BANK, SPRITE_DATA_ADDR + 64*64/2, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16) ; bottom half of dragon
|
||||
sprites.init(sprite_num+1, SPRITE_DATA_BANK, SPRITE_DATA_ADDR, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16, SPRITE_PALETTE_OFFSET_IDX)
|
||||
sprites.init(sprite_num+2, SPRITE_DATA_BANK, SPRITE_DATA_ADDR + 64*64/2, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16, SPRITE_PALETTE_OFFSET_IDX)
|
||||
|
||||
xpositions[sprite_num] = math.rndw() % (640-64) as word
|
||||
xpositions[sprite_num+1] = xpositions[sprite_num]
|
||||
|
Loading…
x
Reference in New Issue
Block a user