6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 9:24 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Fri Oct 23, 2009 5:12 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Am using these pups for lights, using 32 variables and packing and unpacking them to 4 variable locations. hope someone can use these puppies. Enjoy!

Code:
; Takes bytes LightPackBytes0 to LightPackBytes3 and unpacks them to LightHardware bits
; 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9  8  7  6  5  4  3  2  1
; d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
; Byte 3                  Byte 2                  Byte 1                  Byte 0

UnpackLights
   LDY #$00   ; hardware 1-8
   LDX LightPackByte3
UnpackLights1
   TXA
   AND #$01
   STA LightHardware1,y
   TXA
   LSR
   TAX
   INY
   CPY #$08
   BNE UnpackLights1


   LDY #$00   ; hardware 9-16
   LDX LightPackByte2
UnpackLights2
   TXA
   AND #$01
   STA LightHardware9,y
   TXA
   LSR
   TAX
   INY
   CPY #$08
   BNE UnpackLights2            


   LDY #$00   ; hardware 17-24
   LDX LightPackByte1
UnpackLights3
   TXA
   AND #$01
   STA LightHardware17,y
   TXA
   LSR
   TAX
   INY
   CPY #$08
   BNE UnpackLights3


   LDY #$00   ; hardware 25-32
   LDX LightPackByte0
UnpackLights4
   TXA
   AND #$01
   STA LightHardware26,y
   TXA
   LSR
   TAX
   INY
   CPY #$08
   BNE UnpackLights4

   RTS


   

; PackLightBits
; places LightHardware into LightBytes 0-3
; 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9  8  7  6  5  4  3  2  1
; d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
; Byte 3                  Byte 2                  Byte 1                  Byte 0


PackLightBits
   STZ LightPackByte0
   STZ LightPackByte1
   STZ LightPackByte2
   STZ LightPackByte3
   LDY #$08

PackLightBits1
   LDA LightHardware1,y
   ORA LightPackByte0
   ASL

   DEY
   CPY #$00
   BNE PackLightBits1

   LDY #$10

PackLightBits2
   LDA LightHardware1,y
   ORA LightPackByte1
   ASL

   DEY
   CPY #$00
   BNE PackLightBits2

   LDY #$18

PackLightBits3
   LDA LightHardware1,y
   ORA LightPackByte2
   ASL

   DEY
   CPY #$00
   BNE PackLightBits3

   LDY #$20

PackLightBits4
   LDA LightHardware1,y
   ORA LightPackByte3
   ASL

   DEY
   CPY #$00
   BNE PackLightBits4

   RTS

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 23, 2009 11:43 pm 
Offline

Joined: Tue Nov 18, 2003 8:41 pm
Posts: 250
It lools like each LightHardwarex has it's individual byte address
and is controlled by bit zero ie one (byte) address one light
(else why pack and unpack)


Nightmaretony wrote:
Code:
 .
 .

UnpackLights
   LDY #$00   ; hardware 1-8
   LDX LightPackByte3
UnpackLights1
   TXA
   AND #$01
   STA LightHardware1,y
   TXA
   LSR
   TAX
   INY
   CPY #$08
   BNE UnpackLights1
 .
 .



One of those TXAs are redundant

Code:
   LDY #$00   ; hardware 1-8
   LDA LightPackByte3
UnpackLights1
   TAX
   AND #$01
   STA LightHardware1,y
   TXA
   LSR
   INY
   CPY #$08
   BNE UnpackLights1


You could get rid of the CPY #$08

Code:
   LDY #$F8   ; hardware 1-8
   LDA LightPackByte3
UnpackLights1
   TAX
   AND #$01
   STA LightHardware1+8,y
   TXA
   LSR
   INY
   BNE UnpackLights1


Unfortunately that almost guarantees a page crossing
while indexing.

You could work backwards through the bits

Code:
   LDY #$07
   LDA LightPackByte3
   ROL
UnpackLights1
   ROL
   TAX
   AND #$01
   STA LightHardware1,y
   TXA
   DEY
   BPL UnpackLights1


Nightmaretony wrote:
Code:
 .
 .

   LDY #$18

PackLightBits3
   LDA LightHardware1,y
   ORA LightPackByte2
   ASL

   DEY
   CPY #$00
   BNE PackLightBits3 .
 
  LDY #$20

 .
 .



Not sure I understand the intention here

It lools like you're trying to pack three bytes worth
in this loop.
(you LDY #$18 and you quit the loop when y reaches zero)
Presumably this should be LDY #$08 and the offset
should be in the indexed address, something like
LDA LightHardware1+18,y)

I don't see you saviing the packed byte.

DEY sets the zero flag so I think the CPY #$00 is redundant

Best be sure bits 1-7 of the LightHardwarex bytes are zero
(and not floating or pulled high 'cause they're unconnected)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 24, 2009 9:31 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
An utterly untested recursive pack/unpack.

Code:
Pack32:
  LDX #0
  LDY #0
  JSR $+3
  JSR $+3
  JSR PackBits
  INX
  RTS

PackByte:
  JSR $+3
  JSR $+3
  JSR $+3
  LDA Unpacked,Y
  INY
  ROR A
  ROR Packed,X
  RTS


Code:
Unpack32:
  LDX #0
  LDY #0
  JSR $+3
  JSR $+3
  JSR UnpackBits
  INX
  RTS

UnpackBits:
  JSR $+3
  JSR $+3
  JSR $+3
  LDA #0
  ROR Packed,X
  ROL A
  STA Unpacked,Y
  INY
  RTS

The last bit destroys the packed data as it unpacks it. It could be made to cycle the shifted bit back in to preserve it.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 24, 2009 11:38 am 
Offline

Joined: Tue Nov 18, 2003 8:41 pm
Posts: 250
BitWise wrote:
An utterly untested recursive pack/unpack.

Code:
Pack32:
  LDX #0
  LDY #0
  JSR $+3
  JSR $+3
  JSR PackBits
  INX
  RTS

PackByte:
  JSR $+3
  JSR $+3
  JSR $+3
  LDA Unpacked,Y
  INY
  ROR A
  ROR Packed,X
  RTS




oooh, I like that.
you are twisted :)
but don't you need to fix one of those labels?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 26, 2009 2:52 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
4 bytes actually, and you are correct Bogax in using bit 0 of the individual bytes as simple flags. There is only 32 flags, located at $10-$2f, so I am not concerned with page crossing for this routine.

the unpack already seems to work :) Have not tried the pack as of yet in practice.

also, the TXA is not redundant since I am preserving the packbyte. The first TXA masks out the single bit at the end and sends to the hardware location. It is pulled a second time and shifted for the next operation, being stored temporarily in the X register.

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 26, 2009 10:17 pm 
Offline

Joined: Tue Nov 18, 2003 8:41 pm
Posts: 250
Nightmaretony wrote:
4 bytes actually, and you are correct Bogax in using bit 0 of the individual bytes as simple flags. There is only 32 flags, located at $10-$2f, so I am not concerned with page crossing for this routine.

the unpack already seems to work Have not tried the pack as of yet in practice.


I didn't see anything wrong with your unpacking code.

For your packing code

You have four loops one for each byte you are packing,
but the second loop does 16 bits, the third loop does 24
bits (the three bytes worth I mentioned) and the fourth
loop does all 32 bits. They all return the same byte,
the first 8 flags, the rest get shifted out.

Quote:
also, the TXA is not redundant since I am preserving the packbyte. The first TXA masks out the single bit at the end and sends to the hardware location. It is pulled a second time and shifted for the next operation, being stored temporarily in the X register.



The TXA is redundant in that you can do it with only one TXA
by a slight modification.


As far as the page crossings, I was just pointing out that the
way I set up that loop has the disadvantage of increasing the
number of page crossings the indexing does.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 27, 2009 10:16 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Ah, I see my mistake now,. The LDY goes for each byte but the CPY 00 should increase by 8 for each time for 8 unpacks in a row. Missed that entirely. thanks!

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 28, 2009 9:16 am 
Offline

Joined: Tue Nov 18, 2003 8:41 pm
Posts: 250
Just for the hell of it I decided to do one in loops
to compare to BitWise' recursing.
Here's what I came up with (totally untested)

Code:
PACK
 ldy #$1F
 ldx #$03
LOOP_BYTES
 lda #$01
LOOP_BITS
 asl
 ora lites,y
 dey
 bcc LOOP_BITS
 sta packed,x
 dex
 bpl LOOP_BYTES
 rts


UNPACK
 ldx #$1F
 ldy #$03
LOOP_BYTES
 lda packed,y
 sec
 rol
LOOP_BITS
 rol lites,x
 dex
 asl
 bne LOOP_BITS
 dey
 bpl LOOP_BYTES
 rts


Edit: swapped x,y for unpack forgot you need x for an indexed rol


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 29, 2009 2:40 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Let me try testing that out in the next couple of days. If it works to spec, can I use it in the pinball programming? All it does is get ya a credit in the front end credit area though :)

With me, I do a most unsubtle programming style called "bull in a china shop" type of programming. It will get you there but smashes dishes and antiques along the way :D

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 29, 2009 8:49 pm 
Offline

Joined: Tue Nov 18, 2003 8:41 pm
Posts: 250
Nightmaretony wrote:
Let me try testing that out in the next couple of days. If it works to spec, can I use it in the pinball programming? All it does is get ya a credit in the front end credit area though :)


No problem.

But mine packs the bytes in reverse order to yours.
eg mine has lites 0-7 going into packed byte0

Also I used ORA to pack 'cause that's what you did.
However what I said previously still holds, bits 1-7 need to read
as 0 for that to work (which strikes me as unusual, I'd expect them
to be tied high or floating but I assumed you know what you are
doing better than I :) )

If bits 1-7 don't read as zeros but they do read the same on
succesive reads a couple cycles apart (like if thay're all tied high
or something) you could use EOR

Code:
PACK
 ldy #$1F
 ldx #$03
LOOP_BYTES
 lda #$01
LOOP_BITS
 asl
 eor lites,y
 and #$FE
 eor lites,y
 dey
 bcc LOOP_BITS
 sta packed,x
 dex
 bpl LOOP_BYTES
 rts


Actually if bits 1-7 always read the same maybe it
makes more sense to use an immediate for the first
EOR and leave out the AND so eg if bits 1-7 are all 1

Code:
PACK
 ldy #$1F
 ldx #$03
LOOP_BYTES
 lda #$01
LOOP_BITS
 asl
 eor #$FE
 eor lites,y
 dey
 bcc LOOP_BITS
 sta packed,x
 dex
 bpl LOOP_BYTES
 rts


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 29, 2009 10:10 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
the only reason I went numbering a little strange on the bits is to the pinball machine user, the self test and lights will be identified as 1-32. In digital, we know 0-31 which would create some confusion, so I opted to go that route for clarity in the code. ultimately, this will be a pinball machine for the home user and not a computer programmer at all.

The packbytes are used for convenience in loading a whole group instead of each bit at a time from a table. Attract mode or special It seemed to work out for loading as the one huge 32 bit setup, I think reversing the order may confuse me. will be playing with it to where I want it all. Thanks again for being able to make a single loop. I am not good enough to get that jump to your level of pulling that stunt. When I get there, I will rewrite my address test for the same sort when I can, unless oyu want to give it a shot. (tis in the code resources on here, am wanting this code in there as well :)





The ORA/LSR stunt is a condition byte trick to save conditional testing. If I have 8 1 bit variables to test or 4 1 bit and a nibble variable, I can do a single compare with that method. DCVLXII turned me onto it in here and I love that one :)

http://www.ipdb.org/showpic.pl?id=4116&picno=37355
here is a picture of it if I never showed it yet. It used a Fairchild F8. This is because of the very non availability of that part....

_________________
"My biggest dream in life? Building black plywood Habitrails"


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 18 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:  
cron