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 > Cartridge - C64 Game System, System 3 Memory Management
2016-08-18 16:37
TWW

Registered: Jul 2009
Posts: 541
Cartridge - C64 Game System, System 3 Memory Management

Does these cartridges allow memory management in terms of normal ROM/RAM/IO? I.E. Can I use the RAM under $a000-$bfff, $d000-$dfff and $e000-$efff?

Reason I ask i coz I made a frame for this cartridge in CRT format and it loads and executes fine. However I am only able to access ROM and IO.

http://vice-emu.sourceforge.net/vice_15.html#SEC319
2016-08-18 16:48
chatGPZ

Registered: Dec 2001
Posts: 11126
works exactly the same as with a regular 8k Game cartridge
2016-08-18 17:40
TWW

Registered: Jul 2009
Posts: 541
Please help me get some clarification;

15.11.3.1 0 - Normal cartridge

Size 8Kb
GAME active (1)
EXROM inactive (0)
Load address $8000-9FFF

15.11.3.16 15 - C64 Game System, System 3

Size 512Kb (64 banks of 8Kb each)
GAME inactive (0)
EXROM active (1)
Load address $8000-9FFF (all modules)

The GAME/EXROM lines are inverted. From what I understand is that the System 3 cartridge uses the ultimax format which is crypticly described as "open" (as opposed to "RAM") in the programmers ref. manual. so I am curious what exactly this means?
2016-08-18 18:20
JackAsser

Registered: Jun 2002
Posts: 1989
Tww: just check https://www.c64-wiki.com/index.php/Bank_Switching specifically the mode table section
2016-08-18 19:34
Mr. SID

Registered: Jan 2003
Posts: 421
I find this easier to read than the mode table:

http://www.harries.dk/files/C64MemoryMaps.pdf

Btw, the better option is to use the EasyFlash format, because it's a more powerful and flexible standard.
2016-08-18 20:27
TWW

Registered: Jul 2009
Posts: 541
Yes, it's the same table you guys show and it's based on the C64 Prog. Ref. Man. info.

Basically if EXROM is high and GAME is low, you are in ultimax mode and the loram/hiram get's ignored. In fact the only C64 RAM memory available is from $0000 to $0fff and everything else is hidden from the CPU except the cartridge @ $8000 (or $e000 or both).

Assuming I haven't misunderstood this completely, how does games based on the System 3 cartridge format (like "last ninja 3 remix") manage in this mode? Something is missing.
2016-08-18 20:47
chatGPZ

Registered: Dec 2001
Posts: 11126
*both* carts use regular 8k mode, not ultimax (i havent seen a game cart that uses that, except the actual ultimax carts) - the years old VICE doc you are looking at is simply wrong. (also generally those flags for GAME and EXROM in crt images is pretty meaningless, and emulators ignore them anyway - its a relict from the days when ppl thought a generic cartridge emulation could handly all the different cartridges) if you want to see how a certain cartridge works, its a much better idea to look at the actual VICE source, it usually contains a short description: https://sourceforge.net/p/vice-emu/code/HEAD/tree/trunk/vice/sr..
2016-08-19 03:57
TWW

Registered: Jul 2009
Posts: 541
Alright GPZ, I will check out the source when I sober up, meanwhile, here is the simple frame-setup (I checked it with a hex-editor and it's identical headers for the cartridge and the chips to the original described in the docs):

    /*---------------------------------------------------------

        C64 Game System Cartridge, System 3
          512Kb (64 banks a 8Kb located at $8000-$9fff)

        Cartridge Header File is set up 100%, no need to touch.
        Chip Header File needs to be repeated for each chip
          only update is 'CartridgeChipNumber' which is updated
          automatically when the header data is copied into the
          chip in question.

        Bank switching:
          Write to address $de00 + x, where x is the bank number.

        Kickass Compiling:
          -aom
          -binfile
          -maxaddr -1
          Output as "file.crt"

        VICE Autostart:
          x64sc.exe -cartcrt "${outputFilePath}"

    ---------------------------------------------------------*/


    // Functions
    // ------------------------

    .function _SwitchEndian16(argument) {
        .return floor(argument / $100) + floor([argument/$100-floor(argument / $100)]*256)*256
    }
    .function _SwitchEndian32(argument) {
        .return floor(argument / $1000000) + [floor(argument / $10000) - floor(argument / $1000000)*256]*256 + [floor(argument / $100) - floor(argument / $10000)*256]*$10000 + [argument - floor(argument / $100)*256]*$1000000
    }

    // Variables
    // ------------------------

    .var i                     = 0

    // Cartridge Parameters
    // ------------------------

    // Cartridge Header File
    .const CartridgeHeaderSize     = $40                  // #$40 is default Double Word (Big endian)
    .const CartridgeVersion        = 1.000                // High/Low Order Fixed Point Word
    .const CartridgeType           = 15                   // 15 = C64 GS System 3. Word (Big Endian)
    .const CartridgeEXROM          = 1                    // 0 = Inactive & 1 = Active.
    .const CartridgeGAME           = 0                    // 0 = Inactive & 1 = Active.
    .const CartridgeName           = "C64GS C"            // Maximum 32 bytes.
    // Chip Header File
    .const CartridgeChipHeaderSize = $10                  // Size of Bank Header Integer (#$10 is default)
    .const CartridgeChipSize       = $2000                // Size of Cartridge Banks Integer
    .const CartridgeChipType       = 0                    // 0 = ROM, 1 = RAM, 2 = Flash. Word (Big Endian)
    .var CartridgeChipNumber       = 0                    // ID Number for the Chips
    .const CartridgeLocation       = $8000                // Cartridge ROM address on the C64 Word (Big Endian)

    // Cartridge Header File
    // ------------------------

    .pc = $0000 "Cartridge Header"
    .text "C64 CARTRIDGE   "
    .dword _SwitchEndian32(CartridgeHeaderSize)
    .byte CartridgeVersion, round([CartridgeVersion-floor(CartridgeVersion)]*1000)
    .word _SwitchEndian16(CartridgeType)
    .byte CartridgeGAME
    .byte CartridgeEXROM
    .fill 6,0
    .text CartridgeName
    .byte $61,$72,$74,$72,$69,$64,$67,$65  // Ugly hack due to string handling...
     .fill 32-CartridgeName.size()-8,0


    // Chip Header File - 01
    // ------------------------

    .text "CHIP"
    .dword _SwitchEndian32(CartridgeChipHeaderSize + CartridgeChipSize)
    .word _SwitchEndian16(CartridgeChipType)
    .word _SwitchEndian16(CartridgeChipNumber) .eval CartridgeChipNumber++
    .word _SwitchEndian16(CartridgeLocation)
    .word _SwitchEndian16(CartridgeChipSize)


!Begin:

    .pseudopc CartridgeLocation {

        .word CartridgeColdStart
        .word CartridgeWarmStart
        .byte $c3, $c2, $cd, $38, $30  // CBM80

    CartridgeColdStart:
    CartridgeWarmStart:
        sei
        lda #$35
        sta $01
    !:  inc $d020
        jmp !-
    }

!End:
    .fill CartridgeChipSize - [!End- - !Begin-], $00


    .for (i = 0 ; i < 127 - CartridgeChipNumber ; i++) {
        // Chip Header File - NN
        // ------------------------

        .text "CHIP"
        .dword _SwitchEndian32(CartridgeChipHeaderSize + CartridgeChipSize)
        .word _SwitchEndian16(CartridgeChipType)
        .word _SwitchEndian16(CartridgeChipNumber) .eval CartridgeChipNumber++
        .word _SwitchEndian16(CartridgeLocation)
        .word _SwitchEndian16(CartridgeChipSize)

    !Begin:
        .byte $00
    !End:
        .fill CartridgeChipSize - [!End- - !Begin-], $00
    }



Runs perfectly but only problem is how do I access RAM under $a000 or $e000 (when I enter monitor, I only see C64 ROM @ these locations when CPU is banked (meaning LoRam/HiRam is ignored as it was set in the code executed during autostart))?
2016-08-19 04:42
JackAsser

Registered: Jun 2002
Posts: 1989
Are you saying #$35 in $01 doesn't give you access to RAM? Did you try "bank ram" in the VICE mon?
2016-08-19 04:58
TWW

Registered: Jul 2009
Posts: 541
What I mean is that when I enter the monitor, the default bank is CPU (as it sees it) and normally this means (if You set #$35 to $01) you should see ram under $a000 and $e000. but when I enter the monitor I see C64 BASIC and KERNAL ROM.

Surely I can BANK into RAM by monitor command but that does not help me access (read) RAM in the code (by manipulating Hi/LoRAM bits).
2016-08-19 05:19
oziphantom

Registered: Oct 2014
Posts: 478
Dumb Question. What are you initialising $00 to? If it is set to inputs, then you will always be $37 on the pins. I really recommenced you put a proper C64 boot up sequence in the code and then test.
2016-08-19 06:18
soci

Registered: Sep 2003
Posts: 474
Quoting TWW
Alright GPZ, I will check out the source when I sober up, meanwhile, here is the simple frame-setup (I checked it with a hex-editor and it's identical headers for the cartridge and the chips to the original described in the docs):
Simple is this not. Now that you've learned how to do it the hard way, I'd like to suggest a different solution this the problem.

Create a raw 512 KiB file instead and let cartconv to do the container for you:
cartconv -i in.bin -o out.crt -t gs -n "cartname"

ps.: Cartconv is part of VICE, just like c1541.
2016-08-19 07:34
tlr

Registered: Sep 2003
Posts: 1717
Quote: Dumb Question. What are you initialising $00 to? If it is set to inputs, then you will always be $37 on the pins. I really recommenced you put a proper C64 boot up sequence in the code and then test.

I too believe this is the cause. Classic mistake.
2016-08-19 08:49
chatGPZ

Registered: Dec 2001
Posts: 11126
indeed, its a bit silly that they didnt do that in the kernal before the CBM80 check :)
2016-08-19 09:00
Krill

Registered: Apr 2002
Posts: 2850
Maybe due to circumstantial or even technical reasons. Leaving the CPU port to all-inputs in order not to break whatever would be connected in the final design, before cartridge code takes over, or something like that. Or it's really just a silly oversight. :)
2016-08-19 09:21
oziphantom

Registered: Oct 2014
Posts: 478
Quoting soci
Quoting TWW
Alright GPZ, I will check out the source when I sober up, meanwhile, here is the simple frame-setup (I checked it with a hex-editor and it's identical headers for the cartridge and the chips to the original described in the docs):
Simple is this not. Now that you've learned how to do it the hard way, I'd like to suggest a different solution this the problem.

Create a raw 512 KiB file instead and let cartconv to do the container for you:
cartconv -i in.bin -o out.crt -t gs -n "cartname"

ps.: Cartconv is part of VICE, just like c1541.


Pro tip. Don't bother forcing the assembler to make the right sized file and let cart conv do it for you with -p ;)
2016-08-19 09:22
tlr

Registered: Sep 2003
Posts: 1717
I actually think it's nice that the cartridge hook starts up with as little setup before it as possible. That enables all sorts of hacks to the hardware without changing the kernal.
2016-08-19 11:03
TWW

Registered: Jul 2009
Posts: 541
Yes, strangely enough I initially did set the DDR for the MPU. However when I did, the cartridge ROM would not appear at all.

For sake of good order I added the boot sequence as follows:

    .pseudopc CartridgeLocation {

        .word CartridgeColdStart
        .word CartridgeWarmStart
        .byte $c3, $c2, $cd, $38, $30  // CBM80

    CartridgeColdStart:
    CartridgeWarmStart:
	stx $d016
	jsr $fda3
	jsr $fd50
	jsr $fd15
	jsr $ff5b
	cli
	jsr $e453
	jsr $e3bf
	jsr $e422
	ldx #$fb
	txs

        sei
        lda #$35
        sta $01

!:      dec $d020
        jmp !-
    }


The boot sequence is followed nicely (basic screen comes up) but once I manipulate $01 to #$35 (Try to access LO/HIRAM), the Cartridge ROM disappears and the border color cycle snippet at the end is never executed but instead a BRK from RAM below Cartridge ROM happens.

EDIT: I could relocate the code and access HI/LORAM from outside Cartridge ROM off course...
2016-08-19 12:01
tlr

Registered: Sep 2003
Posts: 1717
Quoting TWW
Yes, strangely enough I initially did set the DDR for the MPU. However when I did, the cartridge ROM would not appear at all.

Maybe you just set the DDR before $01? The correct sequence is:
LDA #$37
STA $01
LDA #$2F
STA $00

When doing cartridge setup you really should have thoroughly examined the kernal startup code first so you know what's originally there.
2016-08-19 12:05
tlr

Registered: Sep 2003
Posts: 1717
Quoting TWW
The boot sequence is followed nicely (basic screen comes up) but once I manipulate $01 to #$35 (Try to access LO/HIRAM), the Cartridge ROM disappears and the border color cycle snippet at the end is never executed but instead a BRK from RAM below Cartridge ROM happens.

EDIT: I could relocate the code and access HI/LORAM from outside Cartridge ROM off course...

This seems obvious? You run code in ROM and try to switch out the ROM and it doesn't work.

If you need to read RAM below ROM you need to use a small accessor somewhere. Writing is possible without switching out ROM though. Even $d000-$dfff can be written using $33->$01.
2016-08-19 13:47
oziphantom

Registered: Oct 2014
Posts: 478
Quoting TWW

The boot sequence is followed nicely (basic screen comes up) but once I manipulate $01 to #$35 (Try to access LO/HIRAM), the Cartridge ROM disappears and the border color cycle snippet at the end is never executed but instead a BRK from RAM below Cartridge ROM happens.

EDIT: I could relocate the code and access HI/LORAM from outside Cartridge ROM off course...


So then it works as expected.
You pull the ROM out from under the CPU and put the RAM there instead, its hits a $00 stored in the RAM, it breaks. That is the correct behaviour.
You want to be able to access the RAM and execute code from the ROM, can't do it. ROM at memory or RAM at memory. But you can write to the RAM at any time.
2016-08-19 14:13
TWW

Registered: Jul 2009
Posts: 541
Quote: Quoting TWW
Yes, strangely enough I initially did set the DDR for the MPU. However when I did, the cartridge ROM would not appear at all.

Maybe you just set the DDR before $01? The correct sequence is:
LDA #$37
STA $01
LDA #$2F
STA $00

When doing cartridge setup you really should have thoroughly examined the kernal startup code first so you know what's originally there.


Well to be fair it writes #$e7 ;-)

Not sure why it would write to the port prior to setting the DDR but I guess it's like aligning the valves before opening the manifoil (metafor intended).

And yes I see no that I was too caught up in the GAME/EXROM lines to actually see that there is no memory configuration allowing what I wanted (All RAM + CART @ $8000 + IO).

Nevertheless this only means (practically) that one can not access the RAM under LO/HIROM or IO from CARTROM.

Thanks for the guidance to all + other input.
2016-08-19 14:22
tlr

Registered: Sep 2003
Posts: 1717
Quoting TWW
Well to be fair it writes #$e7 ;-)

True, although the effect is the same.
Quoting TWW
Not sure why it would write to the port prior to setting the DDR but I guess it's like aligning the valves before opening the manifoil (metafor intended).

Yes, something like that.

The way it works is that upon reset all bits in $00 are set to inputs. The pullups inside the 6502 will then keep the three lower bits effectively high (=$x7). When you set the correct DDR value the contents of $01 will start to affect those bits. If they haven't been set to the desired configuration, boom!
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
Airwolf/F4CG
Viti/Hokuto Force
TheRyk/MYD!
Exile/Anubis
bugjam
CA$H/TRiAD
grasstust/Hoaxers
Guests online: 131
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

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