📄 ds400rom.c
字号:
// ROM REDIRECT TABLE FUNCTIONS (denoted with ROMRT)//#define ROMRT_KERNELMALLOC ( 1 * ROMRT_ENTRYSIZE)#define ROMRT_KERNELFREE ( 2 * ROMRT_ENTRYSIZE)#define ROMRT_MALLOC ( 3 * ROMRT_ENTRYSIZE)#define ROMRT_FREE ( 4 * ROMRT_ENTRYSIZE)#define ROMRT_MALLOCDIRTY ( 5 * ROMRT_ENTRYSIZE)#define ROMRT_DEREF ( 6 * ROMRT_ENTRYSIZE)#define ROMRT_GETFREERAM ( 7 * ROMRT_ENTRYSIZE)#define ROMRT_GETTIMEMILLIS ( 8 * ROMRT_ENTRYSIZE)#define ROMRT_GETTHREADID ( 9 * ROMRT_ENTRYSIZE)#define ROMRT_THREADRESUME (10 * ROMRT_ENTRYSIZE)#define ROMRT_THREADIOSLEEP (11 * ROMRT_ENTRYSIZE)#define ROMRT_THREADIOSLEEPNC (12 * ROMRT_ENTRYSIZE)#define ROMRT_THREADSAVE (13 * ROMRT_ENTRYSIZE)#define ROMRT_THREADRESTORE (14 * ROMRT_ENTRYSIZE)#define ROMRT_SLEEP (15 * ROMRT_ENTRYSIZE)#define ROMRT_GETTASKID (16 * ROMRT_ENTRYSIZE)#define ROMRT_INFOSENDCHAR (17 * ROMRT_ENTRYSIZE)#define ROMRT_IP_COMPUTECHECKSUM_SOFTWARE (18 * ROMRT_ENTRYSIZE)#define ROMRT_0 (19 * ROMRT_ENTRYSIZE) // undefined#define ROMRT_DHCPNOTIFY (20 * ROMRT_ENTRYSIZE)#define ROMRT_ROM_TASK_CREATE (21 * ROMRT_ENTRYSIZE)#define ROMRT_ROM_TASK_DUPLICATE (22 * ROMRT_ENTRYSIZE)#define ROMRT_ROM_TASK_DESTROY (23 * ROMRT_ENTRYSIZE)#define ROMRT_ROM_TASK_SWITCH_IN (24 * ROMRT_ENTRYSIZE)#define ROMRT_ROM_TASK_SWITCH_OUT (25 * ROMRT_ENTRYSIZE)#define ROMRT_OWIP_READCONFIG (26 * ROMRT_ENTRYSIZE)#define ROMRT_SETMACID (27 * ROMRT_ENTRYSIZE)#define ROMRT_UNDEREF (28 * ROMRT_ENTRYSIZE)#define GETC \ clr a \ movc a, @a+dptr // expects function number in R6_B3 (low byte) & R7_B3 (high byte)void _romcall(void) _naked{_asm push dpx ; dptr0 preserved here push dph push dpl ; point to the address of the table mov dptr, #(ROM_BANK << 16 | ROM_EXPORTTABLE_OFFS) push acc ; acc preserved here push b ; b preserved here inc dptr GETC ; get the address of the table push acc inc dptr GETC add a, R6_B3 ; add function offset to the table mov dpl, a pop acc addc a, R7_B3 mov dph, a ; ; dpx is the same, all in the same bank ; inc dptr ; get the target address of the function we want GETC mov b, a inc dptr GETC mov R3_B3, a mov R4_B3, b mov R5_B3, dpx ; high byte does not change pop b ; b restored here pop acc ; acc restored here pop dpl ; dptr0 preserved here pop dph pop dpx push R3_B3 ; push the target address push R4_B3 push R5_B3 ret ; this is not a ret, it is a call! ; the called function ends with a ret which will return to our original caller._endasm ;}// expects function number in R6_B3 (low byte) & R7_B3 (high byte)void _romredirect(void) _naked{_asm push dpx push dph push dpl push acc ; dptr = CALL_TABLE_TOP + function offset. mov a, #(CALL_TABLE_TOP & 0xff) add a, R6_B3 ; add function offset to the table mov dpl, a mov a, #((CALL_TABLE_TOP >> 8) & 0xff) addc a, R7_B3 mov dph, a mov dpx, #((CALL_TABLE_TOP >> 16) & 0xff) movx a, @dptr ; read high byte mov R5_B3, a inc dptr movx a, @dptr ; read mid byte mov R4_B3, a inc dptr movx a, @dptr ; read low byte mov R3_B3, a pop acc ; restore acc and dptr pop dpl pop dph pop dpx push R3_B3 ; push low byte of target address push R4_B3 push R5_B3 ; push high byte of target address ret ; this is not a ret, it is a call! ; the called function ends with a ret which will return to our original caller._endasm; }// This macro is invalid for the standard C preprocessor, since it// includes a hash character in the expansion, hence the SDCC specific// pragma.#pragma sdcc_hash +#define ROMCALL(x) \ mov R6_B3, #(x & 0xff) \ mov R7_B3, #((x >> 8) & 0xff) \ lcall __romcall#define ROMREDIRECT(x) \ mov R6_B3, #(x & 0xff) \ mov R7_B3, #((x >> 8) & 0xff) \ lcall __romredirect// init_rom: the ds400 ROM_INIT ROM function.unsigned char init_rom(void xdata *loMem, void xdata *hiMem) _naked{ // shut compiler up about unused parameters. loMem; hiMem; _asm ; load params. ; loMem is already in DPTR. mov r2, dpx mov r1, dph mov r0, dpl ; hiMem is in _init_rom_PARM_2 mov dptr, #_init_rom_PARM_2 mov r5, dpx mov r4, dph mov r3, dpl ROMCALL(ROMXT_ROM_INIT) ; result is in acc, move to dpl for C convention. mov dpl, a ret_endasm ;}// DSS_gettimemillis: note that the ROM actually returns 5 bytes of time,// we're discarding the high byte here.unsigned long task_gettimemillis_long(void) _naked{_asm ; no parameters to load. ROMREDIRECT(ROMRT_GETTIMEMILLIS) ; results in r4 - r0, return in DPTR/B mov dpl, r0 mov dph, r1 mov dpx, r2 mov b, r3 ret_endasm;}unsigned char task_getthreadID(void) _naked{_asm ; no parameters to load. ROMREDIRECT(ROMRT_GETTHREADID) ; results in acc, return in dpl mov dpl, a ret_endasm; }unsigned int task_gettickreload(void){ return DSS_timerReload;}void task_settickreload(unsigned int rl){ DSS_timerReload = rl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -