; Received from Kelly Smith's CP/M-NET (tm) ; For publication in Doctor Dobb's Journal ; ; ASSEMBLED, LOADED AND EXECUTED AS SHOWN ; (except for custom equates) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; MBOOT.ASM ver 3.0 ; (revised 5 Nov 80) ; ;MODEM BOOT PROGRAM by Keith Petersen, W8SDZ. ;Thanks to John Taylor for idea of incorporating ;simple terminal routine. Based on MODEM.ASM V2.O, ;by Ward Christensen with enhancements from MODEM527. ; ;CP/M - CP/M file transfer program (receive-only) ; ;This program is intended for use as a way to ;initially transfer MODEM.COM or MODEM.ASM to ;a new user. It may be used with almost any ;modern (see equates). If PMMI or D.C. Hayes modem ;is used, then uses 'ORIGINATE' mode, 300 baud. ; ;A simple terminal routine at start of program allows ;user to communicate with a remote system prior to ;receiving a file to make it possible to down-load ;a file without intervention on the part of the host ;system's operator. ; ;COMMANDS: MBOOT FILENAME.FILETYPE ; or MBOOT A:FILENAME.FILETYPE ; or MBOOT B:FILENAME.FILETYPE ; ;The program will operate as a dumb terminal until ;an 'ESC' key is typed (ctrl-[). It then branches ;to the receive routine. The user may also exit ;to CP/M without opening the receive file by typing ;ctrl-E from the terminal. The values for the escape ;and exit keys may be changed in accordance with the ;needs of the user - some keyboards do not have the ;'ESC' key and/or provision for control characters. ;See equates. ; ;NOTE: Comments for the source code and tabs have been ;removed to make this file easier to transport from one ;System to another. (KBP) ; ;NOTE: NOTE: TABS have been re-expanded for DDJ format ; 0000 = FALSE EQU 0 FFFF = TRUE EQU NOT FALSE ; FFFF = STDCPM EQU TRUE ;TRUE, IS STANDARD CP/M 0000 = ALTCPM EQU FALSE ;TRUE, IS ALTERNATE CP/M FOR HB OR TRS80 ; IF STDCPM 0000 = BASE EQU 0 ENDIF ; IF ALTCPM BASE EQU 4200H ENDIF ; 0005 = EXITCHR EQU 05H ; CTL-E TO EXIT TERM MODE TO CP/M 001B = ESC EQU 1BH ;ESCAPE TO EXIT TERM MODE TO FILE RCVE ; 0000 = FASTCLK EQU FALSE ;TRUE FOR 4 MHZ CLOCK ; FFFF = PMMI EQU TRUE ;TRUE, IS PMMI MODEM 0000 = DCH EQU FALSE ;TRUE, IS D.C. HAYES MODEM ; ;IF YOU ARE USING AN EXTERNAL MODEM (NOT S-1OO PLUG-IN) ;CHANGE THESE EQUATES FOR YOUR MODEM PORT REQUIREMENTS ; 0000 = INITREQ EQU FALSE ;TRUE, IF MODEM PORT INIT. REQ'D 00AA = INITC1 EQU 0AAH ;1ST INIT CHAR TO CTL PORT FOR USART 0040 = INITC2 EQU 40H ;2ND " 004E = INITC3 EQU 4EH ;3RD " 0037 = INITC4 EQU 37H ;4TH " ; IF NOT PMMI AND NOT DCH MODCTLP EQU 02H ;PUT YOUR MODEM CONTROL PORT HERE MODSNDB EQU 80H ;YOUR BIT TO TEST FOR SEND MODSNDR EQU 80H ;YOUR VALUE WHEN READY TO SEND MODRCVB EQU 40H ;YOUR BIT TO TEST FOR RECEI VE MODRCVR EQU 40H ;YOUR VALUE WHEN READY TO RECEIVE MODDATP EQU 03H ;YOUR MODEM DATA PORT ENDIF ;END OF EXTERNAL MODEM EQUATES ; IF PMMI 00C0 = MODCTLP EQU 0C0H 0001 = MODSNDB EQU 1 0001 = MODSNDR EQU 1 0002 = MODRCVB EQU 2 0002 = MODRCVR EQU 2 00C1 = MODDATP EQU 0C1H 00C2 = BAUDRP EQU 0C2H 00C3 = MODCTL2 EQU 0C3H 001D = ORIGMOD EQU 1DH 001E = ANSWMOD EQU 1EH ENDIF ; IF DCH MODCTLP EQU 82H MODSNDB EQU 2 MODSNDR EQU 2 MODRCVB EQU 1 MODRCVR EQU 1 MODDATP EQU 80H MODCTL2 EQU 81H ORIGMOD EQU 87H ANSWMOD EQU 83H ENDIF ; 000A = ERRLIM EQU 10 ; 0001 = SOH EQU 1 0004 = EOT EQU 4 0006 = ACK EQU 6 0015 = NAK EQU 15H 0018 = CAN EQU 18H 000A = LF EQU 10 000D = CR EQU 13 ; 0005 = BDOS EQU BASE+5 005C = FCB EQU BASE+5CH ; 0100 ORG BASE+100H ; 0100 210000 LXI H,0 0103 39 DAD SP 0104 224805 SHLD STACK 0107 314805 LXI SP,STACK 010A CD6204 CALL INITADR 010D CDB804 CALL ILPRT 0110 4D424F4F54 DB 'MBOOT as of ' 011C 31312F352F DB '11/5/80',CR,LF,0 0126 3A5D00 LDA FCB+1 0129 FE20 CPI ' ' 012B C25101 JNZ TERMI 012E CDB804 CALL ILPRT 0131 2B2B4E4F20 DB '++NO FILE NAME SPECIFIED++',CR,LF,0 014E C3F504 JMP EXIT ; 0151 CD7504 TERMI CALL INITMOD 0154 DBC1 IN MODDATP 0156 DBC1 IN MODDATP 0158 CDB804 CALL ILPRT 015B 0D0A544552 DB CR,LF,'TERMINAL MODE',CR,LF 016C 43544C2D45 DB 'CTL-E exits to CP/M, ESC starts file transfer' 0199 0D0A00 DB CR,LF,0 ; 019C CDA104 TERM CALL STAT 019F CAB101 JZ TERML 01A2 CDAC04 CALL KEYIN 01A5 FE05 CPI EXITCHR 01A7 CAF504 JZ EXIT 01AA FE1B CPI ESC 01AC CAC401 JZ RCVFIL 01AF D3C1 OUT MODDATP ; IF NOT DCH 01B1 DBC0 TERML IN MODCTLP ENDIF ; IF DCH TERML IN MODCTL2 ENDIF ; 01B3 E602 ANI MODRCVB 01B5 FE02 CPI MODRCVR 01B7 C29C01 JNZ TERM 01BA DBC1 IN MODDATP 01BC E67F ANI 7FH 01BE CD9404 CALL TYPE 01C1 C39C01 JMP TERM ; 01C4 CD2203 RCVFIL CALL ERASFIL 01C7 CD6903 CALL MAKEFIL 01CA CDB804 CALL ILPRT 01CD 46494C4520 DB 'FILE OPEN, READY TO RECEIVE',CR,LF,0 ; 01EB CD1D02 RCVLP CALL RCVSECT 01EE DAFD01 JC RCVEOT 01F1 CDCA03 CALL WRSECT 01F4 CD1A03 CALL INCRSNO 01F7 CDD002 CALL SENDACK 01FA C3EB01 JMP RCVLP ; 01FD CDE203 RCVEOT CALL WRBLOCK 0200 CDD002 CALL SENDACK 0203 CDAA03 CALL CLOSFIL 0206 CDC704 CALL ERXIT 0209 0D0A545241 DB CR,LF,'TRANSFER COMPLETE$' ; 021D AF RCVSECT XRA A 021E 320705 STA ERRCT ; 0221 060A RCVRPT MVI B,10 0223 CD3D04 CALL RECV 0226 DA3602 JC RCVSERR 0229 FE01 CPI SOH 022B CA7D02 JZ RCVSOH 022E B7 ORA A 022F CA2102 JZ RCVRPT 0232 FE04 CPI EOT 0234 37 STC 0235 C8 RZ ; 0236 0601 RCVSERR MVI B,1 0238 CD3D04 CALL RECV 023B D23602 JNC RCVSERR 023E 3E15 MVI A,NAK 0240 CDD202 CALL SEND 0243 3A0705 LDA ERRCT 0246 3C INR A 0247 320705 STA ERRCT 024A FE0A CPI ERRLIM 024C DA2102 JC RCVRPT ; 024F CDAA03 RCVSABT CALL CLOSFIL 0252 CDC704 CALL ERXIT 0255 2B2B554E41DB '++UNABLE TO RECEIVE BLOCK' 026E 0D0A2B2B41DB CR,LF,'++ABORTING++$' ; 027D 0601 RCVSOH MVI B,1 027F CD3D04 CALL RECV 0282 DA3602 JC RCVSERR 0285 57 MOV D,A 0286 0601 MVI B,1 0288 CD3D04 CALL RECV 028B DA3602 JC RCVSERR 028E 2F CMA 028F BA CMP D 0290 CA9602 JZ RCVDATA 0293 C33602 JMP RCVSERR ; 0296 7A RCVDATA MOV A,D 0297 320505 STA RCVSNO 029A 0E00 MVI C,0 029C 218000 LXI H,BASE+80H ; 029F 0601 RCVCHR MVI B,1 02A1 CD3D04 CALL RECV 02A4 DA3602 JC RCVSERR 02A7 77 MOV M,A 02A8 2C INR L 02A9 C29F02 JNZ RCVCHR 02AC 51 MOV D,C 02AD 0601 MVI B,1 02AF CD3D04 CALL RECV 02B2 DA3602 JC RCVSERR 02B5 BA CMP D 02B6 C23602 JNZ RCVSERR 02B9 3A0505 LDA RCVSNO 02BC 47 MOV B, A 02BD 3A0605 LDA SECTNO 02C0 B8 CMP B 02C1 CACA02 JZ RECVACK 02C4 3C INR A 02C5 B8 CMP B 02C6 C2E202 JNZ ABORT 02C9 C9 RET ; 02CA CDD002 RECVACK CALL SENDACK 02CD C31D02 JMP RCVSECT ; 02D0 3E06 SENDACK MVI A,ACK ; 02D2 F5 SEND PUSH PSW 02D3 81 ADD C 02D4 4F MOV C,A ; IF NOT DCH 02D5 DBC0 SENDW IN MODCTLP ENDIF ; IF DCH SENDW IN MODCTL2 ENDIF ; 02D7 E601 ANI MODSNDB 02D9 FE01 CPI MODSNDR 02DB C2D502 JNZ SENDW 02DE F1 POP PSW 02DF D3C1 OUT MODDATP 02E1 C9 RET ; 02E2 314805 ABORT LXI SP,STACK ; 02E5 0601 ABORTL MVI B,1 02E7 CD3D04 CALL RECV 02EA D2E502 JNC ABORTL 02ED 3E18 MVI A,CAN 02EF CDD202 CALL SEND ; 02F2 0601 ABORTW MVI B,1 02F4 CD3D04 CALL RECV 02F7 D2F202 JNC ABORTW 02FA 3E20 MVI A, ' ' 02FC CDD202 CALL SEND 02FF CDC704 CALL ERXIT 0302 4D424F4F54 DB 'MBOOT PROSRAM CANCELLED$' ; 031A 3A0605 INCRSNO LDA SECTNO 031D 3C INR A 031E 320605 STA SECTNO 0321 C9 RET ; 0322 115C00 ERASFIL LXI D,FCB 0325 0E11 MVI C,17 0327 CD0500 CALL BDOS 032A 3C INR A 032B C8 RZ 032C CDB804 CALL ILPRT 032F 2B2B46494C DB '++FILE EXISTS, TYPE Y TO ERASE:',0 034F CDAC04 CALL KEYIN 0352 F5 PUSH PSW 0353 CD9404 CALL TYPE 0356 CD8D04 CALL CRLF 0359 F1 POP PSW 035A E65F ANI 5FH 035C FE59 CPI 'Y' 035E C2CD04 JNZ MXIT 0361 115C00 LXI D,FCB 0364 0E13 MVI C,19 0366 C30500 JMP BDOS ; 0369 115C00 MAKEFIL LXI D,FCB 036C 0E16 MVI C,22 036E CD0500 CALL BDOS 0371 3C INR A 0372 C0 RNZ 0373 CDC704 CALL ERXIT 0376 2B2B455252 DB '++ERROR - CAN''T MAKE FILE',CR,LF 0391 2B2B444952 DB '++DIRECTORY MUST BE FULL$' ; 03AA 115C00 CLOSFIL LXI D,FCB 03AD 0E10 MVI C,16 03AF CD0500 CALL BDOS 03B2 3C INR A 03B3 C0 RNZ 03B4 CDC704 CALL ERXIT 03B7 2B2B43414E DB '++CAN"T CLOSE FILE$' ; 03CA 2A0905 WRSECT LHLD SECPTR 03CD EB XCHG 03CE 218000 LXI H,BASE+80H 03D1 CDFA04 CALL MOVE128 03D4 EB XCHG 03D5 220905 SHLD SECPTR 03D8 3A0B05 LDA SECINBF 03DB 3C INR A 03DC 320B05 STA SECINBF 03DF FE10 CPI 16 03E1 C0 RNZ ; 03E2 3A0B05 WRBLOCK LDA SECINBF 03E5 B7 ORA A 03E6 C8 RZ 03E7 4F MOV C,A 03E8 114A05 LXI D,DBUF ; 03EB E5 DKWRLP PUSH H 03EC D5 PUSH D 03ED C5 PUSH B 03EE 0E1A MVI C,26 03F0 CD0500 CALL BDOS 03F3 115C00 LXI D,FCB 03F6 0E15 MVI C,21 03F8 CD0500 CALL BDOS 03FB C1 POP B 03FC D1 POP D 03FD E1 POP H 03FE B7 ORA A 03FF C21D04 JNZ WRERR 0402 218000 LXI H,80H 0405 19 DAD D 0406 EB XCHG 0407 0D DCR C 0408 C2EB03 JNZ DKWRLP 040B AF XRA A 040C 320B05 STA SECINBF 040F 214A05 LXI H,DBUF 0412 220905 SHLD SECPTR ; 0415 118000 RSDMA LXI D,BASE+80H 0418 0E1A MVI C,26 041A C30500 JMP BDOS ; 041D CD1504 WRERR CALL RSDMA 0420 CDB804 CALL ILPRT 0423 2B2B455252 DB '++ERROR WRITING FILE',CR,LF,0 043A C3E202 JMP ABORT ; 043D D5 RECV PUSH D ; IF FASTCLK MOV A,B ADD A MOV B,A ENDIF ; 043E 1150C3 MSEC LXI D,50000 ; IF NOT DCH 0441 DBC0 MWTI IN MODCTLP ENDIF ; IF DCH MWTI IN MODCTL2 ENDIF ; 0443 E602 ANI MODRCVB 0445 FE02 CPI MODRCVR 0447 CA5904 JZ MCHAR 044A 1D DCR E 044B C24104 JNZ MWTI 044E 15 DCR D 044F C24104 JNZ MWTI 0452 05 DCR B 0453 C23E04 JNZ MSEC 0456 D1 POP D 0457 37 STC 0458 C9 RET ; 0459 DBC1 MCHAR IN MODDATP 045B D1 POP D 045C F5 PUSH PSW 045D 81 ADD C 045E 4F MOV C,A 045F F1 POP PSW 0460 B7 ORA A 0461 C9 RET ; 0462 2A0100 INITADR LHLD BASE+1 0465 110300 LXI D,3 0468 19 DAD D 0469 22A504 SHLD VSTAT+1 046C 19 DAD D 046D 22B004 SHLD VKEYIN+1 0470 19 DAD D 0471 229A04 SHLD VTYPE+1 0474 C9 RET ; 0475 = INITMOD EQU $ ; IF INITREQ MVI A,INITC1 OUT MODCTLP NOP ! NOP ! NOP NOP ! NDP MVI A,INITC2 OUT MODCTLP NOP ! NOP ! NOP NOP ! NOP MVI A,INITC3 OUT MODCTLP NOP ! NOP ! NOP NOP ! NOP MVI A,INITC4 OUT MODCTLP NOP ! NOP ! NOP NOP ! NOP ENDIF ; IF PMMI 0475 3E34 MVI A,52 0477 D3C2 OUT BAUDRP 0479 3E7F MVI A,7FH 047B D3C3 OUT MODCTL2 ENDIF ; IF DCH MVI A,16H OUT MODCTL2 ENDIF ; IF PMMI OR DCH 047D 21A00F LXI H,4000 ; 0480 2D OFFDLY DCR L 0481 C28004 JNZ OFFDLY 0484 25 DCR H 0485 C28004 JNZ OFFDLY 0488 3E1D MVI A,ORIGMOD 048A D3C0 OUT MODCTLP ENDIF ; 048C C9 RET ;<--THIS RET MUST BE HERE ; 048D 3E0D CRLF MVI A,CR 048F CD9404 CALL TYPE 0492 3E0A MVI A,LF ; 0494 F5 TYPE PUSH PSW 0495 C5 PUSH B 0496 D5 PUSH D 0497 E5 PUSH H 0498 4F MOV C,A 0499 CD0000 VTYPE CALL $-$ 049C E1 POP H 049D D1 POP D 049E C1 POP B 049F F1 POP PSW 04A0 C9 RET ; 04A1 C5 STAT PUSH B 04A2 D5 PUSH D 04A3 E5 PUSH H 04A4 CD0000 VSTAT CALL $-$ 04A7 E1 POP H 04A8 D1 POP D 04A9 C1 POP B 04AA B7 ORA A 04AB C9 RET ; 04AC C5 KEYIN PUSH B 04AD D5 PUSH D 04AE E5 PUSH H 04AF CD0000 VKEYIN CALL $-$ 04B2 E1 POP H 04B3 D1 POP D 04B4 C1 POP B 04B5 E67F ANI 7FH 04B7 C9 RET ; 04B8 E3 ILPRT XTHL ; 04B9 7E ILPLP MOV A,M 04BA B7 ORA A 04BB CAC504 JZ ILPRET 04BE CD9404 CALL TYPE 04C1 23 INX H 04C2 C3B904 JMP ILPLP ; 04C5 E3 ILPRET XTHL 04C6 C9 RET ; 04C7 D1 ERXIT POP D 04C8 0E09 MVI C,9 04CA CD0500 CALL BDOS ; 04CD CDB804 MXIT CALL ILPRT 04D0 0D0A444F4E DB CR,LF,'DON"T FORGET TO DISCONNECT MODEM' 04F2 0D0A00 DB CR,LF,0 ; 04F5 2A4805 EXIT LHLD STACK 04F8 F9 SPHL 04F9 C9 RET ; 04FA 0680 MOVE128 MVI B,128 ; 04FC 7E MOVE MOV A,M 04FD 12 STAX D 04FE 23 INX H 04FF 13 INX D 0500 05 DCR B 0501 C2FC04 JNZ MOVE 0504 C9 RET ; 0505 00 RCVSNO DB 0 0506 00 SECTNO DB 0 0507 00 ERRCT DB 0 0508 00 EOFLG DB 0 0509 4A05 SECPTR DW DBUF 050B 00 SECINBF DB 0 050C DS 60 0548 STACK DS 2 054A = DBUF EQU $ ; 054A END