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 > C64/C128 combo program compilation
2024-08-15 22:47
Jammer

Registered: Nov 2002
Posts: 1336
C64/C128 combo program compilation

Question might turn out plainly stupid so bear with me but I'm total noob on C128.

Can C64 program be compiled to run both on C64 and C128 in its native 128k mode if it has appropriate branches in code? Or it's always two separate tailored builds?

I've already learnt that C128 program startup is either $1C01 or $4001 but if C128 startup was embedded at the right spot, would it still launch?
 
... 35 posts hidden. Click here to view all posts....
 
2024-08-19 18:22
oziphantom

Registered: Oct 2014
Posts: 490
SYS(PEEK(46)*256+30) would do it I think.
2024-08-19 19:55
MagerValp

Registered: Dec 2001
Posts: 1078
Quoting oziphantom
SYS(PEEK(46)*256+30) would do it I think.

No that points to the end of the loaded program on the C64, which unless it's really short doesn't give you $08.
2024-08-20 01:16
Martin Piper

Registered: Nov 2007
Posts: 726
Quote: yeah but the VIC-20 and C64 have the same version of BASIC with the same vectors and ROM in the same place. The 128 is not a slightly bigger C64 it's a smaller Amiga.

Putting that code on a 128 will trash
02a2-02ae	674-686	Kernal RAM

02a2-02ae	Bank Peek Subroutine
02af-02bd	Bank Poke Subroutine
02be-02cc	Bank Compare Subroutine
02cd-02e2	JSR to Another Bank
02e3-02fb	JMP to Another Bank
02fc-02fd	Function Execute Hook	[4c78]

which will cause crashes


43/44 on the C128 are also not the start of basic.
2024-08-20 19:08
zzarko

Registered: Feb 2003
Posts: 77
CBM FileBrowser v1.6 implements a basic stub that checks if the machine is VIC-20, C64, C128, C64DTV or Plus/4 and loads binary for recognized one:

https://github.com/0cjs/cbm-filebrowser/blob/master/sources/fb...
2024-08-20 19:20
chatGPZ

Registered: Dec 2001
Posts: 11387
A stub loader is easy to do - the challenge is to make it a single self contained binary :)
2024-08-20 20:51
zzarko

Registered: Feb 2003
Posts: 77
Knowing the machine is knowing the address of the loaded program. Binary could be attached to similar BASIC code. A few more data lines could hold some adjusting values, like to where to copy binary part, and then to jump to that address. Binary part could even have machine-specific sub-parts and so on. No?
2024-08-20 21:13
MagerValp

Registered: Dec 2001
Posts: 1078
Quoting chatGPZ
A stub loader is easy to do - the challenge is to make it a single self contained binary :)

My sample project above does that, although I was lazy and only did an 8-bit code relocator and the "program" is just inc $d020. But it's a single .prg that loads and runs on both C64 and C128.
2024-08-20 22:26
Krill

Registered: Apr 2002
Posts: 2981
While this thread seems to degra^Wmorph into a code golf challenge, i need to re-emphasise that having a single binary run in both C-64 and native C-128 modes is a pointless exercise wrt actual real-life use-cases. =)
2024-08-21 01:36
Martin Piper

Registered: Nov 2007
Posts: 726
I think the examples given above demonstrate real life use cases.

They are real applications, they have use...

A nice puzzle is to have the BASIC start with only a SYS <simple number>.
It's doable.
2024-08-21 07:43
MagerValp

Registered: Dec 2001
Posts: 1078
True, you can just use SYS7181 and put startup code at two different offsets in the .prg.

And I disagree that it's useless, file browsers are a good example where it makes sense. Games though maybe not so much.
Previous - 1 | 2 | 3 | 4 | 5 - 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
Mike
blitzed
Bob/Censor Design
Laddh
MCM/ONSLAUGHT
Guests online: 118
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.6)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Sprite Bukkake 2  (9.6)
9 Uncensored  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.7)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 Morph  (9.5)
7 Dawnfall V1.1  (9.5)
8 Libertongo  (9.5)
9 Katzen-Video.mp4  (9.5)
10 Onscreen 5k  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Performers  (9.3)
4 Fairlight  (9.3)
5 Triad  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.048 sec.