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 > Starting a program after copying from cartridge
2019-06-23 12:48
zzarko

Registered: Feb 2003
Posts: 67
Starting a program after copying from cartridge

I am working on a 3.0 version of Magic Desk Cartridge Generator and I have come up with a problem with three programs (testing is done in VICE 3.3, and on a real C64):

Turbocopy V5.0
Turbo Nibbler V5.0
64 Tester

that simply would not start when copied from cartridge to $0801 (the other ~140 programs that I have tried worked just fine).

Anyhow, cold start is like this:
stx $d016
jsr $FDA3 // IOINIT, init CIA,IRQ
jsr $FD50 // RAMTAS, init memory
jsr $FD15 // RESTOR, init I/O
jsr $FF5B // SCINIT, init video
cli
jsr $E453 // load BASIC vectors
jsr $E3BF // init BASIC RAM
jsr $E422 // print BASIC start up messages
ldx #$FB // init BASIC stack
txs

Then I setup IRQ, VIC and CIA registers to my liking. After a program is selected from cartridge menu, I restore original IRQ and call these:
jsr $FDA3 // IOINIT, init CIA,IRQ
jsr $FD15 // RESTOR, init I/O
jsr $FF5B // SCINIT, init video
cli
jsr $E453 // load BASIC vectors
jsr $E3BF // init BASIC RAM
jsr $A68E // set current character pointer to start of basic - 1
ldx #$FB
txs

then I copy the program to its address ($0801), set $2d/2e to end of program, and then:
jsr $A871 // clr
jsr $A533 // re-link
jmp $A7AE // run

Does someone knows what initialization am I missing here (or have too much of it)? Complete source code will be available soon, but I would like to fix this before the release, if possible.
2019-06-23 18:45
AlexC

Registered: Jan 2008
Posts: 293
Just a guess, but some programs assume default register/memory state after load so either you are missing some register values or memory setup is wrong or garbage in memory (leftovers after depacking) may be in your way.
2019-06-23 21:47
Claus_2015

Registered: Oct 2012
Posts: 53
Another guess: two of the programs are disk tools, maybe they want to see an 8 in $ba?
2019-06-23 22:15
zzarko

Registered: Feb 2003
Posts: 67
Cartridge code messes up some zero page locations and cassette buffer, otherwise it runs from ROM. $BA is set to first found active drive, and if none is found, it is set to 8. I have tried to save zero page locations before messing them up, and restoring them afterwards, but to no avail.
2019-06-23 22:28
zzarko

Registered: Feb 2003
Posts: 67
I have also tried to just transfer 64 Tester right after cold start, messing only $FB-$FD and cassette buffer ($0340-0398), but it still won't run this way.
2019-06-23 23:26
zzarko

Registered: Feb 2003
Posts: 67
Ahhh, finally... I have put end address also in ae/af and now those 3 work :)

And that leaves only one that still misbehaves (from those that I tested): Basic 64 Compiler 1.03. This one was captured with action replay, and runs fine when loaded from disk. But, when run from cartridge, it shows the menu, but pressing any option does nothing.
2019-06-24 07:34
zzarko

Registered: Feb 2003
Posts: 67
For Basic 64 compiler, I have tried this: I saved the memory blocks 0002-00ff and 0200-03ff when program loads from disk (with bs from VICE), started program form cartridge, put a breakpoint at program start, inserted saved memory blocks (with bl), and continued to run the program, but it still doesn't work...

So, my guess is that it isn't a problem with zeropage or 0200-0400 area. What else?
2019-06-24 08:29
Oswald

Registered: Apr 2002
Posts: 5031
find out why it doesnt works? see where it crashes and trace it back.
2019-06-24 09:15
zzarko

Registered: Feb 2003
Posts: 67
Huh, I tried that but it seems that Basic 64 Compiler is written in BASIC and compiled by itself. I cannot make sense of tracing its code (I'm not that good with C64 assembly)...
2019-06-24 09:23
zzarko

Registered: Feb 2003
Posts: 67
It doesn't crash, it just redraws the menu when I press any key (when loaded from disk, it does that when I press wrong key).

Weird thing is that if I press any combination of keys 87 times (don't ask...), it displays the prompt for filename, but it doesn't work afterwards as it should.
2019-06-24 22:38
AlexC

Registered: Jan 2008
Posts: 293
I would bet - especially if this was freeze using AR - VIC/IO registers are not set correctly. Also make sure 00 and 01 are set as needed too.
2019-06-25 07:31
Krill

Registered: Apr 2002
Posts: 2855
Since you have both a working and a failing setup for the same program, you can do a side-by-side comparison.

Get both invocations (from cartridge and from disk) in two VICE instances to the same point, that is, some loop where it waits for user input, same program counter, at least.

Then inject a keypress. I guess writing something into the keyboard buffer would do, but you'll see how it checks for input anyways.*

Then step through both instances simultaneously until they diverge, at which point you might have a vague idea what the problem might be. Watch out for stray or spurious interrupts, too.

Analyse memory and other state, redo for more hints, repeat until success. =)

* Finding out how to inject a keypress with the program performing the desired action can be done beforehand with the working setup.
2019-06-25 08:45
Count Zero

Registered: Jan 2003
Posts: 1826
Why use an AR bloated version of that compiler at all?
2019-06-25 12:37
zzarko

Registered: Feb 2003
Posts: 67
One reason is I haven't found cracked version of 1.03. I have tried to make executable from disk (got it from http://commodore.software/index.php/downloads/download/53-basic..), but I wasn't successfull (I obviously lack knowledge), so a friend made an AR snapshot that works from floppy.

Second reason is that it was in my set of testing programs and it failed. Maybe some other program could fail to work from cartridge for the same reason(s).

But, good thing is that 145 out od 146 tested programs now work :)
2019-06-25 16:21
Count Zero

Registered: Jan 2003
Posts: 1826
Cracked version?
You mean a single .prg stripped from that auto start and the text or so?

Couldn't find some kind of real protection.
2019-06-25 17:22
Hoogo

Registered: Jun 2002
Posts: 102
You could prefer the "practical" solution and replace the problematic file with a nicer version.
Or you could be happy that you've found such a problematic example and really understand and fix the problem.

Not sure what I would do in this case...
2019-06-25 23:17
zzarko

Registered: Feb 2003
Posts: 67
Quote: Cracked version?
You mean a single .prg stripped from that auto start and the text or so?

Couldn't find some kind of real protection.


The image in 192K, and after starting it loads (or tries to load) a bunch of blocks from tracks 36-39 (if I remember correctly). I tried to track down what is being loaded where, but, as i said, couldn't figure it out.
2019-06-27 07:37
map

Registered: Feb 2002
Posts: 27
As it was mentioned before, the protection seems not to be very hard, so I spend some time yesterday evening to create a onefile version of this thing. If you like I can send it to you. Maybe it helps..
2019-06-27 15:43
zzarko

Registered: Feb 2003
Posts: 67
Yes please! (I've sent you a PM)
2019-06-27 15:56
Oswald

Registered: Apr 2002
Posts: 5031
if it only has input problems maybe its cia initialization problem ? (reading keyboard)
2019-06-28 14:34
zzarko

Registered: Feb 2003
Posts: 67
It is not just an input problem, apart from showing the menu, almost nothing works as it should. Something in initialization is missing, but I do not know what. I tried running cartridge and disk version side by side in VICE, they both enter some kind of loop, but as it is a compiled basic, I was unable to determine what is going on.

And I found one more program that works from floppy, but not from cartridge.

Marko and I have decided to release the current code, as it works in most cases:
Magic Desk Cartridge Generator V3.0
Source code is available, and if someone who knows more than we can help, please do.

I'd like to thank all of you for your advices and help, code is better than it was thanks to you.
2019-06-28 21:17
map

Registered: Feb 2002
Posts: 27
Ok, so you still would like to start the AR-snapshot from the crt.

Did you try if AR-snapshots from other programs can be started with your solution?

Some general ideas:

The adresses of some ROM calls used in these examples look a bit different compared to what you use but I did not check the details.

https://codebase64.org/doku.php?id=base:runbasicprg
https://codebase64.org/doku.php?id=base:kernalbasicinit

Also for debugging this tool is very nice:

C64 Debugger V0.64.56

Maybe you already knew these..
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
Alakran_64
Scrapper
iAN CooG/HVSC
sailor/Triad
Martin Piper
Flexman
Mihai
Guests online: 151
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 No Bounds  (9.6)
7 Aliens in Wonderland  (9.6)
8 Comaland 100%  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Happy Birthday Dr.J  (9.7)
2 Layers  (9.6)
3 It's More Fun to Com..  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Copper Booze  (9.6)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Rainbow Connection  (9.5)
9 Dawnfall V1.1  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

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