Jump to content

Planet Bob

  • entries
    430
  • comments
    1,870
  • views
    659,797

Code escapes from Cartridge!

Sign in to follow this  
Cybergoth

292 views

Hi there!

 

Uihjah!

 

Remember that small snippet from yesterday? Besides calling half a dozen reset routines from the kernel and the BASIC interpreter, it basically just copies the first two bank 1 pages into the C64 RAM. Then it jumps there and does something rather unusual (at least for the VCS programmer ;)):

 

It switches through all four banks, copying all content of the cartridge into the C64 RAM, creating a solid 28K block of ROM. If you ever tried booting the Park Patrol cartridge in VICE, you may have noticed that it starts with a black screen, unexpectedly saying "Loading". So that's precisely what it really does then! :-o

 

Here's where the contents get copied:

  • $9000-$9FFF from Bank 1 goes to $5000-$5FFF
  • $8000-$9FFF from Bank 2 goes to $6000-$7FFF
  • $8000-$9FFF from Bank 3 goes to $8000-$9FFF
  • $8000-$9FFF from Bank 4 goes to $A000-$BFFF

Notice something? Bank 3 goes to $8000! That's where I said the cartridge is residing! Huh?!?

 

Well, actually no big deal. The C64 is a pretty smart machine. It has a full 64K of RAM. When you write to an area where a ROM block is active, all writes will still go through to the RAM *under* the ROM. (Reading there still means reading from the ROM.)

 

What puzzles me though, is: Why is the content of bank 3 *copied* there?

- It could've just switched to bank 3 to get the content of bank 3 there in no time!

 

Well, Ok, maybe for some selfmodifying code. (Or just making it easier for Crackers to copy the game onto disk, making 'em no worries over the bankswitching... :ponder: :lol:)

 

Remember another thing I said about bank 3 yesterday? Yup, it's the other one with starting code! Hm... well, I bet the game *is* started there, but why does it need a cartridge boot signature? Only thing I can think of right now, is that it is required for a warm start. To start it now after the copying sequence, all it requires is to jump there after activating RAM at $8000 again.

 

I think that is exactly what it does at the end of the copying routine:

	lda #$2F
	sta $00
	lda #$36
	sta $01
	jmp J_8009; $8009

 

I'm not C64 expert enough to fully understand this. Location $00 is the data direction register of the 6510. AFAIK is #$2F the default value, so I could imagine that this turns the cartridge off. Location $01 handles which parts of the multi-layered memory map are active. What I definitely can say is that it does switch from the BASIC interpreter ROM to the RAM residing there, which makes sense as the loader code just copied the 4th Park Patrol bank there ;)

 

Interesting note at this point: It seems as if the remainder of the first 4K of the first bank contains just unused garbage. Also interesting: The *used* 4K are almost completely filled with alternating $00 and $FF pages... Hm... :?

 

My next task will be constructing a working PRG file, by combining all info bits I found out so far. Halfway as a proof of concept of all my theories so far and halfway to have a compiling and working game source in hands to toy with :)

 

Greetings,

Manuel

Sign in to follow this  


2 Comments


Recommended Comments

If the game was available on disk and tape as well, then it seems absolutely logical to copy everything from ROM into RAM first.

 

EDIT: The 4k garbage could be hires graphics, sprites or something like that and $FF/$00 maybe color values. :party:

Share this comment


Link to comment
If the game was available on disk and tape as well, then it seems absolutely logical to copy everything from ROM into RAM first.

 

I see that it makes sense when it was developed as a disk/tape game. But why release it on Cartridge at all then? :party:

 

I think you're definitely right though: Even the cartridge game will store its settings on a disk and of course it can only read back into RAM! ;)

 

Also interesting, I had a quick look into the D64 version. It seems there the game is packed, because the main portion is even smaller than the 28K binary I'm currently trying to create.

 

EDIT: The 4k garbage could be hires graphics, sprites or something like that and $FF/$00 maybe color values. :party:

 

I'll dig further into this. Wether the garbage was required or not, will be revealed quickly when I try starting the game without :D

I thought the $00/$FF 4K might somehow initialize the area where the game will later point the VIC to for its graphics RAM.

Share this comment


Link to comment
Guest
Add a comment...

×   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...