Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!hphalle6!behrenss From: behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) Subject: Using SRAM while developing Firmware (a "guide") Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem) Organization: Technische Universitaet Muenchen, Germany Date: Mon, 11 Oct 1993 10:51:28 GMT Message-ID: Lines: 206 Hallo, here's the promised little "essay" on using SRAM instead of EPROM while developing a card. I assume that you have a pretty good knowledge of the GS's hardware and bus, otherwise you wouldn't need this info. It is really quite simple: An SRAM is pin-compatible with an EPROM of the same size. Pin 27, however, is A14 (or /PGM for smaller sizes) on the EPROM and /WE on the SRAM. Thus, to be able to use either EPROM or SRAM have a jumper that connects Pin 27 to your EPROM bank-switching device in one position and to a logic that serves /WE in the other. This has one limitation: If you actually _use_ the space addressed through A14, you will have to do some more work. In that case, connect the signal from the bank-switching logic (A14) to Pin 1 of the SRAM. If you use a 27C512, I can't help you ... there are no 64k*8 SRAMs to my knowledge. As far as the /WE logic is concerned: All it has to do is to trap write cycles to Cs00 and C800 and pull /WE low on these. This fits easily into the GAL that already serves /OE, /CE and A8 through A10 on the EPROM. If you do not use a GAL for that purpose, consider doing so. You can do the same things with TTL logic, but it needs more space and chips and is therefore more expensive. Appended is the loader I use for my current hardware project. It's an EXE that loads an SRAM in a slot with information from a file. Assumptions this code makes: - The C800 space in the EPROM (from 2nd 256-byte "page" on) is switched in at C900 through CFBF (it's that way on my card since it makes address decoding easier). Limitations this code has: - Bank switching on the EPROM has not been "implemented" since my firmware is so small right now it's not necessary. These assumption and limitations are easily removed/replaced, though. Have fun developing Soenke ========== cut here to get C code ======================== #include #include #include int main (int argc, char *argv[]) { size_t fsize; int slot; int i; FILE *fp; unsigned char *buffer; volatile unsigned char *writeto; unsigned char *freebuf; if (argc != 3) { fprintf(stderr,"Usage: %s \n",argv[0]); exit (-1); } slot = atoi (argv[2]); if (slot < 1 || slot > 7) { fprintf(stderr,"%s: parameter was invalid. It has to" " be an integer between 1 and 7.\n",argv[0]); fprintf(stderr,"It was: %s\n",argv[1]); exit (-1); } fp = fopen(argv[1],"rb"); if (fp == NULL) { fprintf(stderr,"%s: Unable to open file %s\n",argv[0],argv[1]); perror(argv[1]); exit (-1); } fseek(fp, 0, SEEK_END); fsize = ftell(fp); fseek(fp, 0, SEEK_SET); /* Take out if you bank-switch !!! */ if (fsize > 0x07BF) { fprintf(stderr,"I'm terribly sorry, this version of %s does" " not support bank-switched EPROMs. Your input\n" "file is too large.\n",argv[0]); if (fclose (fp) == EOF) { fprintf(stderr,"Also, the file %s could not be " "properly closed. Its contents may be lost\n",argv[1]); } free (buffer); exit (-1); } buffer = malloc (fsize); if (buffer == NULL) { fprintf(stderr,"%s: Unable to allocate memory for file" " buffer\n", argv[0]); exit (-1); } fread ((void *) buffer, 1UL, fsize, fp); if (ferror(fp)) { fprintf(stderr,"%s: An error occured while trying to read" " from %s\n",argv[0],argv[1]); perror(argv[1]); if (fclose (fp) == EOF) { fprintf(stderr,"Also, the file could not be properly" " closed. Its contents may be lost\n"); } exit (-1); } /* * Now that I finally have the contents of my file, let's write them * to the slot SRAM. */ /* * First, check if the slot is switched in at all. */ { volatile unsigned char *slotreg = (unsigned char *) 0x00C02D; unsigned char mask = 0x01 << slot; if ((*slotreg & mask) == 0) { /* Slot is set to internal */ fprintf (stderr,"%s: Slot %d is set to internal." " Please change and reboot\n",argv[0],slot); if (fclose (fp) == EOF) { fprintf(stderr,"Also, the file %s could not" " be properly closed. Its contents may be" " lost\n",argv[1]); } free (buffer); exit (-1); } } /* It apparently is ... so let's continue with writing the stuff * out actually. */ freebuf = buffer; /* Cs00 space first */ writeto = (unsigned char *) 0x00C000 + (0x0100 * slot); for (i = 0; i < 0x100; i++) { /* write out the first 256 bytes */ *writeto++ = *buffer++; } /* Continue with C900 to CFBF space */ writeto = (unsigned char *) 0x00C900; for (i = 0,fsize -= 0x100; i < fsize; i++) { assert (writeto < (unsigned char *) 0xCFC0); assert (writeto >= (unsigned char *) 0xC900); *writeto++ = *buffer++; } /* I'm done ... clean up and exit */ buffer = freebuf; if (fclose (fp) == EOF) { fprintf(stderr,"%s: The file %s could not be properly" " closed. Its contents may be lost\n",argv[0],argv[1]); free (buffer); exit (-1); } free (buffer); printf("File successfully loaded into firmware space of slot %d\n", slot); return (0); } -- =========================================================================== More than silver, more than gold, I need ! behrenss@informatik. electricity. I need it for my dreams. ! tu-muenchen.de (RACTER) ! FIDO: 2:246/13 Soenke Behrens Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!cs.utexas.edu!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!hphalle6!behrenss From: behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) Subject: Re: Using SRAM while developing Firmware (a "guide") References: Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem) Organization: Technische Universitaet Muenchen, Germany Date: Tue, 12 Oct 1993 00:43:29 GMT Message-ID: Lines: 65 behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) writes: >Hallo, Again, just goes to show how easy it is to mess up real bad if you're not careful ... yeah right. I forgot something important without which the whole scheme won't work. > /* It apparently is ... so let's continue with writing the stuff > * out actually. > */ > freebuf = buffer; Insert some code here ....: asm { sei sta >$CFFE } Hope that works now, haven't tested the sta yet actually .... > /* Cs00 space first */ > > writeto = (unsigned char *) 0x00C000 + (0x0100 * slot); > for (i = 0; i < 0x100; i++) > { /* write out the first 256 bytes */ > *writeto++ = *buffer++; > } > /* Continue with C900 to CFBF space */ > writeto = (unsigned char *) 0x00C900; > for (i = 0,fsize -= 0x100; i < fsize; i++) > { > assert (writeto < (unsigned char *) 0xCFC0); > assert (writeto >= (unsigned char *) 0xC900); > *writeto++ = *buffer++; > } And here too: asm { cli } Sorry for that. W/O disabling interrupts and switching in your ROM space, you get into a real mess .... Soenke -- =========================================================================== More than silver, more than gold, I need ! behrenss@informatik. electricity. I need it for my dreams. ! tu-muenchen.de (RACTER) ! FIDO: 2:246/13 Soenke Behrens