Re: [cc65] CBM disk write problems

Date view Thread view Subject view

From: Greg King (gngking_at_erols.com)
Date: 2003-12-31 23:30:00


From: Johan Kotlinski, on Tuesday, December 16, 2003, at 06:23 PM
>
> > On Tue, Dec 16, 2003 at 01:44:46AM +0100, Johan Kotlinski wrote:
> > > I have a problem with saving to 1541.  When saving to a file the
> > > first time, everything works great.  But, the second time I call my
> > > routine, it just doesn't work.
>
> I tried writing it in assembler, and it worked.  If you are interested,
> here are the two (in my eyes, equivalent) routines:
>
> Assembler (WORKING):
>
> _sub_save_hiscores:
>   SEI
>   LDA #1
>   LDX #8
>   LDY #$F
>   JSR $FFBA
>   LDA #$12
>   LDX #<filename_start  ; points to "@:KIDGRID_HISCORES"
>   LDY #>filename_start
>   JSR $FFBD
>   LDA #$90
>   STA $FB
>   LDA #$11
>   STA $FC
>   LDA #$fb
>   LDX #$44
>   LDY #$12
>   JSR $FFD8
>   CLI
>   RTS
>
> C (won't work):
>
> void save_highscores() {
>  __asm__ ("\tsei");
>  cbm_open(1,8,15,"@:KIDGRID.HISCORES");
>  cbm_write(1,(char*)0x1190,180);
>  cbm_close(1);
>  __asm__ ("\tcli");
> }

Your assembly code actually does this:

void save_highscores(void) {
    cbm_save("@:KIDGRID.HISCORES", 8, (void*)0x1190, 0x1244 - 0x1190);
    }

But, you might have a serious problem.  A program works once, then fails
the next time, often because it changes something that it should not touch,
in between those two times.  Does your game's source-code actually contain
raw addesses like that 0x1190, or was it only an example for us to see on
this mailing list?  If the source has raw addresses, then you must fix that
bug.  You must use C structures, arrays, and simple variables, instead.
Let cc65 decide where they will sit in memory.  Otherwise, your program
might put data on top of its code -- it might destroy itself!  (The game
probably changed its file code.)

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2004-01-01 00:04:08 CET