1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-04-05 03:37:43 +00:00

HGR sprite library WIP

This commit is contained in:
David Schmenk 2019-12-25 10:23:50 -08:00
parent 1f94b7331a
commit dd721f5a75
3 changed files with 183 additions and 44 deletions

View File

@ -4,6 +4,7 @@ import hgrlib
predef hgrXorPlot(x, y)#0
predef hgrHLin(x1, x2, y)#0
predef hgrVLin(y1, y2, x)#0
predef hgrRect(x1, x2, y1, y2)#0
predef hgrBLT(x, y, width, height, srcptr)#0
predef hgrCopySrc(ofst, y, w, h, srcptr)#0
predef hgrAndSrc(ofst, y, w, h, srcptr)#0
@ -11,8 +12,9 @@ import hgrlib
predef hgrCopyDst(ofst, y, w, h, dstptr)#0
predef hgrMode#1
predef txtMode#0
predef hgrClear#0
predef hgrShow(page)#1
predef hgrSwap#0
predef hgrSwap#1
predef hgrDrawBuf(page)#0
predef hgrColor(clr)#0
end

View File

@ -108,7 +108,7 @@ export asm divmod7(x)#2
STA ESTKH,X
STA ESTKH+1,X
RTS
end
end
export def hgrColor(c)#0
curhclr = hcolor[c & $07]
end
@ -132,7 +132,7 @@ export def hgrXorPlot(x, y)#0
end
export def hgrHlin(x1, x2, y)#0
word pixptr, x
byte lofst, lpixofst, lpmask, clr
byte lofst, lpixofst, lpmask
byte rofst, rpixofst, rpmask
if x1 == x2
@ -175,6 +175,52 @@ export def hgrVlin(y1, y2, x)#0
next
fin
end
export def hgrRect(x1, x2, y1, y2)#0
word pixptr, x, y, lofst, rofst
byte lpixofst, lpmask, cmask
byte rpixofst, rpmask
if x1 == x2
hgrVLin(y1, y2, x1)
else
lofst, lpixofst = divmod7(x1)
rofst, rpixofst = divmod7(x2)
lofst = lofst + drawbuff
rofst = rofst + drawbuff
lpmask = hlmask[lpixofst]
rpmask = hrmask[rpixofst]
if lofst == rofst
lpmask = lpmask & rpmask
cmask = curhclr.[pixptr.0 & 1] & lpmask
lpmask = ~lpmask
for y = y1 to y2
pixptr = hgrscan[y] + lofst
^pixptr = (^pixptr & lpmask) | cmask
next
else
for y = y1 to y2
pixptr = hgrscan[y] + lofst
^pixptr = (^pixptr & ~lpmask) | (curhclr.[pixptr.0 & 1] & lpmask)
pixptr++
for x = lofst + 1 to rofst - 1
^pixptr = curhclr.[pixptr.0 & 1]
pixptr++
next
^pixptr = (^pixptr & ~rpmask) | (curhclr.[pixptr.0 & 1] & rpmask)
next
fin
fin
end
export def hgrCopyDst(ofst, y, w, h, dstptr)#0
word j, srcptr
ofst = ofst + drawbuff
for j = y to y + h - 1
srcptr = hgrscan[j] + ofst
memcpy(dstptr, srcptr, w)
dstptr = dstptr + w
next
end
export def hgrCopySrc(ofst, y, w, h, srcptr)#0
word j, dstptr
@ -211,16 +257,6 @@ export def hgrXorSrc(ofst, y, w, h, srcptr)#0
srcptr = srcptr + w
next
end
export def hgrCopyDst(ofst, y, w, h, dstptr)#0
word j, srcptr
ofst = ofst + drawbuff
for j = y to y + h - 1
srcptr = hgrscan[j] + ofst
memcpy(dstptr, srcptr, w)
dstptr = dstptr + w
next
end
export def hgrBLT(x, y, w, h, srcptr)#0
word i, j
word saveclr
@ -231,15 +267,15 @@ export def hgrBLT(x, y, w, h, srcptr)#0
for i = 0 to w - 1
c = srcptr->[i >> 1]
if i & 1
curhclr = hcolor[(c >> 4) & $07]
if c & $80
curhclr = hcolor[c & $07]
if c & $08
hgrXorPlot(x + i, j)
else
hgrPlot(x + i, j)
fin
else
curhclr = hcolor[c & $07]
if c & $08
curhclr = hcolor[(c >> 4) & $07]
if c & $80
hgrXorPlot(x + i, j)
else
hgrPlot(x + i, j)
@ -264,6 +300,9 @@ export def txtMode#0
^showpage1
^showtext
end
export def hgrClear#0
memset(drawbuff, curhclr, $2000) // Clear HGR page 1
end
//
// Set display page, return other page
//
@ -272,10 +311,11 @@ export def hgrShow(page)#1
^(showpage1 + page)
return page ^ 1
end
export def hgrSwap#0
export def hgrSwap#1
^(showpage1 + drawpage)
drawpage = drawpage ^ 1
drawbuff = hgrbuff[drawpage]
return drawpage
end
export def hgrDrawBuf(page)#0
drawpage = page & 1

View File

@ -1,46 +1,143 @@
include "inc/cmdsys.plh"
include "inc/linespans.plh"
include "inc/hgrlib.plh"
sysflags reshgr1 | reshgr2 // Reserve HGR page 1 and 2
include "inc/linespans.plh"
sysflags reshgr1|reshgr2 // Reserve HGR page 1 and 2
byte ball = $88, $8F, $FF, $F8, $88
byte = $88, $FF, $FF, $FF, $88
byte = $8F, $FF, $FF, $FF, $F8
byte = $FF, $FF, $FF, $FF, $FF
byte = $FF, $FF, $FF, $FF, $FF
byte = $FF, $FF, $FF, $FF, $FF
byte = $FF, $FF, $FF, $FF, $FF
byte = $8F, $FF, $FF, $FF, $F8
byte = $88, $FF, $FF, $FF, $88
byte = $88, $8F, $FF, $F8, $88
struc t_sprite
byte s_underofst[2]
var s_undery[2]
var s_width
var s_height
var s_pitch
var s_size
var s_mask[14]
var s_map[14]
var s_under[14]
end
byte ball = $88, $83, $33, $38, $88
byte = $88, $33, $11, $33, $88
byte = $83, $31, $11, $13, $38
byte = $33, $11, $11, $11, $33
byte = $33, $11, $11, $11, $33
byte = $33, $11, $11, $11, $33
byte = $33, $11, $11, $11, $33
byte = $83, $31, $11, $13, $38
byte = $88, $33, $11, $33, $88
byte = $88, $83, $33, $38, $88
var sprtBall
byte drawpage
//
// Sprite routines
//
def spriteCompile(spriteprt)
return 0
export def spriteBLTMask(x, y, w, h, srcptr)#0
word i, j
byte c
for j = y to y + h - 1
for i = 0 to w - 1
c = srcptr->[i >> 1]
if i & 1
hgrColor(c & $08 ?? 7 :: 0)
else
hgrColor(c & $80 ?? 7 :: 0)
fin
hgrPlot(x + i, j)
next
srcptr = srcptr + (w + 1) / 2
next
end
def spriteCompile(w, h, srcptr)
var sprtptr, bytewidth, spritesize, i
sprtptr = heapalloc(t_sprite)
bytewidth = (w + 7) / 7 + 1
sprtptr=>s_pitch = bytewidth
spritesize = bytewidth * h
sprtptr=>s_size = spritesize
sprtptr=>s_width = w
sprtptr=>s_height = h
sprtptr=>s_under[0] = heapalloc(spritesize)
sprtptr=>s_under[1] = heapalloc(spritesize)
for i = 0 to 13
sprtptr=>s_map[i] = heapalloc(spritesize)
sprtptr=>s_mask[i] = heapalloc(spritesize)
hgrColor(0)
hgrRect(0, i + w + 14, 0, h - 1)
hgrBLT(i, 0, w, h, srcptr)
hgrCopyDst(i > 6 ?? 1 :: 0, 0, bytewidth, h, sprtptr=>s_map[i])
hgrColor(7)
hgrRect(0, i + w + 14, h, h * 2 - 1)
spriteBLTMask(i, h, w, h, srcptr)
hgrCopyDst(i > 6 ?? 1 :: 0, h, bytewidth, h, sprtptr=>s_mask[i])
next
sprtptr->s_underofst[0] = 255 // Mark as under not valid
sprtptr->s_underofst[1] = 255
return sprtptr
end
def spriteDraw(page, x, y, sprtptr)#0
byte ofst, map
var width, height
ofst, map = divmod7(x)
if ofst & 1
map = map + 7
fin
sprtptr->s_underofst[page] = ofst
sprtptr->s_undery[page] = y
width = sprtptr=>s_pitch
height = sprtptr=>s_height
hgrCopyDst(ofst, y, width, height, sprtptr=>s_under[page])
hgrAndSrc( ofst, y, width, height, sprtptr=>s_mask[map])
hgrXorSrc( ofst, y, width, height, sprtptr=>s_map[map])
end
def spriteUnDraw(page, sprtptr)#0
if sprtptr->s_underofst[page] < 40
hgrCopySrc(sprtptr->s_underofst[page], sprtptr->s_undery[page], sprtptr=>s_pitch, sprtptr=>s_height, sprtptr=>s_under[page])
fin
end
def testline#0
var i
setlinespans(@hgrHlin, @hgrVlin)
hgrColor(3)
for i = 0 to 191 step 4
hgrColor(7)
for i = 0 to 191 step 24
linetospans(0, 0, 279, i)
next
for i = 0 to 279 step 24
linetospans(0, 0, i, 191)
linetospans(0, 0, 191, i)
next
end
def testblt#0
var i
def testblt(sprtptr)#0
var i, j, ii, jj
for i = 0 to 200 step 3
hgrBlt(i, 50, 10, 10, @ball)
hgrBlt(i, 50, 10, 10, @ball)
next
i = 100
ii = 1
j = 80
jj = 1
while ^$C000 < 128
spriteUnDraw(drawpage, sprtptr)
i = i + ii
if i < 1 or i > 269
ii = -ii
fin
j = j + jj
if j < 1 or j > 181
jj = -jj
fin
spriteDraw(drawpage, i, j, sprtptr)
drawpage = hgrSwap()
loop
end
hgrMode
hgrDrawBuf(0)
drawpage = hgrMode
hgrDrawBuf(0) // So we can see the compile process
sprtBall = spriteCompile(10, 10, @ball)
hgrColor(0)
hgrClear()
testline
testblt
memcpy($4000, $2000, $2000) // Copy to both buffers
hgrDrawbuf(drawpage)
testblt(sprtBall)
getc
txtMode
done