After optimization the size of the loadable binary file shrinked to only 65 bytes being 7 for the file header, 14 for hook code installer and 44 for the hook code itself which is small enough to fit whithin the unused 64 bytes reserved for the rs232 queue in 'system variables' area.
; ; Install bitbang routine on printer HOOK ; Borrowed from the book "+50 dicas para o MSX" ; HLPT: EQU 0FFB6H ; Printer hook entry RS2IQ: EQU 0FAF5H ; RS232 queue, 64 bytes ; INSTALL: LD HL, HOOK_PRNTJ232 ; beginning of hook code LD DE, RS2IQ ; destiny, unused rs232 queue LD BC, HOOK_END-HOOK_PRNTJ232 ; block size LDIR ; transfer hook code to its new location LD HL,RS2IQ ; Write the execution entry point for printer hook LD [HLPT+1],HL LD A,0C3H ; then write the CALL instruction (0xC3) LD [HLPT],A RET
The downside is that now we need 10 extra bytes of instructions to move the hook code from the load address to the rs232 queue area. Another necessary modification was on the bit delay loop which used an absolute address jump to simplify the timing (JP NZ,xxxx takes 11 cycles either jump or no jump) . It was replaced by a relative jump (JR NZ,xxxx) .
; delay 1 bit time LD C,T9600 ; 8 8 poke here to change the baud rate DELAY_C: DEC C ; ( 5) JR NZ,DELAY_C ; (12)(/7) ; (12+5)*(TDelay-1)+(7+5) = 17*TDelay - 17 + 12 = (17*Tdelay-5) DJNZ SEND_BITS ; 14(/9) send next bit
The relative jump made the hook code relocatable (now it can be copied and executed from wherever address) and the new timing due to the relative jump ended by enhancing the error rate for 14400 and 19200 baud are now both under 2% of error (it was not intentional though).
Clock = 3.575611 MHz
Baud Tdelay Cycles RealRate Error %
1200 170 2971 1203,50 0,29
2400 83 1492 2396,52 -0,14
4800 39 744 4805,92 0,12
9600 17 370 9663,81 0,66
14400 10 251 14245,4 -1,07
19200 6 183 19538,8 1,76
I could have loaded the hook code directly in the rs232 queue along with the installation code (14+44 bytes) , but I am planning to use the remaining 20 bytes to allow extra stuff like parity.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.