It is currently Wed Dec 13, 2017 9:59 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Oct 17, 2005 9:28 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
I believe Disch is the one who told me of this, but I've created a routine in 6502 that will load this map successfully. How the compression works:

Mapdata:
.db $85,$24

This is only part of the .db segment by the way. Okay, the decompression will read the first byte, and it will read that bit 7 is set, and it will then take the 2nd digit of the first byte, and that will be the number of times the following tile number will be displayed. So with just that, 24 will be displayed 5 times. Understand? Okay. Here we have more tiles, but these next ones are uncompressed tiles:

Mapdata:
.db $85,$24,$03,$45,$24,$59

Notice that the third byte says 03. It is set up so that if bit 7 is 0, then take the second digit, which is 3, and display the next 3 as uncompressed tiles. Understand? okay. Here's the decompression code:

Code:
namload:
   dec amount
it:
   lda mapdata,x
   bmi putit
   asl a
   asl a
   asl a
   asl a
   lsr a
   lsr a
   lsr a
   lsr a
   tay
   inx
putmore:
   lda mapdata,x
   sta $2007
   inx
   dey
   bne putmore
   inx
   lda #$00
   sta $2005
   sta $2005   
   rts

putit:
   asl a
   asl a
   asl a
   asl a
   lsr a
   lsr a
   lsr a
   lsr a
   tay
   inx
here:
   lda mapdata,x
   sta $2007
   dey
   bne here
   inx
   lda #$00
   sta $2005
   sta $2005
   rts


And amount is a variable that holds the amount of bytes are in the "mapdata" array/arrays. And in my quick demo, I just had it jsring to this routine until amount was 0. Tell me if you have any questions. Just thought I'd be somewhat helpful to people that were wondering about this.

Edit:
Also, another thing. This will be kind of confusing. You must set "amount" to equal as many different tile#'s there are minus two, not how many bytes there are.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 9:39 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
ASL x4, LSR x4? Any reason why you're avoiding AND?

Also, why only use the low 4 bits for the length? why not all 7?

You can push the 'here' label forward one line (after the LDA command) for a slight speed increase, since A nor X never change inside the loop, you don't have to keep reloading A every iteration.

Plus that seems like a very strange place to put your $2005 writes o_O

Looks like it'll work though =D. Although it seems to only want to decompress one "block" ($85,$24,$03,$45,$24,$59 --- it will stop [rts] after it does the $85 $24 .. is that what you want?)

Don't want to sound critical... just trying to offer optimization suggestions ^^. Call it a bad habit... I overanalyze things sometimes.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 9:56 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
It does work for me... I just wrote that today, so I will be making modifications to make it better. I'm surprised that it seems like it would work to other people. I really hate the and instruction. Okay, just so I'm getting this right, in the and instruction, isn't it like so:

0&0=0
1&0=0
0&1=0
1&1=1

Okay, so I could just change that aslx4 lsrx4 to and #$0F? Okay, so I'll do that. But how I use all 7 bits for the RLE method? I bet I could just have it say like:

if the first bit is 7
and #$0F
remainder=r
next byte=c
dipsplay the next r tiles c times

Mapdata:
.db $84,$FF,$31,$32,$33,$34

How does that sound? I think that's excellent. What do you think? that would completely fill the name table! That code up there would.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 10:02 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
AND is used for "flipping off" bits. When you want to ignore certain bits of a byte, you can use AND to mask them off. Simply AND with the bits you want to keep.

so AND #$0F will turn off the high 4 bits of A, leaving the low 4 bits in tact. AND #$7F will turn off only the high bit, leaving the low 7.

Conversely, ORA turns on certain bits. Just ORA with the bits you want to turn on. Like if you want to flip on the high bit, you could just ORA #$80.

EOR toggles bits. just EOR with the bits you want to be toggled. ie "EOR #$F0" will toggle the high 4 bits (0 becomes 1, 1 becomes 0), and will leave the low 4 bits unchanged.

As for using the low 7 bits... you wouldn't have to change anything in your code... except you'd AND with #$7F instead of #$0F (keep the low 7 bits instead of just the low 4). After that, A can be used as your length for the following loops


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 10:28 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
Okay, I haven't tested this yet, and I'm really not sure if this works, but it should. This could be the master RLE compression method! Here it is, study and see if you can get what I'm trying to do:

Code:
mapload:
   dec amount
here:
   lda mapdata,x
   pha
   inx
   lda mapdata,x
   tay
   inx
display:
   lda mapdata,x
   sta $2007
   dey
   bne display
   pla
   tay   
   cpy #$00
   bne gohere
   rts

gohere:
   dey
   inx
   tya
   pha
   rts
   
mapdata:
   .db $04,$FF,$39,$38,$37,$36


This really could be awesome! what do you think? I haven't tested it. There could be some awful error. Do you think it could work?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 10:37 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Celius wrote:
Code:
   pha
   rts




CRASH

The return address will be screwed if you leave stuff pushed on the stack... RTS will think the value you just pushed is the address to jump back to... and will jump to garbage code.

I don't see where you're seperating runs from non-runs... this code looks like it will treat EVERY block as a run... instead of looking at the high bit to see if it should run or not.

I think you were more on the right track with your first post's code. And hey, if that first posts code worked, then rock on. If it ain't broke, don't fix it. ;D


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 5:54 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
Celius wrote:
It does work for me... I just wrote that today, so I will be making modifications to make it better. I'm surprised that it seems like it would work to other people.


In this case it is not a matter of "working". The code may do what it is supposed to, but may be inneficient at that.

I would really like to agree with Disch when he says "If it ain't broke, don't fix it". In fact this logic works for most stuff, but in a machine as slow as the NES somethings can make quite a difference...

It certainly is much better to use 1 instruction (AND) instead of 8 (4 ASL + 4 LSR). And since your flag is only 1 bit (bit 7) it would be faster even if you did 1 ASL followed by 1 LSR.

Having more bits for the repeat count is good, as it can describe longer runs and improve the compression ratio. Compressing 127 bytes can only be better than compressing 15, right?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 8:33 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19341
Location: NE Indiana, USA (NTSC)
I've got some ready-made, working, tested (on NTSC NES hardware no less) RLE compression and decompression code in my NES tools package.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 8:55 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
I've already downloaded your NES tools package. I've been using name for making title screens. I like it quite a bit. But I revised my compression code, and it works good. I'll put it up, I'm not on my PC right now, so I have to put it up when I get to my PC. I prefer my compression method, I think it will do for now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group