Please consider at least running a github if only for your example code and updated binaries so that we can post issues. Since this appears to be the only place to talk with you and provide feedback, I have no choice but to post a long message.
Im creating a c64 target (for the supercpu), but calls to main() are always a byte or two off.
Heres the build commands:
Code:
as65816 c64startup.asm -o c64startup.o -l --code-model small --data-model large
as65816 c64.asm -o c64.o -l --code-model small --data-model large
cc65816 test.c -o test.o -l --code-model small --data-model large
ln65816 test.o c64.o c64startup.o rules.scm clib-sc-ld.a --rtattr cstartup=c64startup --output-format raw -l --cross-reference
Here is my cstartup.s (with my modifications):
Code:
.rtmodel cstartup,"c64startup"
.rtmodel version, "1"
.rtmodel cpu, "*"
.section stack
.section cstack
.section heap
.section data_init_table
.extern main, exit
.extern _Dp, _Vfp
.extern _DirectPageStart
#ifndef __CALYPSI_DATA_MODEL_SMALL__
.extern _NearBaseAddress
#endif
#include "macros.h"
;;; ***************************************************************************
;;;
;;; The reset vector. This uses the entry point label __program_root_section
;;; which by default is what the linker will pull in first.
;;;
;;; ***************************************************************************
.section reset
.pubweak __program_root_section
__program_root_section:
.word __program_start
;;; ***************************************************************************
;;;
;;; __program_start - actual start point of the program
;;;
;;; Set up CPU stack, initialize sections and call main().
;;; You can override this with your own routine, or tailor it as needed.
;;; The easiest way to make custom initialization is to provide your own
;;; __low_level_init which gets called after stacks have been initialized.
;;;
;;; ***************************************************************************
.section code,noreorder
.pubweak __program_start
__program_start:
; provides BASIC startup: "10 SYS 2062"
.byte 0x01, 0x08 ; always zero, load address
.byte 0x07, 0x08 ; pointer to next line
.byte 0x0A, 0x00 ; line number (10)
.byte 0x9e ; SYS token
.ascii " 2062" ; SYS address in ASCII
.byte 0, 0, 0 ; end-of-program
clc
xce ; native 16-bit mode
rep #0x38 ; 16-bit registers, no decimal mode
ldx ##.sectionEnd stack
txs ; set stack
lda ##_DirectPageStart
tcd ; set direct page
#ifdef __CALYPSI_DATA_MODEL_SMALL__
lda ##0
#else
lda ##.word2 _NearBaseAddress
#endif
stz dp:.tiny(_Vfp+2)
xba ; A upper half = data bank
pha
plb ; pop 8 dummy
plb ; set data bank
;;; **** Initialize data sections if needed.
; .section code, noroot, noreorder
; .pubweak __data_initialization_needed
; .extern __initialize_sections
;__data_initialization_needed:
; lda ##.word2 (.sectionEnd data_init_table)
; sta dp:.tiny(_Dp+6)
; lda ##.word0 (.sectionEnd data_init_table)
; sta dp:.tiny(_Dp+4)
; lda ##.word2 (.sectionStart data_init_table)
; sta dp:.tiny(_Dp+2)
; lda ##.word0 (.sectionStart data_init_table)
; sta dp:.tiny(_Dp+0)
; call __initialize_sections
;;; **** Initialize streams if needed.
; .section code, noroot, noreorder
; .pubweak __call_initialize_global_streams
; .extern __initialize_global_streams
;__call_initialize_global_streams:
; call __initialize_global_streams
;;; **** Initialize heap if needed.
; .section code, noroot, noreorder
; .pubweak __call_heap_initialize
; .extern __heap_initialize, __default_heap
;__call_heap_initialize:
;#ifdef __CALYPSI_DATA_MODEL_SMALL__
; lda ##.sectionSize heap
; sta dp:.tiny(_Dp+2)
; lda ##.sectionStart heap
; sta dp:.tiny(_Dp+0)
; lda ##__default_heap
;#else
; lda ##.word2 (.sectionStart heap)
; sta dp:.tiny(_Dp+6)
; lda ##.word0 (.sectionStart heap)
; sta dp:.tiny(_Dp+4)
; lda ##.word2 __default_heap
; sta dp:.tiny(_Dp+2)
; lda ##.word0 __default_heap
; sta dp:.tiny(_Dp+0)
; ldx ##.word2 (.sectionSize heap)
; lda ##.word0 (.sectionSize heap)
;#endif
; call __heap_initialize
.section code, root, noreorder
lda ##0 ; argc = 0
call main
rts
https://imgur.com/a/9lfFU4o