Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Getting 5-bit data
2010-12-02 14:30
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Getting 5-bit data

I am working on a little something for a 6502-based system (no, not a C64, but the best coders hang here so... :D)

I have about 200 bytes to store some scrolltext in, and got the bright idea that storing the text as 5-bit data would yield me 320 characters of text instead!

The problem though is that when I started writing the code to actually "unpack" the 5-bit data, I ended up wasting more than the 120 bytes that I won...

Any bit-magician who can figure out a compact way of getting a 5-bit data, and without using self-modifying code (since this is a ROM-based system...)

I would ideally want to do something like this

	lda #$00
	sta SCROLLPOS
	...
	
	
Mainloop:	
	jsr Get5Bit
	...
	
	
Get5Bit:
        ldy SCROLLPOS
	lda scrolltext,y
	// Do magic
	// if necessary increase Y and store in SCROLLPOS	
	..
	rts
	
	
		
scrolltext:
		(5-bit data packed into 8-bit bytes here)


-edit-
Removed unnecessary ZP-inderection stuff
 
... 10 posts hidden. Click here to view all posts....
 
2010-12-05 10:52
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Here's my final version that I used in the code:

get5bits:
	lda #$00
	sta TMPBYTE1		
	ldy #$05
!loop:	
	lda BITCOUNT
	bne !skip+
	ldx SCROLLPOS
	lda scrolltext,x
	sta TMPBYTE2
	inx
	stx SCROLLPOS	
	lda #$08
	sta BITCOUNT
!skip:
	asl TMPBYTE2
	rol TMPBYTE1
	dec BITCOUNT
	dey
	bne !loop-	
	lda TMPBYTE1
	rts


36 bytes if I counted it correctly.
2010-12-05 21:24
JackAsser

Registered: Jun 2002
Posts: 2014
get5bits:
	lda #$00
	ldy #$05
!loop:
	asl TMPBYTE2
	rol
	dec BITCOUNT
        bne !skip+
	pha
        ldx SCROLLPOS
	lda scrolltext,x
	sta TMPBYTE2
	inc SCROLLPOS	
	lda #$08
	sta BITCOUNT
        pla
!skip:
	dey
	bne !loop-
	rts


30 bytes... linear bit order.
2010-12-05 21:36
JackAsser

Registered: Jun 2002
Posts: 2014
I'm perhaps a bit too tired now but this might work:

get5bits:
	lda #%00001000
!loop:
	asl TMPBYTE2
	dec BITCOUNT
        bne !skip+
        ldx SCROLLPOS
	ldy scrolltext,x
	sty TMPBYTE2
	inc SCROLLPOS	
	ldy #$08
	sty BITCOUNT
!skip:
        rol
        bcc !loop-
	rts


25 bytes.
2010-12-07 08:52
Slammer

Registered: Feb 2004
Posts: 416
15 bytes : 280 Chars Scroll
2010-12-07 12:36
terric
Account closed

Registered: Feb 2009
Posts: 47
Well, now you got me tempted and also you got my brain going for some coding.(Really should study) ;) I did a byterunner attempt, it does benefit from languages using same charachters twice or more, and some spaces in scroller does shrink to a nice size. ;)
2010-12-07 13:04
enthusi

Registered: May 2004
Posts: 677
well, so far the codes can handle generic texts.
Not sure if much could be safed if you know the text in advance. Surely for 1024KB but in 256B? I have my doubts :)
2010-12-07 15:13
WVL

Registered: Mar 2002
Posts: 902
Well.. how short can you write a huffman decoder? :)
2010-12-07 18:45
Mace

Registered: May 2002
Posts: 1799
enthusi, WVL: my thoughts exactly...
2010-12-08 01:07
Fresh

Registered: Jan 2005
Posts: 101
@Slammer
First of all nice routine!
I managed to get room for 8 more characters to play with for a total of 288.
I'm too lazy to regenerate the encoded text so I've only added some dots.

(Updated on 9/12: now 296 chars and free color choice)

*= $0326	

packedbytes	equ $B9

.word start
.word $F6ED

data=*-1
.byte  $5D,$B5,$25,$25,$D5,$DB,$FF,$79,$5B,$FD,$21,$3B,$51,$85,$3B,$E7
.byte  $77,$77,$3B,$23,$FF,$CD,$BB,$BB,$CF,$57,$55,$DF,$77,$55,$A9,$FF
.byte  $E7,$67,$31,$A1,$ED,$09,$1B,$E5,$F7,$FF,$F5,$D5,$F7,$CD,$9F,$69
.byte  $49,$59,$65,$21,$9B,$01,$67,$BB,$3F,$4D,$A5,$91,$29,$6E,$03,$F3
.byte  $19,$9B,$69,$AD,$A9,$0B,$3F,$12,$1B,$1B,$3D,$57,$F7,$D7,$4F,$1F
.byte  $8F,$2E,$41,$11,$AB,$6D,$FE,$AB,$A7,$31,$63,$6E,$CD,$57,$71,$95
.byte  $74,$47,$0C,$F4,$91,$84,$FB,$82,$84,$CC,$29,$E9,$D9,$8C,$79,$4B
.byte  $75,$61,$41,$1E,$33,$BB,$3E,$16,$F3,$F2,$45,$61,$44,$3C,$28,$7A
.byte  $B9,$2C,$EB,$CC,$83,$83,$E0,$94,$75,$FD,$F6,$14,$7C,$12,$26,$07
.byte  $48,$AA,$ED,$F4,$A6,$E1,$FF,$E7,$4F,$4F,$D7,$75,$D4,$88,$80,$29
.byte  $5A,$AA,$FF,$72,$02,$80,$2E,$99,$89,$96,$D0,$58,$F9,$C3,$C8,$FF
.byte  $00,$FF,$FF,$FF,$FF,$00,$FF,$FF,$FF

start
		LDX #packedbytes
		SEI	
loop
		LDA #$07	; #$87/#$07	slow/fast
waitr   
		CMP $D012	
		BNE waitr
		SBC #$01
		AND #$87
		STA $d016
		BCS waitr	; BMI/BCS	slow/fast
		
copychar		
		LDA $05E1,Y	
		STA $05E0,Y	
		LDA #$0F	; Selectable color
		STA $D9E0,Y
		INY 	
		BNE copychar	
		
		LDA #$08
inner		
		ASL data,x	
		BCC zero
		INC data,x	
zero		
		ROL 
		DEX 	
		BNE skipreset
		LDX #packedbytes
skipreset				
		BCC inner	
		ADC #$00		
		CMP #$1E	
		BNE skipdot
		LDA #$2E
		STA $D021	
skipdot
		STA $0607	
		BNE loop
			



2010-12-12 10:18
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Nice to see that a simple question can turn into a good old coders competition! :)

Btw. here is the resulting product for which I originally asked.
Atari VCS, 128 bytes RAM, 4kB ROM cartridge...
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Holy Moses/Role
/Panor..
iAN CooG/HVSC
deetsay
DJ Space
Unicorn/TWA
t0m3000/hf^boom!^ibx
Guests online: 134
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Logo Graphicians
1 t0m3000  (10)
2 Sander  (9.8)
3 Mermaid  (9.5)
4 Facet  (9.4)
5 Shine  (9.4)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.043 sec.