Re: cc65 and "Hello World"



On Apr 19, 9:03 am, ol...@xxxxxx (Oliver Schmidt) wrote:

I don't understand why "everybody" assumes that cc65 by default
generates SYS programs. This is _NOT_ the case - as documented. As
already pointed out rather often in this group the reason is that the
progams cc65 is intended for should rather be loaded to $803 instead
of $2000. The loader mentioned above is a SYS program used to load
binaries to arbitrary addresses. In example cc65 binaries to their
default address of $803.


On Apr 18, 10:42 pm, "BluPhoenyx" <bluphoe...@xxxxxxxxxxxxxxxxxxxxxxxxx
this> wrote:
And always know where your program will load/end and what memory areas
it will require for execution. Then proofread your code to ensure it
isn't running or overwriting memory it shouldn't use.

First off Mike (and Oliver)

I never realized that it needed to be so complicated. Why should an
application programmer need to worry about all these things... some of
them I can see learning in due course... but the bit about *knowing*
sounds a little too carnal for a newbie... (please, there are small
children listening:) send them to bed.

Gio, the linker should manage your program arrangement in memory and
the use of overlays should keep things down to a manageable size.
Having said that I realize that you have decided to go a different
route than what I have recommended so on to understanding the problem
at hand... so you wanna be an expert eh:) I thought you were just
getting started.

There is a section in the Aztec C ReadMe about starting Aztec C SYS
programs from within the Aztec C shell interpreter. Now that I have
realized that Gio is using a loader dare I ask if this is a ProDOS sys
program similar to the Aztec C Shell of days gone by. Bare with me
while I have one of my now-famous brain f*rts here... here's da readme
note:

x--- snip ---x

9. System programs

Many ProDOS system programs created using Aztec C65 will crash
if they're started from the SHELL. There is no problem if they are
started from the Basic Interpreter or automatically upon system start-
up.

The problem arises from the facts that
(1) the section of memory used by the SHELL's environment pages
(0xbc00-0xbf00) is still allocated when a system program is started,
and (2) a system program's pseudo stack grows down through the
SHELL's environment pages. If the ProDOS MLI is told to perform an
operation
and return information on the pseudo stack,
the MLI will not perform the operation if the information would be
placed in the SHELL's still-allocated environment pages.

x--- snip ---x

Ok and excellent reference in the CSA2 FAQ BTW. I think we have all
appreciated that...

For Gio's benefit I want to point him to a gif that made back in in
1990 or so I have placed on the Aztec C Website. This gif was made to
explain to a client who was a DOS 3.3 BASIC programmer what I was
doing with an Aztec C program. Really this applies to all SYS programs
in Appledom. Anything you load needs to Be-LOADed at such an address
that does not clobber anything else. Click here...

http://www.clipshop.ca/Aztec/apmap.gif

I am going to give-up asking folks why they want to do things that are
hard to make work and also suggesting that they try something easier.
I guess everyone needs a challenge. To me making a BIN file to run in
BASIC in PRODOS is a waste of time. Running BASIC in PRODOS is a waste
of time and disk space if you are writing in C.

Also to me, BLOADing and BRUNning BIN programs in DOS 3.3 from BASIC
and in fact using BASIC in DOS 3.3 is not a waste of time since ProDOS
wasn't invented yet and we did things differently then.

OK so back to ProDOS

Here's crt(0) from Aztec C65 ProDOS source. This'll go along with the
gif that I pointed you to. Question is are you trying to debug a
compiler or write a program or put one more card onto a house of cards
to see if you can do it without toppling the rest of the cards?

So when crt(0) fires up it calls samain which in turn loads the main()
program function. This is compiler specific mind you but if you are
using a loader this might tell you a thing or two about what needs to
happen... on the way back-out of main saiman takes over again and
calls exit to end...


crt0.a65
*:ts=8
*
* Copyright (C) 1982,83,84,85 by Manx Software Systems, Inc.
*

instxt <zpage.h>

global _Top_,2
global _mbot_,2

dseg
public MEMRY
MEMRY rmb 2
public _Stksiz_
_Stksiz_
fdb $0800 ;default stack size is 2K
public _End_
_End_
fdb $0001 ;force into inited data space

cseg
public _Uorg_,_Uend_,_Corg_

public .begin
entry .begin
.begin cld
lda #>_Corg_
cmp #$20 ;check system load address
bne notsys
lda #$fe
ldx #$be ;just below system global page
bne put
notsys lda $E000 ;check basic type
cmp #$20 ;is it integer?
bne chkap ;no, check applesoft
lda $4C ;get integer HIMEM
ldx $4D
bne put
chkap lda $73 ;get applesoft HIMEM
ldx $74
put sta SP ;save in stack pointer
sta _End_
stx SP+1
stx _End_+1
lda #<_Uorg_ ;clear out bss space
sta VAL
lda #>_Uorg_
sta VAL+1
ldy #0
loop tya
sta (VAL),Y
inc VAL
bne skip
inc VAL+1
skip lda VAL
cmp #<_Uend_
bne loop
lda VAL+1
cmp #>_Uend_
bne loop
lda MEMRY ;set end of program for alloc routines
sta _Top_
sta _mbot_
lda MEMRY+1
sta _Top_+1
sta _mbot_+1
lda #<acc ;init pointers for floating point registers
sta ACC
lda #>acc
sta ACC+1
lda #<sec
sta SEC
lda #>sec
sta SEC+1
jmp _main_#

dseg
global acc,14 ;space reserved for floating point registers
global sec,14
*

x--- snip ---x

samain.a65
*:ts=8
*
* Copyright (c) 1982,83,84,85 by Manx Software Systems, Inc.
*
instxt <zpage.h>

global _dev_info_,2
global _devinfo_,0
global _fil_tab_,2
global _filtab_,0
global errno_,2
global _Sp_,2

public _main_
_main_
lda #<_devinfo_
sta _dev_info_
lda #>_devinfo_
sta _dev_info_+1
lda #<_filtab_
sta _fil_tab_
lda #>_filtab_
sta _fil_tab_+1
sec
lda SP
sbc #6
sta SP
bcs .1
dec SP+1
.1
ldy #5
lda #0
.2
sta (SP),Y
dey
bpl .2
jsr main_
sec ;return from main: call exit(0)
lda SP
sbc #4
sta SP
bcs drop1
dec SP+1
drop1
lda #0
ldy #3
loop1
sta (SP),Y
dey
bne loop1
jsr exit_
brk
;
public main_
public exit_

x--- snip ---x

exit.c
/* Copyright (C) 1985 by Manx Software Systems, Inc. */

#include <prodos.h>

static
noper()
{
return(0);
}

int (*cls_)() = noper;

exit(n)
int n;
{
register unsigned i;

(*cls_)();
for (i=0;i<MAXFILES;i++)
if (_fil_tab[i].unit)
close(i); /* close all remaining "unbuffered" streams */
_exit(n);
}

x--- snip ---x


exitu.c
/* Copyright (C) 1985 by Manx Software Systems, Inc. */

#include <prodos.h>
#include <sysfunc.h>

extern struct shvar {
char vects[6];
int retflg;
} *_Sp;

_exit(n)
{
_sys_parm[0] = 1;
_sys_parm[1] = 0; /* close all files */
_system(SYS_CLOSE);
if (_Sp) /* if called from SHELL */
_Sp->retflg = n;
(*((void (*)())0x03d0))(); /* ProDOS warm boot */
}

x--- snip ---x

So in order to be aware of what your program is doing as Poenix
suggests the above is required reading in Aztec C and I am sure CDC65
will provide you with the equivalent, and many variations thereof as
does Aztec C whether we are rumnning in and out of the Aztec C shell
since Aztec C offers an interpreted pcode mode as well as stand-alone
mode and also offers DOS 3.3 as well as ProDOS.

When it comes to loading overlays which are bits of binary with a
wrapper we use a similar but different strategy.

Now if the goal is to learn all the different ways we can load and run
code on the Apple II that is wonderful.

Then we go back to the fundamental framework for a bit of code that is
bloaded in basic to an address then brun.

The first two bytes of the bloadable module like a hires picture is a
short int with the address that it was bsaved from or in this case may
be the address that it is bloaded to which if a prodos sys program
should be $2000. The next two bytes are the length of the module that
needs to Be-LOADed.

BRUN will then jump to the first instruction and start executing. If
you have an error in your program then of course that error will
execute.

Lastly, since I haven't seen your code, I haven't seen your makefile,
and I don't know what it is you are up to with your linker and what
libraries you have linked to I will assume that you are doing
something like the following:

# ------------------------------------------------------------------
# (C) Copyright 2008 Bill Buckels
# makefile by bill buckels 2007
#
# note: I am copying ovld.r and samain.r to the current directory
# otherwise linker commandline exceeds maximum length
# note: the libraries a listed twice on the linker line
# this ensures that LN65 resolves routines in libraries
# that have depencies on other libraries
# big
# note: my utility MAKEPRO2 is required to strip the BLOADable header
# from the linker output in the root module and to embed the
# the raw bitmap splash screen and the cursor library
# (snail cursor and musical note) in the memory holes in the
# root module. the xfer program provided by Aztec C strips
# off the BLOADable header when xfering to a ProDOS xfer slave
# if a serial cable used to transfer this to a real Apple IIe
# We use the same linker for programs that are created for
# for Apple DOS 3.3 in which case the load address needs to
# be left in place and in which case the xfer program does not
# strip the load address. I never have built DOS 3.3 programs
# and did not much care for the tedious task of using xfer
# to transfer files one at a time from the IBM-PC to the Apple
IIe
# even when this was all current so wrote myself the MAKEPRO
# and MAKEPRO2 utilitities to prepare the final output and then
# used proper communications packages on the Apple and IBM to
# transfer multiple files en-masse using YMODEM protocol.
# Anyways, it is also notable that the MKBASIC utility provided
# with the Aztec C cross-development environment for the
# Commodore 64 took almost the opposite approach as I did and
# appended some Commodore BASIC startup code to the beginning
of
# programs linked with that linker. The other consideration that
Manx's
# developers made was to support whatever version of Pcode C
# which ran in their shell. Since they insisted on using the
# same linker for all their programs in any given environment
# some little process needed to be run to produce a fit
# executable for the real world, after they produced their
# initial output for their lowest common denominator.
# For your purposes since you are unlikely to produce programs
# that run in their shell, and if you are like me you won't
bother
# with DOS 3.3 and you won't ever worry about using xfer, just
use
# my MAKEPRO and MAKEPRO2 utilities for all your own Apple IIe
efforts.
# Off topic, but if you do use my Aztec64 Commodore 64
# cross-development environment for Windows XP. the makefiles
# in that particular environment use a separate utility that
# I wrote for embedding Splash Screens, Fonts, and Cursor
Libraries
# into Commodore 64 executables after linking, and then Manx's
# MKBASIC utility is always run afterwards to produce a fit
# executable for the C64. That's all I want to say on the
subject.
# Delve deepr if you wish.
#
# Have Fun!
# Bill Buckels
# bbuckels@xxxxxxx
#
# ------------------------------------------------------------------

time.sys: time.r cinit.r plogo.r flogo.r mainmenu.r time0.r time0a.r
time1.r time1a.r time2.r time2a.r
copy $(CR65)ovld.r ovld.r
copy $(CR65)samain.r samain.r
LN65 -t -r +s +H 4000,6004 time.r +C 2800 +D 400 ovld.r samain.r -
lSYSIO -lg2 -lc -ls -lm -lSYSIO -lg2 -lc -ls -lm
del time.r
MAKEPRO2 time RES\OLDIES.BIN
del time
@echo time.sys now created!
LN65 -t cinit.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del cinit.r
@echo cinit.ovr now created!
LN65 -t plogo.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del plogo.r
@echo plogo.ovr now created!
LN65 -t flogo.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del flogo.r
@echo flogo.ovr now created!
LN65 -t mainmenu.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -
lm -lSYSIO -lg2 -lc -ls -lm
del mainmenu.r
@echo mainmenu.ovr now created!
LN65 -t time0.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time0.r
@echo time0.ovr now created!
LN65 -t time0a.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time0a.r
@echo time0a.ovr now created!
LN65 -t time1.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time1.r
@echo time1.ovr now created!
LN65 -t time1a.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time1a.r
@echo time1a.ovr now created!
LN65 -t time2.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time2.r
@echo time2.ovr now created!
LN65 -t time2a.r $(CR65)ovbgn.r time.rsm -lSYSIO -lg2 -lc -ls -lm -
lSYSIO -lg2 -lc -ls -lm
del time2a.r
@echo time2a.ovr now created!
del time.rsm
del time.sym
del cinit.sym
del plogo.sym
del flogo.sym
del mainmenu.sym
del time0.sym
del time0a.sym
del time1.sym
del time1a.sym
del time2.sym
del time2a.sym
del ovld.r
del samain.r
copy *.ovr ENGLISH\*.*
copy *.ovr FRENCH\*.*
copy flogo.ovr FRENCH\plogo.ovr
del ENGLISH\flogo.ovr
del FRENCH\flogo.ovr
copy time.sys ENGLISH\TIME.SYSTEM
copy time.sys FRENCH\TIME.SYSTEM
del time.sys
del *.ovr
copy RES\*.FNT ENGLISH\*.*
copy RES\*.FNT FRENCH\*.*
copy RES\SNAIL.RIB ENGLISH\*.*
copy RES\SNAIL.RIB FRENCH\*.*
copy RES\PLOGO.RAG ENGLISH\PLOGO.RAG
copy RES\FLOGO.RAG FRENCH\PLOGO.RAG
copy RES\TIME.RIB ENGLISH\TIME.RIB
copy RES\FTIME.RIB FRENCH\TIME.RIB
cls
@echo Done!


time.r: time.c
c65 time.c

cinit.r: cinit.c
c65 cinit.c

plogo.r: plogo.c
c65 plogo.c

flogo.r: flogo.c
c65 flogo.c

mainmenu.r: mainmenu.c
c65 mainmenu.c

time0.r: time0.c
c65 time0.c

time0a.r: time0a.c
c65 time0a.c

time1.r: time1.c
c65 time1.c

time1a.r: time1a.c
c65 time1a.c

time2.r: time2.c
c65 time2.c

time2a.r: time2a.c
c65 time2a.c

x-- snip --x

Yes let's make it really complicated to get you started.

Regards,

Bill

.



Relevant Pages

  • Re: Scheduled Task error code:The task completed with an exit code
    ... echo %fileDATE%>filedate.txt ... if exist concatdate.txt del /q concatdate.txt ... You consistently fail to specify a drive and a path for your ... *** You must specify the exact file locations. ...
    (microsoft.public.windows.server.general)
  • Re: find and remove duplicate files
    ... > What are those strings of characters? ... echo commands. ... wit a "del " ...
    (microsoft.public.win2000.cmdprompt.admin)
  • RE: comments
    ... operating system. ... @echo off ... echo COUNTRY: DENMARK>>info.txt ... del ncurses.tar.gz ...
    (freebsd-questions)
  • Re: Batch file for cleaning up
    ... Cleaning the TIF folders using del and all files will only create ... Delete/Empty Temporary Internet Cache completely ... > echo * CCC L OOO SSS EEE * ...
    (microsoft.public.windows.inetexplorer.ie6.browser)

Loading