📄 datapage.c
字号:
// input 16 bit offset is bit15..bit0
// ppage values: ppage7..ppage0
// epage values: epage7..epage0
// dpage values: dpage7..dpage0
// rpage values: rpage7..rpage0
PSHX ;// D contains bit15..bit0
PSHB ;// store page
TFR X,D ;// D is cheaper to shift
LSLD ;// D contains 0 bit14..bit0, C contains bit15
BCC Below8000 ;// bit15 == 0?
// from 0x8000 to 0xFFFF
LSLD ;// D contains 00 bit13..bit0, C contains bit14
BCC BelowC000
PULB ;// cleanup stack
LDAB #0x7F
PULX
RTS ;// returns 0b0111 1111 11 bit13...bit0
BelowC000: ;// from 0x8000 to 0xBFFF
TFR D,X
PULB ;// cleanup stack
SEC
RORB
RORX
LSRB
RORX
LEAS 2,SP
RTS ;// returns 0b01 ppage7..ppage0 bit13...bit0
Below8000:
LSLD ;// D contains 00 bit13..bit0, C contains bit14
BCC Below4000
;// from 0x4000 to 0x7FFF
PULB ;// cleanup stack
LDAB #0x7F
PULX
RTS ;// returns 0b0111 1111 01 bit13...bit0
Below4000:
LSLD ;// D contains 000 bit12..bit0, C contains bit13
BCC Below2000
// from 0x2000 to 0x3FFF
PULB ;// cleanup stack
PULX
ADDX #(0xE000-0x2000)
LDAB #0x0F
RTS ;// returns 0b0000 1111 111 bit12...bit0
Below2000:
LSLD ;// D contains 0000 bit11..bit0, C contains bit12
BCC Below1000
// from 0x1000 to 0x1FFF
PULB
LDAA #0x10
MUL
EORB 0,SP
EORB #0x10 ;// clear 1 bit
STAB 0,SP
TFR A,B
PULX
RTS
Below1000:
LSLD ;// D contains 0000 0 bit10..bit0, C contains bit11
BCC Below0800
// from 0x0800 to 0x0FFF
LSLD ;// D contains 0000 00 bit9..bit0, C contains bit10
BCC Below0C00
// from 0x0C00 to 0x0FFF
PULB ;// cleanup stack
LDAB #0x13
PULX
ADDX #0xF000
RTS ;// returns 0b0001 0011 1111 11 bit9...bit0
Below0C00:
// from 0x0800 to 0x0BFF
PULB
LDAA #0x04
MUL
EORB 0,SP
EORB #0x08
STAB 0,SP
TFR A,B
ORAB #0b00010000
PULX
RTS
Below0800:
PULB
PULX
CLRB
RTS
}
}
/*--------------------------- _FAR_COPY_RC HCS12X Routines --------------------------------
copy larger far memory blocks
There are the following memory block copy routines:
_COPY : 16 bit logical copies.
Src and dest are both near. Note: implemented in rtshc12.c and not here.
_FAR_COPY_RC HC12/HCS12 struct copy routine.
Expects HC12/HCS12 logical 24 bit address.
Note: Does not exist for the HCS12X.
The HC12/HCS12 implementation is implemented above.
_FAR_COPY_GLOBAL_GLOBAL_RC:
_FAR_COPY_GLOBAL_LOGICAL_RC:
_FAR_COPY_LOGICAL_GLOBAL_RC:
_FAR_COPY_LOGICAL_LOGICAL_RC:
_FAR_COPY_NEAR_GLOBAL_RC:
_FAR_COPY_NEAR_LOGICAL_RC:
_FAR_COPY_GLOBAL_NEAR_RC:
_FAR_COPY_LOGICAL_NEAR_RC: HCS12X specific far copy routine. The name describes what the src/dest address format are.
All near src arguments are passed in X, all 24 bit src in X/B.
All near dest arguments are passed in Y, all 24 bit src in Y/A.
(Note: HC12 _FAR_COPY_RC is using X/A as src and Y/B as dest, so the register usage is not the same!)
Arguments :
- B:X : src address (for NEAR/_COPY: only X)
- A:Y : dest address (for NEAR/_COPY: only Y)
- number of bytes to be copied behind return address (for _COPY: in D register). The number of bytes is always > 0
Result :
- memory area copied
- no registers are saved, i.e. all registers may be destroyed
- for _COPY: D contains 0.
- for HCS12X _FAR_COPY_... routines: GPAGE state is unknown
*/
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_GLOBAL_GLOBAL_RC(void) {
__asm {
PSHD
PSHY
LDY 4,SP ;// load return address
LDD 2,Y+ ;// load size
STY 4,SP ;// store return address
PULY
PSHD
LDAB 3,SP
Loop:
STAB __GPAGE_ADR__
GLDAA 1,X+
MOVB 2,SP,__GPAGE_ADR__
GSTAA 1,Y+
DECW 0,SP
BNE Loop
LEAS 4,SP
_SRET ;// debug info only: This is the last instr of a function with a special return
RTS
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _SET_PAGE_REG_HCS12X(void) {
// Sets the page contained in A to the register controlling the logical adr contained in X.
// saves the old page before and returns it in A together with the page address just below the return address.
// X/Y both remain valid.
__asm {
PSHX
// 0000..FFFF
CPX #0x8000
BLO _LO8000
LDX #__PPAGE_ADR__
BRA Handle
_LO8000:
// 0000..7FFF
CPX #0x1000
BLO _LO1000
LDX #__RPAGE_ADR__
BRA Handle
_LO1000:
LDX #__EPAGE_ADR__
Handle:
LDAA 0,X ;// load old page register content
STAB 0,X ;// set new page register
STX 4,SP
PULX
RTS
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_GLOBAL_LOGICAL_RC(void) {
__asm {
STAB __GPAGE_ADR__
EXG X,Y
TFR A,B
PSHY ;// space to store size
PSHX ;// allocate some space where _SET_PAGE_REG_HCS12X can return the page
LDY 4,SP ;// load return address
LDX 2,Y+ ;// load size
STY 4,SP
LDY 2,SP ;// restore dest pointer
STX 2,SP ;// store size
LDX 0,SP ;// reload src pointer
__PIC_JSR(_SET_PAGE_REG_HCS12X)
Loop: GLDAB 1,Y+
STAB 1,X+
DECW 2,SP
BNE Loop
PULX ;// reload page register address
STAA 0,X ;// restore old page content (necessary if it was PPAGE)
PULX ;// clean up stack
_SRET ;// debug info only: This is the last instr of a function with a special return
RTS
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_LOGICAL_GLOBAL_RC(void) {
__asm {
STAA __GPAGE_ADR__
PSHY ;// space to store size
PSHX ;// allocate some space where _SET_PAGE_REG_HCS12X can return the page
LDY 4,SP ;// load return address
LDX 2,Y+ ;// load size
STY 4,SP
LDY 2,SP ;// restore dest pointer
STX 2,SP ;// store size
LDX 0,SP ;// reload src pointer
__PIC_JSR(_SET_PAGE_REG_HCS12X)
Loop: LDAB 1,X+
GSTAB 1,Y+
DECW 2,SP
BNE Loop
PULX
STAA 0,X ;// restore old page content (necessary if it was PPAGE)
PULX ;// clean up stack
_SRET ;// debug info only: This is the last instr of a function with a special return
RTS
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_LOGICAL_LOGICAL_RC(void) {
__asm {
PSHA
__PIC_JSR(_CONV_LOGICAL_TO_GLOBAL);
PULA
__PIC_JMP(_FAR_COPY_GLOBAL_LOGICAL_RC);
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_NEAR_GLOBAL_RC(void) {
__asm {
CLRB
__PIC_JMP(_FAR_COPY_LOGICAL_GLOBAL_RC);
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_NEAR_LOGICAL_RC(void) {
__asm {
PSHA
__PIC_JSR(_CONV_NEAR_TO_GLOBAL);
PULA
__PIC_JMP(_FAR_COPY_GLOBAL_LOGICAL_RC);
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_GLOBAL_NEAR_RC(void) {
__asm {
CLRA /* near to logical (we may have to use another runtime if this gets non trivial as well :-( */
__PIC_JMP(_FAR_COPY_GLOBAL_LOGICAL_RC);
}
}
#ifdef __cplusplus
extern "C"
#endif
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
void NEAR _FAR_COPY_LOGICAL_NEAR_RC(void) {
__asm {
EXG A,B
EXG X,Y
PSHA
__PIC_JSR(_CONV_NEAR_TO_GLOBAL);
PULA
EXG A,B
EXG X,Y
__PIC_JMP(_FAR_COPY_LOGICAL_GLOBAL_RC);
}
}
/* _FAR_COPY_LOGICAL_GLOBAL: is used by some old wizard generated projects. Not used by current setup anymore */
#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
}
}
#endif /* __HCS12X__ */
/*----------------- end of code ------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -