COP8C - Executing Initialization Code

COP8C

Byte Craft's COP8C compiler uses 5 bytes at 0x0000 for initialization. It calls the function __STARTUP() if it is defined, and then jumps to main().

If you want your own initialization code executed on reset instead, use the directive #pragma option NOINIT to turn off the default initialization, and place your own code at 0x0000.

/* INITCOP8 V1.0 IMPORTANT NOTES:
    1. Your init code must be the FIRST code compiled
       (after # directives, but before any functions). 
    2. You must call __STARTUP() (if used) and main() in
       your init code. 
    3. The compiler always leaves room for its default
       init code when it allocates ROM for C source.  Your
       init code must use inline assembly with an ORG to start
       at 0x0000, but because it is compiled before other code,
       you have an unlimited number of bytes for initialization. 

   This code may be adapted for any purpose when used with
   the COP8C Code Development System.  No warranty is implied
   or given as to its usability for any purpose.
   Copyright April 1996, 2001, Byte Craft Limited, All rights reserved.
   Byte Craft Limited, Waterloo, Ontario, Canada N2J 4E4  */ 

/* Turn off default initialization */ #pragma option NOINIT;

#pragma memory ROM [0x00f0] @ 0;
#pragma memory RAM [112] @ 0;
#pragma memory RAM [0xc] @ 0xf0;
#pragma has 840;

 /* Program status word */ #pragma portrw PSW @ 0xef;

/* Interrupt Enable Bit */ #define GIE 0 
#asm
   ORG   0         ;Start at 0000
   RBIT  GIE,PSW   ;Turn off interrupts
   JSRL  __STARTUP ;Call startup function
   JMPL  main      ;Jump to main()
#endasm

 /* Optional startup init function */ 

void __STARTUP(void) { } 

void main(void) {     
  /* ... */
}