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-16 13:34
Jammer

Registered: Nov 2002
Posts: 1336
Thanks, guys, for the heads up! <3 Is it also same problem with SuperCPU and other accelerators?
2024-08-16 13:51
chatGPZ

Registered: Dec 2001
Posts: 11390
No, the others don't result in that kind of garbage display. SCPU is an entirely different beast though :)
2024-08-16 19:05
zzarko

Registered: Feb 2003
Posts: 77
3rd place at Revision 2024 Wild category:

https://www.pouet.net/prod.php?which=96567

The same binary (although with some caveats) works on C64, MSDOS, Linux, SNES, NDS, Gameboy, Gamecube, can be unpacked as a ZIP file (then it contains its complete source) and can be openbed as PDF. For any of these, just change the extension.

So I would guess there is definitely a way to make one binary that runs on C64 and C128 without modifications (I am not saying that I can make one!).
2024-08-18 15:04
Martin Piper

Registered: Nov 2007
Posts: 726
Quote: 3rd place at Revision 2024 Wild category:

https://www.pouet.net/prod.php?which=96567

The same binary (although with some caveats) works on C64, MSDOS, Linux, SNES, NDS, Gameboy, Gamecube, can be unpacked as a ZIP file (then it contains its complete source) and can be openbed as PDF. For any of these, just change the extension.

So I would guess there is definitely a way to make one binary that runs on C64 and C128 without modifications (I am not saying that I can make one!).


This is nice. As long as the prg is loaded with ,8 and not ,8,1 then it would be relatively easy to make a prg that detects if it is running in C64 or C128.
2024-08-18 18:00
oziphantom

Registered: Oct 2014
Posts: 490
I guess you could use BASIC to detect which machine you are on, or maybe which version of BASIC you are running?
Set the BASIC error vector to something custom and then try and run a BASIC 7.0 command, if it fails you know you are BASIC 2, if it passes you know you are BASIC 7 and hence then know were the asm code starts. Both the 64 and 128 have the BASIC error vector at $300/1.

However you then still have the issue that your code has to handle being in two different memory locations, but I guess at that point you could jump to a known address at the end of code on a 128 that then copies the main code down to 0801 or wherever you want to start, then apply your patches and then jump to it.
2024-08-18 22:39
aeeben

Registered: May 2002
Posts: 44
@Jammer, if this is for the project I think it is, why not do a native version for C-128 in the VDC 80 column display, then you can run all calculations at 2 kHz :) [Ouch, actually, writing to VDC is probably too slow...]

Almost related bits from VIC 20 world: I used this loader in Hare Basic - it does autostart on both VIC 20 and C-64, and loads&runs either the file "A000" or "C000". As a little bonus, it can be also loaded with ",8" on both machines, but then obviously requires a RUN.

(Inspired by Mike's VIC 20 memory-configuration-independent-autostart code on Denial forum.)

	processor 6502

SETLFS	equ	$ffba
SETNAM	equ	$ffbd
LOAD	equ	$ffd5
RESTOR	equ	$ff8a
CHROUT	equ	$ffd2
CLRCHN	equ	$ffcc
SCREEN	equ	$ffed


;	C-64 / VIC 20 Autostart
;
;	load"*",8 or load"boot",8 (and run)
;	load"*",8,1 or load"boot",8,1 (autostart)


start	equ	$02a7

	org	start
	incbin	"autostart-basic.bin"	; 2024 syspeek(44)*256+peek(43)+21

basic
	ldy	#bootend-start-1
.1
	lda	($2b),y
	sta	start,y
	dey
	bne	.1
	jmp	boot

boot
	jsr	SCREEN		; detect C-64 or VIC 20 by number of rows
	cpy	#$19
	beq	.c64

.vic20
	jsr	$e45b		; restore basic vectors (VIC 20)

	lda	#$a0
	sta	start_+2	; modify start address to $a000
	lda	#$41
	sta	filename	; modify filename to "A000"
	bne	.load

.c64
	jsr	$e453		; restore basic vectors (C-64)

.load
	ldx	#<filename	; set up filename
	ldy	#>filename
	lda	#$04
	jsr	SETNAM

	lda	#$01		; set up file
	sta	$9d
	ldx	$ba
	tay
	jsr	SETLFS

	lda	#$00		; load and execute
	jsr	LOAD

start_
	jmp	$c000

filename
	dc.b	"C000"

bootend
	org	$0300
	dc.w	boot
	dc.w	boot
2024-08-19 08:53
oziphantom

Registered: Oct 2014
Posts: 490
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
2024-08-19 09:35
chatGPZ

Registered: Dec 2001
Posts: 11390
Quote:
The 128 is not a slightly bigger C64 it's a smaller Amiga.

It has more in common with a Spectrum than with an Amiga though :D
2024-08-19 11:04
Jammer

Registered: Nov 2002
Posts: 1336
Amiga is a direct descendent of Atari, deal with it ;)
2024-08-19 11:34
MagerValp

Registered: Dec 2001
Posts: 1078
Writing a big basic program with branching logic to detect C128 or C64 is easy enough, but I'd prefer something compact even if a bit hacky. The best I could come up with on my lunch break is SYS(PEEK(57532)-219)*256+30.

Sample project here: https://github.com/MagerValp/C128-C64-PIBS
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
Raf/Vulture Design
sachy/BOOM!
Andy/AEG
Asphodel
t0m3000/hf^boom!^ibx
The MeatBall
morphfrog
Krill/Plush
Guests online: 117
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.6)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 The Demo Coder  (9.6)
8 Comaland 100%  (9.6)
9 Wonderland XIV  (9.6)
10 What Is The Matrix 2  (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 Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.0)

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