#if EPAGE_LOW_BOUND >= EPAGE_HIGH_BOUND || EPAGE_HIGH_BOUND >= DPAGE_LOW_BOUND || DPAGE_LOW_BOUND >= DPAGE_HIGH_BOUND || DPAGE_HIGH_BOUND >= PPAGE_LOW_BOUND || PPAGE_LOW_BOUND >= PPAGE_HIGH_BOUND
#error
#endif
#if DPAGE_HIGH_BOUND+1 != PPAGE_LOW_BOUND
#error
#endif
--------------------------- _LOAD_FAR_24 ----------------------------------*/
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _LOAD_FAR_24(void) {
#if USE_SEVERAL_PAGES
__asm {
PSHX ;// save X register
__PIC_JSR(_GET_PAGE_REG)
BEQ L_NOPAGE
PSHA ;// save A register
LDAA 0,X ;// save page register
STAB 0,X ;// set page register
LDAB 0,Y ;// actual load, overwrites page of address
LDY 1,Y ;// actual load, overwrites offset of address
STAA 0,X ;// restore page register
PULA ;// restore A register
PULX ;// restore X register
RTS
L_NOPAGE:
LDAB 0,Y ;// actual load, overwrites page of address
LDY 1,Y ;// actual load, overwrites offset of address
PULX ;// restore X register
RTS
}
#else /* USE_SEVERAL_PAGES */
__asm {
PSHA ;// save A register
LDAA PAGE_ADDR ;// save page register
STAB PAGE_ADDR ;// set page register
LDAB 0,Y ;// actual load, overwrites page of address
LDY 1,Y ;// actual load, overwrites offset of address
STAA PAGE_ADDR ;// restore page register
PULA ;// restore A register
RTS
}
#endif /* USE_SEVERAL_PAGES */
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _STORE_FAR_24(void) {
#if USE_SEVERAL_PAGES
__asm {
PSHX ;// save X register
__PIC_JSR(_GET_PAGE_REG)
BEQ L_NOPAGE
PSHA
LDAA 0,X ;// save page register
STAB 0,X ;// set page register
MOVW 1,SP, 1,Y ;// store the value passed in X
MOVB 0,SP, 0,Y ;// store the value passed in A
STAA 0,X ;// restore page register
PULA ;// restore A register
PULX ;// restore X register
RTS
L_NOPAGE:
STX 1,Y ;// store the value passed in X
STAA 0,Y ;// store the value passed in X
PULX ;// restore X register
RTS
}
#else /* USE_SEVERAL_PAGES */
__asm {
PSHA ;// save A register
LDAA PAGE_ADDR ;// save page register
STAB PAGE_ADDR ;// set page register
MOVB 0,SP, 0,Y ;// store the value passed in A
STX 1,Y ;// store the value passed in X
STAA PAGE_ADDR ;// restore page register
PULA ;// restore A register
RTS
}
#endif /* USE_SEVERAL_PAGES */
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_LOGICAL_GLOBAL(void) {
__asm {
STAA __GPAGE_ADR__
PSHX ;// allocate some space where _SET_PAGE_REG_HCS12X can return the page
__PIC_JSR(_SET_PAGE_REG_HCS12X)
Loop: LDAB 1,X+
GSTAB 1,Y+
DECW 4,SP
BNE Loop
PULX
STAA 0,X ;// restore old page content (necessary if it was PPAGE)
LDX 4,SP+ ;// load return address and clean stack
JMP 0,X
}
}