From: Tim Schürmann (tischuer_at_web.de)
Date: 2003-01-13 12:41:51
Hallo! I try to backup a hires graphic in memory by using malloc/memcpy. Why does the following code won't work? As you can see, i'm using loadkoala to exclude any other errors. ------------------------ snip ------------------------------------- ... header-files ... unsigned char loadtoram(unsigned char lfn, unsigned char *dest, unsigned int length) {...} #define POKE(A,X) (*(unsigned char *)A) = (X) #define PEEK(A) (*(unsigned char *)A) unsigned char *filename = "cyberwing.koa"; int main (void) { unsigned char dev; unsigned char addr[2]; unsigned char* bitmap_buffer; /* graphic buffer */ unsigned char* screen_buffer; unsigned char* color_buffer; /* Allocating mem for backup */ bitmap_buffer=(unsigned char*)malloc(8000); if(bitmap_buffer==NULL) exit(1); screen_buffer=(unsigned char*)malloc(1000); if(screen_buffer==NULL) exit(1); color_buffer=(unsigned char*)malloc(1000); if(color_buffer==NULL) exit(1); /* Clear the screen, set white on black */ bordercolor (COLOR_BLACK); bgcolor (COLOR_BLACK); textcolor (COLOR_GRAY3); cursor (0); clrscr (); /* load routines */ dev = PEEK(0x00ba); /* get current device number */ /* open the file */ if (cbm_open(1, dev, 2, filename)) {...} /* read file load address */ if (cbm_read(1, &addr, 2) != 2) {...} /* make sure load address is $4400 or $6000 */ if (addr[0] != 0 || (addr[1] != 0x44 && addr[1] != 0x60)) {...} /* load bitmap data */ if (loadtoram(1, (unsigned char *)bitmap_buffer, 8000)) {...} memcpy ((void*)0x2000, bitmap_buffer, 8000); /* load screen data */ if (loadtoram(1, (unsigned char *)screen_buffer, 1000)) {...} memcpy ((void*)0x0400, screen_buffer, 1000); /* load colour ram */ if (loadtoram(1, (unsigned char*)color_buffer, 1000)) {...} memcpy ((void*)0xd800, color_buffer, 1000); /* load background colour into $d021 */ if (loadtoram(1, (unsigned char *)0xd021, 1)) {...} /* done */ cbm_close(1); POKE(0xd011, 0x3b); /* enable bitmap mode */ POKE(0xd016, 0x18); /* enable multicolour */ POKE(0xd018, 0x1f); /* screen at $0400 bitmap at $2000 */ POKE(0xd020, 0x00); /* black border */ /* Here follows: wait for a key, and "cleanup" code */ ... } ------------------------ snap ------------------------------------- After starting this little routine, the screen messed up. Could anyone help? Thanks, Tim Schürmann tischuer_at_web.de P.S.: Please excuse my really bad english :) ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-01-13 12:41:08 CET