How to crunch cartridge images

Discuss anything related to the VIC
Post Reply
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

How to crunch cartridge images

Post by nbla000 »

Hi.
I've tried to crunch some cartridge image with Pucrunch using this command:

PUCRUNCH -C20 ImageA0.prg ImageCR.prg

but pucrunch says:
"Original file exceeds 0x8000 (0xbfff), not a valid VIC20 file!

Actually the cartridge image is of 8194 bytes.

I've tested with the -d option (data), Pucrunch works but says:
"Runnable on VIC20 with 3k+8k (or 3k+16k, or 3k+24k) expansion memory

In any case doesn't work on Vic.

What does do this Pucrunch option?
a avoid video matrix (for VIC20)
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Why would you crunch a cartridge image? What Pucrunch means is that the program is located at an address higher than 32768 ($8000). You may transfer the cartridge image to e.g. $2000 and write a small routine to relocate it back to $A000:

Code: Select all

      ldx #$20
      stx $fc
      lda #$a0
      sta $fe
      ldy #$00
      sty $fb
      sty $fd
loop: lda ($fb),y
      sta ($fd),y
      iny
      bne loop
      inc $fc
      inc $fe
      dex
      bne loop
      jmp $fd22 ; or whatever startup routine
Then Pucrunch will accept the whole kaboodle.

The -a option makes Pucrunch avoid the video matrix ($1E00-1FFF) on unexpanded VIC-20. Usually it would use it for temporary storage, so you get a bit of garbage on screen while uncrunching. If you prevent it from using it, some unexpanded 4K programs may be impossible to crunch.
Anders Carlsson

Image Image Image Image Image
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

carlsson wrote: Why would you crunch a cartridge image?
i want to fast load images from floppies and add more images to a single disk

My Work:
On vice (Vic memory blocks 1,2,3,5)
LOAD "IMAGEA0",8,1 (8194 bytes)
in the Monitor
MOVE $A000 $BFFF $2000 (8192 bytes ?!?)
SAVE "IMAGE20" 8 $2000 $3FFF
now with Pucrunch:
pucrunch IMAGE20.prg IMAGE20C.prg -c20 -x$2000
on vice (Vic memory blocks 1,2,3,5) again
LOAD"IMAGE20C",8,1
RUN
now in $2000 i've the cartridge to move in $A000
LOAD"20TOA0",8,1 (see code below)
SYS5120
the routine works and soft-reset the vic but the game doesn't start.
in the monitor on $a000 there isn't the same code of $2000
so manually MOVE $2000 $3FFF $A000
and after
SYS64802
and now works.

what's wrong in my routine?

Code: Select all

1400   A2 20      LDX #$20
1402   86 FC      STX $FC
1404   A9 A0      LDA #$A0
1406   85 FE      STA $FE
1408   A0 00      LDY #$00
140a   84 FB      STY $FB
140c   84 FD      STY $FD
140e   B1 FB      LDA ($FB),Y
1410   91 FD      STA ($FD),Y
1412   C8         INY
1413   D0 F9      BNE $140E
1415   E6 FC      INC $FC
1417   E6 F6      INC $F6
1419   CA         DEX
141a   D0 F2      BNE $140E
141c   4C 22 FD   JMP $FD22
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

nbla000 wrote: what's wrong in my routine?

Code: Select all

1417   E6 F6      INC $F6
... should be ...

Code: Select all

1417   E6 FE      INC $FE
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Also, you may want to locate this snippet of code to e.g. $1FE0, save it together with the relocated cartridge image and set that address as execution. It would mean after decrunching, the transfer routine would start immediately and then boot the cartridge image.

It is probably rather easy to hack Pucrunch (the source is out there) to accept VIC programs exceeding $8000, or at least binary patch the decruncher:

1. Transfer cartridge image from $A000 to $2000
2. Run PuCrunch, choose execution address $FD22 (reset)
3. Manually adjust decruncher to store data at $A000 instead of $2000
Anders Carlsson

Image Image Image Image Image
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Code: Select all

1417   E6 FE      INC $FE
OPS... i've reread this code at least 10 times.....
3. Manually adjust decruncher to store data at $A000 instead of $2000
It's relatively simple, you may modify one byte from $20 to $A0 in a specific memory location and save again the program (another step) or just a POKE before RUN.

Normally you preserve about 25% of space and 15/20% of time loading (From LOAD to the effective start).

In any case after experiments i think that the best way is to to modify Pucrunch to accept VIC programs exceeding $8000 for 2 reasons:

1) Because Pucrunch doesn't accept programs exceeding $8000 you need an additional step, to transfer cartridge image from $A000 to $2000 using the Vice monitor or other tools

2) When you load the crunched image you need 16K, 8k in bank 1 and 8k in bank 5 instead of 8k in bank 5 only because the crunched file is stored at bank 1 $2000 and decrunched in bank 5 $A000

Unfortunately i'm not a C programmer, someone want to make some adjustment to Pucrunch Source ?
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

I think you'll get the best result using the stand alone decruncher (sa_uncrunch.asm).
There is no overlap between the source and destination areas, so you don't need all the fancy copy to stack code and such.
Just crunch with the "-c0" option to get raw packed output, and then link it manually to sa_uncrunch.asm.
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

tlr wrote:Just crunch with the "-c0" option to get raw packed output, and then link it manually to sa_uncrunch.asm.
OK, now i've the crunched raw data

pucrunch ImageA0.prg ImageCR.prg -c0 -x64802

But what means link it manually? I need to compile sa_uncrunch.asm and how?

Sorry i'm not so expert to understand what you mean, there is a compiled Vic-20 version of the standalone decruncher? If yes, how does it work?
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

nbla000 wrote:
tlr wrote:Just crunch with the "-c0" option to get raw packed output, and then link it manually to sa_uncrunch.asm.
OK, now i've the crunched raw data

pucrunch ImageA0.prg ImageCR.prg -c0 -x64802

But what means link it manually? I need to compile sa_uncrunch.asm and how?
Yes, you need to modify sa_uncrunch.asm slightly so that it has a sys-line, and then assemble it using dasm.

It can quite easily be done in such a way that allows concatenating any packed cartridge data straight onto the assembled uncruncher.

If you do not know enough assembly, I'm sure someone here wants to help you out. :)
Post Reply