z80playground / cpm-fat

CP/M for the Z80 Playground that runs on the FAT disk format
GNU General Public License v3.0
20 stars 9 forks source link

Reinstate ^C #40

Closed gd-99 closed 3 years ago

gd-99 commented 3 years ago

Fantastic achievement getting a z80 to run CP/M on top of a FAT file system using the CH376 module. I had a stab at it for my own SBC and gave up so simply modified your implementation to run on my SBC. I have found however that in some cases, particularly when running a program, I couldn't consistently bail out of the thing with a control-c if there was no built in quit /exit. To try and get around this I have re-implemented some of the code from the original CPM22.asm. I'm not a programmer but my hack seems to work. Thought I should feed it back in case it is of some use to you. With the changes my compiled bdos turns in at 2.1k.

So down to business: at the top of BDOS.ASM I added the control key constants at around line 26 - modify to suit. BS EQU 08H ;backspace TAB EQU 09H ;tab LF EQU 0AH ;line feed FF EQU 0CH ;form feed CR EQU 0DH ;carriage return CNTRLP EQU 10H ;control-p CNTRLR EQU 12H ;control-r CNTRLS EQU 13H ;control-s CNTRLU EQU 15H ;control-u CNTRLX EQU 18H ;control-x CNTRLZ EQU 1AH ;control-z (end-of-file mark) DEL EQU 7FH ;rubout

The main code differences is around the BDOS_Console_Input function Here I replaced the original _cp 32
ret c
call CORE_printa With call PRINT_CHKCTRL_CHAR ;Print converted CTRL character

;** ; Output (A) to the screen. If it is a control character ; (other than carriage control), use ^x format. ; Uses CHKCHAR ; PRINT_CHKCTRL_CHAR: call CHKCHAR ;Carriage control? jp nc,PRINT_CHAR ;not a control, use normal output. push af ld e,'^' ;for a control character, precede it with '^'. call BDOS_Console_Output pop af or '@' ;and then use the letter equivalent. ld e,a
jp BDOS_Console_Output

PRINT_CHAR: ret z ;Do nothing with zero ld e,a ;Put the character in e jp BDOS_Console_Output ;...and print it using the built-in function

;** ; Check character in (A). Set the zero flag on a carriage ; control character and the carry flag on any other control ; character. ; CHKCHAR: cp CR ;check and exclude for carriage return, line feed, ret Z ;backspace or a tab. cp LF ;Line Feed ret Z cp TAB ;TAB ret Z cp BS ;Backspace ret Z cp CNTRLP ;control-p ret Z cp CNTRLR ;control-r ret Z cp CNTRLS ;control-s ret Z cp CNTRLU ;control-u ret Z cp CNTRLX ;control-x ret Z cp CNTRLZ ;control-z (end-of-file mark) ret Z cp CNTRLC ;is typed. Control-c? jp z,0 ;yes, reboot now. cp 31 ;was 32, but I started missing ' ' space chars ret I sift out some other popular ^chars but not doing anything special with them. The important one here is the CP CNTRLC, which if a mach simply does a jump to 0, a regular way of dropping back to BDOS.

As a belt 'n braces I have also modified the BDOS_Get_Console_Status: routine to:- BDOS_Get_Console_Status: ; Is there a key available? If there is, FF, otherwise 00 ;jp CORE_char_available
call CORE_char_available ;Character availabel? ret z ;Nothing available just return call BDOS_Console_Input ;There is something, go and get it cp CNTRLS jp nz,CONSTA_EXIT ;if not control-s, return with zero cleared call BDOS_Console_Input ;halt processing until another char cp CNTRLC ;is typed. Control-c? jp z,0 ;yes, reboot now. xor a ;no, just pretend nothing was ever ready. ret

CONSTA_EXIT: ld a, 1 ;set (A) to non zero to mean something is ready. ret

I can confirm with these changes a) the ctrl-char (except the filtered ones) get printed to the console ala ^n and b) ^c dumps me out of a "stuck" program - assuming it still has keyboard input - back to CP/M. If nothing else having the ctrl char printed on the console looks nice!

By the by I have also modified CPM.ASM for my use to use an additional config file to set a switch to auto boot straight into CP/M, without stopping at the Monitor first. Happy to detail these changes in a separate post if this would be useful?

All the best,

Glyn.

skx commented 3 years ago

Happy to detail these changes in a separate post if this would be useful?

I would be interested to see that at least, though it might be easier to follow if you showed the output of git diff after making your changes than showing code inline :)

gd-99 commented 3 years ago

@skx I will open a new issue - as there are a number of code blocks to add. I totally agree with your diff suggestion, unfortunately I'm not very well up on using git or git diff and would be quite concerned about mucking up any of the original work. I will re-edit this post to insert the link to the new "issue" once its been created. I may as well close this post at the same time as this isn't an issue with the original system?

gd-99 commented 3 years ago

I have provided a write of the modification as issue #42 Hope this is of some use to you.