Running H8 native from Cyos
Credit to athlor for figuring this out.
Every bytecode program uses a small native program to launch the bytecode and it's embedded in the file 'main.e'. That file is 177 bytes in length and has 3 subroutines. The 1st is the main entry point and offset by a 44 byte header. It's possible to insert your own H8 code there and use an RTS to exit and have the Cybiko in a perfectly stable condition.
To demonstrate the idea 2 sample programs where made, one turns on the green LED and vibrator and the other turns them off.
Disassembly of sdk_main.e --------------------------------- 00000000 91AF 0002 ; 00000004 0000 003C ; 00000008 0000 0134 ; 0000000C 0000 0000 ; 00000010 0000 0029 ; 00000014 0000 0020 ; 00000018 0000 0000 ; 0000001C 0000 0034 ; 00000020 0000 0004 ; 00000024 0000 0038 ; 00000028 0000 0004 ; --------------------------------- ; *Entry Point* 0000002C 0D03 MOV.W R0,R3 0000002E 7A000000003C MOV.L #$0000003C,ER0 00000034 01006DF2 MOV.L ER2,@-ER7 00000038 0F92 MOV.L ER1,ER2 0000003A 0D31 MOV.W R3,R1 0000003C 5E000020 JSR @#$00000020 00000040 0B97 ADDS.L #4,ER7 00000042 5470 RTS --------------------------------- 00000044 7A000000003C MOV.L #$0000003C,ER0 0000004A 79010002 MOV.W #$0002,R1 0000004E 5E00002A JSR @#$0000002A 00000052 5470 RTS --------------------------------- 00000054 7A000000003C MOV.L #$0000003C,ER0 0000005A 5E000027 JSR @#$00000027 0000005E 5470 RTS --------------------------------- 00000060 00 00 00 28 00 00 00 18 ( 00000068 6F 72 64 69 6E 61 6C 73 o r d i n a l s 00000070 00 43 79 57 69 6E 2E 64 C y W i n . d 00000078 6C 00 66 69 6E 64 65 72 l f i n d e r 00000080 2E 61 70 70 00 62 79 74 . a p p b y t 00000088 65 63 6F 64 65 2E 64 6C e c o d e . d l 00000090 00 83 00 00 22 03 00 00 ƒ " 00000098 38 03 00 00 34 83 00 00 8 4 ƒ 000000A0 2E 03 00 00 04 03 00 00 . 000000A8 1A 03 00 00 2A 83 00 00 * ƒ 000000B0 10 00 00 00 00 00 00 00 Length: 177 bytes (b1h)
Original 'main.e; file: 000000 91AF 0002 ; Common in all main.e [Header=11 words] 000004 0000 003C ; Grows w/len 000008 0000 0134 ; Unrelated to length 00000C 0000 0000 ; Common in all 000010 0000 0029 ; Common w/ NOTES_main 000014 0000 0020 ; Grows w/len 000018 0000 0000 00001C 0000 0034 ; Poss end of code start of data 000020 0000 0004 ; Common in all 000024 0000 0038 ; Grows w/len 000028 0000 0004 ; Common in all ---------------------------------------------------------- ; *Entry Point* 00002C 0D03 MOV.W R0,R3 00002E 7A00 0000 003C MOV.L #H'0000003C,ER0 000034 0100 6DF2 MOV.L ER2,@-ER7 000038 0F92 MOV.L ER1,ER2 00003A 0D31 MOV.W R3,R1 00003C 5E00 0020 JSR @H'000020:24 000040 0B97 ADDS #4,ER7 000042 5470 RTS ---------------------------------------------------------- 000044 7A00 0000 003C MOV.L #H'0000003C,ER0 00004A 7901 0002 MOV.W #H'0002,R1 00004E 5E00 002A JSR @H'00002A:24 000052 5470 RTS ---------------------------------------------------------- 000054 7A00 0000 003C MOV.L #H'0000003C,ER0 00005A 5E00 0027 JSR @H'000027:24 00005E 5470 RTS ; Code area is 52 bytes (34h) ... And my hacked versions: --------------------------------------------------------- ; *ENTRY POINT* 00002C 7F61 7030 BSET #3,@H'FFFF61:8 ; Turn Green LED ON 000030 7F60 7260 BCLR #6,@H'FFFF60:8 ; Turn Vibrator ON 000034 5470 RTS ; Return 000036 0000 NOP 000038 0000 NOP 00003A 0000 NOP 00003C 0000 NOP 00003E 0000 NOP 000040 0000 NOP 000042 0000 NOP ... And: --------------------------------------------------------- ; *ENTRY POINT* 00002C 7F61 7230 BCLR #3,@H'FFFF61:8 ; Turn Green LED OFF 000030 7F60 7060 BSET #6,@H'FFFF60:8 ; Turn Vibrator OFF 000034 5470 RTS ; Return