However, I was wondering whether it might be better if I redirected OSWRCH to my code? That way, PRINT statements in BASIC would go through the text wrapping directly without having to CALL a machine code routine explicitly. It's all running in MODE 7 to minimise space usage anyway, so there won't be any control sequences to worry about interfering with. It sort of feels like the way Acorn would have expected you to do it.
I'm thinking I will need to have an initialisation routine to get the address of the real MOS routine (since I don't know what machine it is running on) which will be in WRCHV at &20E-&20F, save that address into bytes 2-3 of a JMP instruction, and then have my code call that instead of OSWRCH:
Code: Select all
.wrap_on LDA &20F \ high byte of WRCHV BPL no_init \ skip this if WRCHV is pointing to RAM STA orig_oswrch+2 \ third byte of JMP instruction LDA &20E \ low byte of WRCHV STA orig_oswrch+1 \ second byte of JMP instruction .no_init LDA new_oswrch STA &20E LDA new_oswrch+1 STA &20F RTS .wrap_off LDA orig_oswrch+2 \ third byte of JMP instruction BPL woff0 \ skip this if it is still pointing to RAM STA &20F \ high byte of WRCHV LDA orig_oswrch+1 \ second byte of JMP instruction STA &20E \ low byte of WRCHV .woff0 RTS .orig_oswrch \ JSR or JMP here instead of &FFEE JMP orig_oswrch \ this will get overwritten by wrap_on .new_oswrch \ do text wrappingy stuff JMP orig_oswrch
Or is this a Really Bad Idea for some reason I have not thought of?