Help w/ Vic20/cc65 Cart Library?

Basic and Machine Language

Moderator: Moderators

Post Reply
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Help w/ Vic20/cc65 Cart Library?

Post by HarryP2 »

Hi! I have been developing a Vic20 app. cart. library for cc65. When I use only my CBMSimpleIO library (available at https://sourceforge.net/projects/cc65extra/files/ui/), it works fine. When I use puts(), the library either restarts every screen refresh (i.e. every 50th or 60th second) or locks up after one screen refresh. I've been able to narrow the problem down to the jsr initlib instruction in the crt0.s file. The crt0.s file follows:

Code: Select all

;
; Startup code for cc65 (Vic20 version)
;

	.export		_exit
        .export         __STARTUP__ : absolute = 1      ; Mark as startup
	.import		initlib, donelib, callirq
       	.import	       	zerobss, push0
	.import	     	_main
        .import         RESTOR, BSOUT, CLRCH
	.import	       	__INTERRUPTOR_COUNT__
     	.import		__RAM_START__, __RAM_SIZE__	; Linker generated

	.import		__DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
	
	.import		_puts, _cgetc, _memcpy, pushax

        .include        "zeropage.inc"
     	.include     	"vic20.inc"

PLOT=$FFF0
; ------------------------------------------------------------------------
; Place the startup code in a special segment.

.segment       	"STARTUP"


	.word	$A000			;Cartridge load address
	.word	Crt0_Init		;Address of start-up code
	.word	0;Crt0_Start		;I don't know.
	.byte	$41,$30,$C3,$C2,$CD	;ROM present signature

;--------------------------------------------------------------------
;Startup code:
Crt0_Init:
sei
	cld
	ldx	#$ff
	txs
	
;Run kernal setup routines.
jsr	$FD8D
jsr	$FD52
jsr	$FDF9
jsr	$E518
cli
;Set up BASIC env.

jsr	$E3A4

;Set up stack.
	;Clear bss.

; Save system stuff and setup the stack

	lda    	#<$1E00
	sta	sp
	lda	#>$1E00
       	sta	sp+1   		; Set argument stack ptr

	;jsr	zerobss

	;Copy read/write data to RAM.
	lda	#<__DATA_RUN__
	ldx	#>__DATA_RUN__
	jsr	pushax
	lda	#<__DATA_LOAD__
	ldx	#>__DATA_LOAD__
	jsr	pushax
	lda	#<__DATA_SIZE__
	ldx	#>__DATA_SIZE__
	;jsr	pushax
	jsr	_memcpy


	;jsr	CLRCH
; Switch to second charset

	lda	#14
	jsr	BSOUT

	;ldx	#0
	;ldy	#0
	;clc
	;jsr	PLOT
	
	lda	#65
	jsr	$FFD2
; Clear the BSS data

	;jsr	zerobss

;Call constructors.
	;jsr	initlib

; If we have IRQ functions, chain our stub into the IRQ vector

        lda     #<__INTERRUPTOR_COUNT__
      	beq	NoIRQ1
      	lda	IRQVec
       	ldx	IRQVec+1
      	sta	IRQInd+1
      	stx	IRQInd+2
      	lda	#<IRQStub
      	ldx	#>IRQStub
      	sei
      	sta	IRQVec
      	stx	IRQVec+1
      	cli

; Call module constructors

NoIRQ1: jsr     initlib

; Push arguments and call main()

        ;jsr     callmain
	jsr	push0
	jsr	push0
	jsr	_main

; Back from main (This is also the _exit entry). Run module destructors

_exit:  jsr     donelib

; Reset the IRQ vector if we chained it.

        ;pha  		     	; Save the return code on stack
	lda     #<__INTERRUPTOR_COUNT__
	beq	NoIRQ2
	lda	IRQInd+1
	ldx	IRQInd+2
	sei
	sta	IRQVec
	stx	IRQVec+1
	cli


NoIRQ2:
; Place the program return code into ST

	;pla
	;sta	ST

;End and restart.
;Print end message.
	lda	#<EndMsg
	ldx	#>EndMsg
	
	jsr	_puts
;Wait for key.
	jsr	_cgetc
;Restart.
	jmp	($FFFC)		;Kernal reset vector

; ------------------------------------------------------------------------
; The IRQ vector jumps here, if condes routines are defined with type 2.

IRQStub:
	cld    	       		   	; Just to be sure
       	jsr    	callirq                 ; Call the functions
       	jmp    	IRQInd			; Jump to the saved IRQ vector

; ------------------------------------------------------------------------
; Data

.data

IRQInd: jmp     $0000
.rodata
;End message.
EndMsg:
	.byt	147,"Your program ended.",13
	.byt	"Press any key to", 13
	.byt	"restart.",0
The config file:

Code: Select all

SYMBOLS {
    __STACKSIZE__: value = $200, type = weak;	# 512-byte stack
}
MEMORY {
    ZP: start =  $0002, size = $001A, type = rw, define = yes;
    #RAM: start = $0200, size = $0200, define = yes;
    RAM: start = $1000, size = $0C00, define = yes;
    ROM: start = $9FFE, size = $2002, define = yes, file = %O,
	 fill=yes;
}
SEGMENTS {
    STARTUP:  load = ROM, type = ro;
    LOWCODE:  load = ROM, type = ro,               optional = yes;
    INIT:     load = ROM, type = ro, define = yes, optional = yes;
    CODE:     load = ROM, type = ro;
    RODATA:   load = ROM, type = ro;
    DATA:     load = ROM, run = RAM, type = rw, define = yes;
    #ZPSAVE:   load = RAM, type = bss;
    BSS:      load = RAM, type = bss, define = yes;
    HEAP:     load = RAM, type = bss, optional = yes; # must sit just below stack
    ZEROPAGE: load = ZP,  type = zp;
}
FEATURES {
    CONDES: segment = INIT,
	    type = constructor,
	    label = __CONSTRUCTOR_TABLE__,
	    count = __CONSTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
	    type = destructor,
	    label = __DESTRUCTOR_TABLE__,
	    count = __DESTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
	    type = interruptor,
	    label = __INTERRUPTOR_TABLE__,
	    count = __INTERRUPTOR_COUNT__;
}
Am I doing something wrong? :(
Post Reply