Jump to content
IGNORED

mirroring a bit pattern


Heaven/TQA

Recommended Posts

We can improve that routine by getting rid of the Y register
Eh? You've changed its functionlity?

 

That routine was a bit pair swapper, yours is for single bits.

The Combat code was:

 

CreateFlipTable:

LDX     #0

@1:

TXA     

LDY     #7

@2:

ASL     A

ROR     $80

DEY     

BPL     @2

LDA     $80

STA     $600,X

INX     

BNE     @1

RTS

So yes, you do save on that ;)

 

I did think to change the bit pair version to not use the zero page temp register.

 

CreateFlipTable: 

  LDX     #1 

@1:

  TXA      

  LDY     #3 

@2:

  ASL     A 

  PHP      

  ASL     A 

  ROR     FlipTable 

  PLP      

  ROR     FlipTable 

  DEY      

  BPL     @2 

  LDA     FlipTable 

  STA     FlipTable,X 

  INX      

  BNE     @1

  STX     FlipTable

  RTS

Link to comment
Share on other sites

Actually, it shouldn't work (because the bottom DEY should be DEX...right?)

 

yep, absolutely right Nukey - thanks. How could I miss that? In such a small piece of code too! - now you know one reason why I don't normally post much :lolblue:

(even preview is no help for some people!)

 

this code might actually work...

 


 ldx #0

?1

 stx mirror_this



 ldy #8

?2

 asl mirror_this

 ror a



 dey

 bne ?2



 sta mirror_table,x



 dex

 bne ?1



 

mirroring 2 bit pixels - trickier, but more interesting - I'll have to look back at some of my code on how I did that - don't think it's as elegant as these though, as it wasn't a time critical routine :)

Link to comment
Share on other sites

6502 maniacs... i try to improve schmutzpuppe's trackball ballcode without the use of a lookup table...

 

he used a strange (but working... :D)  piece of code to mirror the bitpattern of the ballsprite...  of course i could use a pre generated lookup table but i am sure you could do this with some clever bit manipulations...

 

any help here? thomas? manuel?

 

...or perhaps...Andrew?

 

I assume there are 4 pairs of bits, and the bit pairs need to be reversed.

Place the byte to reverse in accumulator, and repeat the following code 4 times (either inline, or loop)...

 

ror temp

rol

rol temp

cmp #128

ror temp

ror temp

asl

 

The last 'asl' can be discarded if code is inline. This should reverse a byte's bits from ABCDEFGH to GHEFCDAB. Inline, it would take 118 cycles, 47 bytes total... ouch! Warning: untested code!

 

Cheers

A

Link to comment
Share on other sites

   ror temp

   rol

   rol temp

   cmp #128

   ror temp

   ror temp

   asl

 

If the code is inline, the first 'ror temp' can also be dropped...

thus the total conversion code is ...

 

rol

rol temp

cmp #128

ror temp

ror temp

asl

 

ror temp

rol

rol temp

cmp #128

ror temp

ror temp

asl

 

ror temp

rol

rol temp

cmp #128

ror temp

ror temp

asl

 

ror temp

rol

rol temp

cmp #128

ror temp

ror temp

 

 

Cheers

A

Link to comment
Share on other sites

We can improve that routine by getting rid of the Y register
Eh? You've changed its functionlity?

 

Okay, my mistake, but I think you should still get rid of using Y as your loop counter and instead use a bit flag in A rotated into Carry as your loop exit test:

 


CreateFlipTable: 

  LDX     #0 

@1:   LDA     #$80      

  STX     byte_0_A8 

@2:   ASL     byte_0_A8 

  PHP      

  ASL     byte_0_A8 

  ROR     A

  PLP      

  ROR     A      

  BCC     @2 

  STA     FlipTable,X 

  INX      

  BNE     @1 

  RTS     

Link to comment
Share on other sites

...i need 8bit "swapper"...

ABCDEFGH -> HGFEDCBA

 

Right?

 

Yes, that was the original request. Apparently, there is also a use in Atari 8-bit programming to be able to do this:

 

ABCDEFGH - > GHEFCDAB

 

For multi-colored backgrounds and such. The 2 discussions got wrapped around each other.

Link to comment
Share on other sites

thomas, you are right, this was my intitial request...

Are you looking for creating a table or an on the fly solution? Or a compromise? :?

I think it doesn't make a differnce because it should be easy to modify a "table create" code to an "on the fly" version and vice versa.

If I understand it correctly the main question was about how to reflect a byte as effective as possible.

Link to comment
Share on other sites

thomas, you are right, this was my intitial request...

Are you looking for creating a table or an on the fly solution? Or a compromise? :?

I think it doesn't make a differnce because it should be easy to modify a "table create" code to an "on the fly" version and vice versa.

If I understand it correctly the main question was about how to reflect a byte as effective as possible.

 

This is pretty easy: repeat the following 8 times...

 

lsr

rol temp

 

 

After 8 of those, temp holds the reflected value of what was in A, and A is 0. Essentially you're rolling bits off the right side of A, and onto the left side of temp... reversing the order.

 

Cheers

A

Link to comment
Share on other sites

This is pretty easy:  repeat the following 8 times...

 

   lsr

   rol temp

   

 

After 8 of those, temp holds the reflected value of what was in A, and A is 0.  Essentially you're rolling bits off the right side of A, and onto the left side of temp... reversing the order.

Yup, that's why I was asking.

 

Doing this on the fly costs at least 7*8=56 cycles (unrolled loop) or about 10*8+5 = 85 cycles (loop). Using a table however will be significantly faster, but use a lot of memory.

 

Combining both (e.g. using two nibble tables and OR them) will use less memory than the table approach and less time than the on the fly solution.

 

So, whatever you choose depends on the situation.

Link to comment
Share on other sites

thankS!!!1 i think now i got this simple task... lsr + rol.

 

1st i wanted to keep trackball into 4k... but now it will be a "fullprice" game hence 64k game... so for the 4k version i would like to have a small code maybe "real time solution".

 

the levels will be now created from char-tiles full screen size...

the level editor will be published to the public as i am not gonna make levels...

 

the levels will be flashpacked and depacked every level start so the scroll engine will be now easier and more 800er like... so the only scrolling overhead will be the parallax effect but not the "genereting" tile lines each 8th frame...

 

more to come later this weekend....

Link to comment
Share on other sites

Heaven 1st i wanted to keep trackball into 4k... but now it will be a "fullprice" game hence 64k game
That's what I like to see :) a full fat game.

 

the levels will be now created from char-tiles full screen size
Nice

 

the level editor will be published to the public as i am not gonna make levels...
8)

 

the levels will be flashpacked and depacked every level start so the scroll engine will be now easier and more 800er like... so the only scrolling overhead will be the parallax effect but not the "genereting" tile lines each 8th frame...
Great stuff, very interested to see the code in all that.

 

more to come later this weekend....
Look forward to it.
Link to comment
Share on other sites

i am just back from 2 hours star wars battlefront on my xbox... so now i am relaxed... damned rebel separatists... ;) dark side ruleZ!

 

i just recieved 3 tilesets for the level gfx so now i am starting to put a demo in with the new gfx set and rewrite the scroll engine for phat levels... ;)

 

i still gonna need the double buffer approach as for the parallax effect...

 

stay tuned...

Link to comment
Share on other sites

ok... after 2 hours little coding & converting...

 

1) implementation of rob's mirrow code

2) dummy level genrator written in turbo basic xl

3) new scroll engine

 

next 1st joystick routine just to get a feeling for the level size...

at the moment its 5x screens tall... = 4800 bytes unpacked...

 

 

the tile set is called "bubble" and was made by stefan aka retrofan... thanks mate!!! gimme more...

 

 

 

here is the level generator...

 


10 REM TRACKBALL LEVEL EDITOR

20 OPEN #1,4,0,"H:BUBBLE.FNT"

30 BGET #1,$6000,1024

40 CLOSE #1

50 GRAPHICS 12+16

55 SCR=DPEEK(88)

60 POKE 756,$60

70 LEVEL=$8000

80 FOR L=0 TO 3

90   GRAPHICS 12+16

95   POKE 756,$60

100   SCR=DPEEK(88)

110   EXEC FILL

120   MOVE SCR,LEVEL,960

130   LEVEL=LEVEL+960

140 NEXT L

800 OPEN #1,8,0,"H:LEVEL.DAT"

810 BPUT #1,$8000,3840

820 CLOSE #1

999 END 

1000 PROC FILL

1010   REM DRAW 10 PLATFORMS

1020   I=0

1030   REPEAT 

1040     X=RAND(36)

1050     Y=RAND(23)

1060     B=RAND(30)

1070     H=RAND(8)

1075     ------------------------------

1080     REM NOW DRAW

1090     POKE SCR+X+Y*40,1

1091     POKE SCR+X+(Y+H+1)*40,3

1100     FOR J=1 TO B

1110       POKE SCR+X+J+Y*40,6

1111       POKE SCR+X+J+(Y+H+1)*40,9

1120     NEXT J

1130     POKE SCR+X+Y*40+J,2

1131     POKE SCR+X+J+(Y+H+1)*40,4

1140     FOR J=1 TO H

1150       POKE SCR+X+(Y+J)*40,7

1155       POKE SCR+X+(Y+J)*40+B+1,8

1160       FOR A=1 TO B

1170         POKE SCR+X+A+(Y+J)*40,5

1180       NEXT A

1190     NEXT J

1200     I=I+1

1210   UNTIL I=10

1299 ENDPROC 

trackb4.zip

post-528-1096739308_thumb.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...