| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
gonna show you guys how it's done !
well that's what i thought a few days ago !
this, my second go at c64 coding. much more serious this time. about a year ago i gave it a shot and got tangled up in stable rasters and such... i remember chatting with graham on irc trying to learn more about them, but mostly hearing about how i should support c128 2mhz in my routines :)
so this time, i decided to try and duplicate (without monitoring!) one of my favorite routines - xbow's sideborder rasters from demus interruptus endpart.
had it all figured out !
(i thought, you'll quickly see what i missed)
open the borders,
fld to get rid of the badlines,
all 8 sprites stretched across,
y-stretch all 8 sprites so the screen is filled with the same row of the sprite (128 rows anyway)
now on each line, plot the new bar into the sprite.
i even had some (i thought) great ideas - like, all 8 sprites use the same buffer, and i toggled the stretching on each, before the effect, so that each would be using the next sprite-line during the effect... so i have a 24-byte 'linear' area to plot new bars on.
of course, i'd have to unroll the loop to get it to fit in 63 cycles.
and it has to be modified each frame, to plot the right bytes directly where they should go.
so the calculation for each frame takes a long time since it has to modify the unrolled irq.
so i had to unroll that also.
and it still takes too long... so i decided to do some more FLD to free up some time from badlines and use that to clear the sprite buffer before the next frame.
oh my
after all this work, and thinking things were not so tough - stretched multicolor sprites are ugly ! but demus's rasters are thin... so after all my efforts, i have a half-screenwidth of bars, which can be put in the sideborder, and not a whole screen.
depressing, cuz now i don't understand it.
can FLI/FLD be used to repeat the same bitmap row all the way down the screen?
i had a few mistakes that seemed to do this, except the byte that i had on the screen appeared to come from $3fff.
then of course the problem of getting the sprites on there, in the sideborders, with badlines (i guess).
now it appears impossible (haha)
nevermind the other demus bars which are in all borders - where is the time to calculate the movement ??
well anyway,
much respect to all you guys because this stuff is very challenging. fun though
|
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
You can stretch bitmap w/ fld too, but IIRC it's easier to stretch chars. Bet that's how the non-border area of Crest's sideborder bars are done. Do do this you just have to time the routine so it starts at the right place - I think it's at the line before a badline. |
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
cruzer: chars won't get me the colors though... (right?)
and i was rereading that vic-article a few times, looking for something that said if the internal RC is always going to roll over or not... i mean, there's stuff on there on getting the same charline to be duplicated. it looked like perhaps u can stretch the top line of a row 8 times (i guess this would be the opposite of linecrunch - actually FLI without switching banks), but it wasn't obvious that u could keep copying the same line. maybe i should reread again.
then deciding if a bar-byte goes into the sprites or the screen will add some cycles to the calculation...
noone has some magic hires multicolor sprites? ;) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
> chars won't get me the colors though... (right?)
Chars will get you 4 multicolor-colors, just like bitmap or sprites. You can redefine the charset on the c64 you know. Try playing around with $d018, and $d016 to turn on the multicolor mode. |
| |
Stryyker
Registered: Dec 2001 Posts: 468 |
Demus Interruptus doesn't have many colours so chars are fine. Stretching a char line isn't too hard. Stretching the bitmap is exactly the same. Stretch it properly and you don't get the 3 char bug. And yes the code looks alot like FLI.
Clever calculations are clever tables. Clever character or sprite organisation. You started with a smart idea for the sprites, 1 sprite just different Y offsets before stretch. Now look at any calclations you are doing. Maybe tidy up tables to reduce any overflow detection if you have any. If you use chars with sprites then you don't need as many sprites. |
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
cruzer: yea i admit i have not touched any bitmap or char stuff yet.. hell i should just try and code a scroller or something :) but if i set onto a complex task then i can learn alot of things on the way, which i have.
stryyker: thanks :) i also wondered if my multicolor 'put-bar' was very good or not. xbow's bars are at least 5 pixels wide... so i made a routine that can do up to 8 pixels wide, always writing two bytes.
i made four masks to and with, and four copies of the bar-pattern to ora.
the low 2 bits of the x position are index into the mask & pattern...
so it looks like
lda sprite,x
and masktable,y
ora patterntable,y
sta sprite,x
but that's a lot of cycles, i'd like a faster way but i don't see it yet. i thought of making a table of precalculated results for all 4-pixel-offsets against any possible existing pixels.
also i need to work on some better sin/cos animation cuz mine is really lacking, so i think i'll write up a generator tonight and see what better movement i can get out of it.
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
> hell i should just try and code a scroller or something :)
Maybe not a bad idea to try something a bit simpler. Not to take anything away from your enthusiasm, but sideborder-kefrensbars are probably quite a hard routine to code. After all, it was done by the #1 coder Crossbow, after the #3 coder HCL had said, he thought it was impossible. :) |
| |
Turtle Account closed
Registered: Jan 2002 Posts: 70 |
@Cruzer: Just in case I missed something: Who's #2 to your oppinion? And what did he (she) thought of the possibility to code such fx? I already have a guess... |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
you can stretch down 1 rasterline of bitmap or characterscreen, the code is as fli, but u have 63 cycles each line... play a bit with a 63 cycle fli routine, and you will find the way. Even with border removal you must have enough cycles to do the thing...
lda #xx ;2
sta $d011 ;4=6
ldx sine ;4
ldy offset,x ;4 (tricky table, either points to
and mask,x ;4 bitmap or the right sprite
ora bar,x ;4 location)
sta spriteorbitmap,y ;4=20
ldx sine
ldy offset,x
and mask,x
ora bar,x
sta spriteorbitmap,y ; =20
ldx #xx ;2
ldy #xx ;2
stx $d016 ;4
sty $d016 ;4=12
this makes 58 cycles... well this is probably too slow, as 4 sprites need more then 5 cycles I guess ;) (you can save 4 cycles if u selfmod the irq speedcode, so you do ldx #sinevalue instead of ldx sine, but thats prolly still not enough) I guess thats why xbow made it only every 2nd line.. but with 2 lines you earn a lot of cycles to do things.
This routine just came from the top of my head, so dont judge it too hard :)
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
ok, I forgot the lda spriteorbitmap,y... now its slower than 63 cycles.. :) and it prolly needs 2 buffered lines of bitmap and sprite, that makes an extra $d018 write.. |
| |
Stryyker
Registered: Dec 2001 Posts: 468 |
NAturally self modifying code is used :) Try to reduce the writes as much as possible.
ldx #$xx
lda $mem,x
and #$aa
ora #$aa
sta $mem,x
This shifts come of the code from the timing critical limited to to the little more time in after the effect is done.
This could maybe be change too.
I never tried it but maybe just change the char on screen, not the contents of the char. Some will say that is cheating though.
Never realised Crossbow did it every 2nd line. Makes me think I have a chance of doing it :) |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
@Stryyker:
changing the chars and not the contents of the chars will have no effect due to no badlines.
@crossbow, hcl and all the others:
i wonder why everyone is so exited about the kefrens bars in sideborder being impossible etc. it has been done in 1992 already in emotional breakdown by offence. |
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
@graham: it's just a pretty routine that looks like one to learn alot while trying to copy. for myself anyway...
@oswald: the sprite-only one that i already did - all of the movement is calculated before each frame is drawn. i calculate the two bytes i will draw, and their addresses, and those bytes are put into the unrolled loop for the effect.
...
ldx #xx <- load precalculated left bar byte
lda #xx <- load precalculated right bar byte
...
sta $80xx <- store right bar byte into sprite
...
stx $80xx <- store left bar byte into sprite
...
now during the calculation, i just modify those four bytes. so to adapt it to use chars and a few sprites will be mostly changes to the calculation.
that made for a slow calculation loop also - so i had to unroll -it- and precalc it's destination addresses in the unrolled raster loop (!)...
i don't see how there is time to do lda/and/ora/sta for both bytes in the raster loop ... with sprites on the screen as well
thanks for all your input guys :)
|
| |
Stryyker
Registered: Dec 2001 Posts: 468 |
Your sprite version works ok? Why not move gfx so the sprites are stored in zero page?
Graham: I was thinking of stretching first char line forgetting about sprites :( |
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
stryyker: yeah it works... i was wondering if sprite from zero page would work or not, i have not done much with the zero page yet except store a few things in $fb/fc/fd. it would win many cycles since so much read/write is done to the sprite - but i did get 127 bars in one frame without it. now if i continue, the next challenge is to get the char portion of the screen going. zero page sprite might buy me some more cycles since i'll be adding another half-width-screen of bytes that have to be cleared twice... and the new ones can't be zeropage.
i havn't done much with turning off the basic/kernel. i flipped a few bits in $01 to try using a sprite at $0300 and everything crashed up - so i'll have to learn some more about how to safely use that zp next
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
you dont have to "switch off" the basic or the kernal to use mem at $0300, the machine only crashed on you, since you fucked up the irq vectors at $0314-$0315, simply use a sei to avoid that, or turn off the kernal and basic rom by lda #$35 sta $01, and use fffe/ffff for irq vectors. |
| |
CyberBrain Administrator
Posts: 392 |
All this kefrensbars-talk, made me wonder if it could be done in 256b. So a lame 256b version has been made. |
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
@CyberBrain: it's good ! i like the sinus low 2-bits seperate from the upper part. probably an old idea but i didn't think of that...
i'm trying to make more complex movement now, trying to sum two different sin-tables when recalculating, and it's not going well.
6502 has no arithmetic shift right ?!? how can i >>1 a signed byte... in a reasonable time
|
| |
WVL
Registered: Mar 2002 Posts: 902 |
anix :
do a cmp #$80, then ror.
if the accu was negative, cmp #$80 will set the carry, and a ror will shift the carry into bit 7, so the result is still negative..
this is a common trick.
|
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
WVL: thanks for the tip, it works fine.
now i took two offset sin() and summed them together, so i can have some neat movement like hcl & xbow... but of course now my calculation is even slower.
it really sucks that all of the opcodes are so slow - you have to get some big gains from a table before they are worth it, since a big table will take your 4/5 cycles to hit... the only way i see to get back to a single frame now, is to put my spritedata in zero page.
anyone ever use S for an extra place to hold a val during IRQ instead of zero page? seems like nothing should be wrong with that... store S into zero page and restore it after the loop is done
|
| |
WVL
Registered: Mar 2002 Posts: 902 |
anix : maybe you should try to use some illegal opcodes.
see this page for a complete list :
http://oxyron.net/graham/opcodes02.html
anyway, while you're at it, please think about using 3 bytes for storing the bars, instead of 2. This will increase the width of the bars from 5 multicolor pixels to 9 multicolor pixels (almost double!), and it's rather cheap in cycles (only lda #$xx sta sprite).
You only need to store the middle byte directly, there's no need for 'and' and 'or'..
|
| |
anix Account closed
Registered: Feb 2004 Posts: 35 |
WVL: i've looked through the illegals, but they don't seem to do much for me. lax #imm could be fun but it says it's unstable. i saved a number of bytes last night be cutting my recalc loop in two... part1 creates a table of the new sinus (sin,x+sin,y) then part2 reads it and sets up the irq loop. this way, i didn't have to store my counters in zero page.
also copied my 4-byte ora/and tables (yours were exactly like mine, so i'm happy i figured that out :) into 256 byte tables, so that the pixel position doesn't have to be and #3 to get the right one.
next step is to dump my sin+sin table, and write those values directly into the second loop as ldx #$xx, but that won't really gain much.
wider bars will need more cycles in my irq loop that i don't have... |
| |
WVL
Registered: Mar 2002 Posts: 902 |
if the sprites are in zeropage, maybe you could use the illegals with &H -> when storing to zeropage, H=$ff so the &H does nothing. (If I'm not mistaking, don't kill me if I'm wrong ;)))
so you could do Store A and X to zeropage for almost free..
well, you figure it out if you want to show us how it's done ;D |
| |
CyberBrain Administrator
Posts: 392 |
Quote: @CyberBrain: it's good ! i like the sinus low 2-bits seperate from the upper part. probably an old idea but i didn't think of that...
i'm trying to make more complex movement now, trying to sum two different sin-tables when recalculating, and it's not going well.
6502 has no arithmetic shift right ?!? how can i >>1 a signed byte... in a reasonable time
anix: yeah, well, i only think that trick is clever when you don't use double sinus - it was just something i made up. I made a better 256byte version with double sinuses today, and i don't use that trick anymore. |