home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / MODEMS / ZMODEM / ZMO-SN05.Z80 < prev    next >
Text File  |  2000-06-30  |  15KB  |  583 lines

  1. ;  PROGRAM: ZMO-SN05.Z80
  2. ;  AUTHOR:  Richard Kopplin
  3. ;  VERSION: 1.5
  4. ;  DATE:  25 Oct, 1988
  5. ;-----------------------------------------------------------------------
  6. ;    This overlay is set up for a Sanyo MBC-1200/1250
  7. ;        UART 8251    NO baud rate generator
  8. ;-----------------------------------------------------------------------
  9. ; 89/04/12 - Modified to ZMP v1.5        - George Conover
  10. ; 89/03/15 - Removed the beginning remarks to make the file
  11. ;            smaller. If you need the remarks there are in the
  12. ;            file ZMP-BLNK.Z80             - George Conover
  13. ; 89/03/14 - Modified to ZMP v1.4        - George Conover
  14. ; 88/10/10 - Modified to ZMP v1.3        - Ron Murray
  15. ; 88/09/15 - Modified to ZMP v1.2        - Ron Murray
  16. ; 88/09/14 - First version of this file        - Richard Kopplin
  17. ;
  18. ;    Written by - Richard Kopplin, 805-486-6847, Port Hueneme, CA
  19. ;-----------------------------------------------------------------------
  20. ; NOTES: On use of ZMP with the Sanyo MBC-1200/1250
  21. ;    Although the Sanyo has no baud rate generator the program will select
  22. ; between 300 or 1200 baud. To get 300 you must select 300 any other baud 
  23. ; rate will program the UART for 1200. Selection of 1 or 2 stop bits, Odd
  24. ; Even or No parity and 7 or 8 bit selection is also enabled. This feature
  25. ; can be disabled by deleting the call to "init2" in the "init" routine.
  26. ;    The "userin:" routine redefines the Sanyo function keys, "userout:"
  27. ; restores the orginal Sanyo function keys when exiting ZMP. The definition
  28. ; table for the function keys while in ZMP is located in the "newkeys:" area
  29. ; just below "userout:".
  30. ;    I could not get the screen print funciton to work with my printer.
  31. ; although if you had the "right" printer I'am sure it would work. What I did
  32. ; add here is a one line message with the overlay date and version.
  33. ;
  34. ;============================================================================
  35. ; User-set variables:
  36.  
  37. CLKSPD    EQU    4    ; Processor clock speed in MHz
  38.  
  39. ;Set the following two equates to the drive and user area which will contain
  40. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  41. ;   (null) to locate them on the drive from which ZMP was invoked.
  42.  
  43. OVERDRIVE    EQU    'A'    ; Drive to find overlay files on ('A'-'P')
  44. OVERUSER    EQU    0    ; User area to find files
  45.  
  46. ;------------------------------------------------------------------------------
  47.  
  48. MDDATA  EQU    0ECH    ; Modem data port for the Sanyo MBC-1200/1250
  49. MDCTRL  EQU    0EDH    ; the UART is an 8251, no baud rate control.
  50.  
  51. ;============================================================================
  52. ; NOT user-set variables
  53.  
  54. USERDEF    EQU    0145H    ; Origin of this overlay.  This address may
  55.             ; change with subsequent revisions.
  56. MSPEED    EQU    05CH        ; location of current baud rate. 
  57. OVSIZE    EQU    0400H        ; max size of this overlay
  58.  
  59. ESC    EQU    1BH
  60. CR    EQU    0DH
  61. LF    EQU    0AH
  62. BDOS    EQU    5
  63.  
  64.     .Z80            ; use z80 code
  65.     ASEG            ; absolute
  66.     ORG    USERDEF
  67.  
  68. CODEBGN    EQU    $
  69.  
  70. ;Jump table for the overlay: do NOT change this
  71. JUMPTAB:
  72.     JP    SCRNPR        ; screen print
  73.     JP    MRD        ; modem read with timeout
  74.     JP    MCHIN        ; get a character from modem
  75.     JP    MCHOUT        ; send a character to the modem
  76.     JP    MORDY        ; test for tx buffer empty
  77.     JP    MIRDY        ; test for character received
  78.     JP    SNDBRK        ; send break
  79.     JP    CURSADD        ; cursor addressing
  80.     JP    CLS        ; clear screen
  81.     JP    INVON        ; inverse video on
  82.     JP    INVOFF        ; inverse video off
  83.     JP    HIDE        ; hide cursor
  84.     JP    SHOW        ; show cursor
  85.     JP    SAVECU        ; save cursor position
  86.     JP    RESCU        ; restore cursor position
  87.     JP    MINT        ; service modem interrupt
  88.     JP    INVEC        ; initialise interrupt vectors
  89.     JP    DINVEC        ; de-initialise interrupt vectors
  90.     JP    MDMERR        ; test uart flags for error
  91.     JP    DTRON        ; turn DTR on
  92.     JP    DTROFF        ; turn DTR OFF
  93.     JP    INIT        ; initialise uart
  94.     JP    WAIT        ; wait seconds
  95.     JP    MSWAIT        ; wait milliseconds
  96.     JP    USERIN        ; user-defined entry routine
  97.     JP    USEROUT        ; user-defined exit routine
  98.     JP    GETVARS        ; get system variables
  99.       JP    SETPORT        ; Set port (0 or 1)
  100. ;
  101. ; Spare jumps for compatibility with future versions
  102. ;
  103.     JP    SPARE        ; spare for later use
  104.     JP    SPARE        ; spare for later use
  105.     JP    SPARE        ; spare for later use
  106.     JP    SPARE        ; spare for later use
  107.     JP    SPARE        ; spare for later use
  108.     JP    SPARE        ; spare for later use
  109.  
  110. ;============================================================================
  111. ; Main code starts here
  112. ;
  113. ;Screen print function
  114. SCRNPR:
  115.     CALL    PRINT
  116.     DB    'Zmodem v1.5 overlay for Sanyo MBC-1200/1250 '
  117.     DB    ' v0.1  dated  25 October 1988',CR,LF
  118.     DB    'Print screen function is not supported.',CR,LF,0
  119. SPARE:
  120.     RET        ; This ret used by both scrnpr and spare
  121.  
  122. ; User-defined entry routine: 
  123. ; Install a new function key table for the Sanyo MBC-1200/1250
  124. USERIN:
  125.     LD    HL,(0001H)    ; Load address of warm boot
  126.     LD    BC,0030H    ; add offset for keytable
  127.     ADD    HL,BC
  128.     LD    BC,NEWKEYS    ; load address of new key table
  129.     LD    E,(HL)        ; store normal keytable in de
  130.     LD    (HL),C
  131.     INC    HL
  132.     LD    D,(HL)
  133.     LD    (HL),B
  134.     LD    (KEYADD),DE    ; store address for normal keytable
  135.     RET
  136.  
  137. ; User-defined exit routine: Reinstall normal function key table
  138. USEROUT:
  139.     LD    HL,(0001H)    ; Load address of warm boot
  140.     LD    BC,0030H    ; add offset for keytable address
  141.     ADD    HL,BC
  142.     LD    BC,(KEYADD)    ; load address of normal keytable
  143.     LD    (HL),C        ; and restore it in BIOS
  144.     INC    HL
  145.     LD    (HL),B    
  146.     RET
  147.  
  148. KEYADD: DW 0            ; Temp storage of normal keytable address
  149. NEWKEYS:
  150.     DB 08H,0,0,0,0,0,0,0    ; Brown "INS" key
  151.     DB CR, 0,0,0,0,0,0,0    ; Brown "ENTER" key
  152.     DB ESC,'1',0,0,0,0,0,0    ; PF1 - Macro key 1
  153.     DB ESC,'2',0,0,0,0,0,0    ; PF2 - Macro key 2
  154.     DB ESC,'3',0,0,0,0,0,0    ; PF3 - Macro key 3
  155.     DB ESC,'4',0,0,0,0,0,0    ; PF4 - Macro key 4
  156.     DB ESC,'5',0,0,0,0,0,0    ; PF5 - Macro key 5
  157.     DB ESC,'6',0,0,0,0,0,0    ; PF6 - Macro key 6
  158.     DB ESC,'7',0,0,0,0,0,0    ; PF7 - Macro key 7
  159.     DB ESC,'8',0,0,0,0,0,0    ; PF8 - Macro key 8
  160.     DB ESC,'9',0,0,0,0,0,0    ; PF9 - Macro key 9
  161.     DB ESC,'0',0,0,0,0,0,0    ; PF10 - Macro key 0
  162.     DB ESC,'K',0,0,0,0,0,0    ; PF11 - Display keyboard macros
  163.     DB ESC,'F',0,0,0,0,0,0    ; PF12 - Disk Operation
  164.     DB ESC,'D',0,0,0,0,0,0    ; PF13 - Disk Directory
  165.     DB ESC,'H',0,0,0,0,0,0    ; PF14 - HELP
  166.     DB ESC,'Q',0,0,0,0,0,0    ; PF15 - Quit/Exit program
  167.     DB ESC,'Z',0,0,0,0,0,0    ; Left arrow - Clear Screen 
  168.     DB ESC,'M',0,0,0,0,0,0    ; Right arrow - Toggle capture mode 
  169.     DB 'Q'-40H,0,0,0,0,0,0,0    ; Up arrow  -   ctrl Q
  170.     DB 'S'-40H,0,0,0,0,0,0,0    ; Down arrow  -   ctrl S
  171.     DB 'C'-40H,0,0,0,0,0,0,0    ; Left/up arrow -   ctrl C
  172.  
  173. ;============================================================================
  174. ;    Modem control area:   UART 8251  No baud rate generator
  175. ;  -------------------------------------------------
  176. ;  | DSR | syn |  FE |  OE |  PE | TxE | RxR | TxR |  Stauts format
  177. ;  -------------------------------------------------
  178. ;  | EH  | IR  | RTS |  ER | SBRK| RxE | DTR | TxE |  Command format
  179. ;  -------------------------------------------------
  180. ;  | S2  | S1  |  EP | PEN |  L2 |  L1 |  B2 |  B1 |  Commands
  181. ;  -------------------------------------------------
  182. ;   
  183. ;  S2 S1 Bits   EP      PEN         L2 L1 Bits   B2 B1 Rate
  184. ;   0  0  ?     0 Odd    0 Disable    0  0  5      0  0   ?
  185. ;   0  1  1     1 Even  1 Enable     0  1  6      0  1  X1
  186. ;   1  0  1.5                        1  0  7      1  0  X16
  187. ;   1  1  2                          1  1  8      1  1  X64
  188. ;
  189. ;Get a character from the modem: return in HL
  190. MCHIN:                ; <== Insert your own code here
  191.     IN    A,(MDDATA)
  192.                 ; <== End of your own code
  193.     LD    L,A        ; put in HL
  194.     LD    H,0
  195.     OR    A        ; set/clear Z
  196.     RET
  197.  
  198. ;Send a character to the modem
  199. MCHOUT:
  200.     LD    HL,2        ; get the character
  201.     ADD    HL,SP
  202.     LD    A,(HL)
  203.                 ; <== Insert your own code here
  204.     OUT    (MDDATA),A
  205.                 ; <== End of your own code
  206.     RET            ; done
  207.  
  208. ;Test for output ready: return TRUE (1) in HL if ok
  209. MORDY:                ; <== Insert your own code here
  210.     LD    HL,0
  211.     IN    A,(MDCTRL)
  212.     BIT    0,A
  213.     JR    Z,MORDY1
  214.     INC    HL
  215.                 ; <== End of your own code
  216. MORDY1: LD    A,L        ; set/clear Z
  217.     OR    A
  218.     RET
  219.  
  220. ;Test for character at modem: return TRUE (1) in HL if so
  221. MIRDY:                ; <== Insert your own code here
  222.     LD    HL,0
  223.     IN    A,(MDCTRL)
  224.     BIT    1,A
  225.     JR    Z,MINDY1
  226.     INC    HL
  227.                 ; <== End of your own code
  228. MINDY1: LD    A,L        ; set/clear Z
  229.     OR    A
  230.     RET
  231.  
  232. ;Send a break to the modem: leave empty if your system can't do it
  233. SNDBRK:
  234.     LD    A,00001000B
  235.     OUT    (MDCTRL),A
  236.     LD    HL,300        ; wait 300 mS
  237.     CALL    WAITHLMS
  238.     LD    A,00110111B
  239.     OUT    (MDCTRL),A
  240.     RET
  241.  
  242. ;Test UART flags for error: return TRUE (1) in HL if error.
  243. MDMERR:                ; <== Insert your own code here
  244.     LD    HL,0
  245.     IN    A,(MDCTRL)
  246.     BIT    4,A
  247.     JR    Z,MDMER1
  248.     LD    A,00110111B    ; if error reset UART
  249.     OUT    (MDCTRL),A
  250.     INC    HL
  251.                 ; <== End of your own code
  252. MDMER1: LD    A,L        ; set/clear Z
  253.     OR    A
  254.     RET
  255.  
  256. ;Turn DTR ON
  257. DTRON:
  258.     LD    A,00110111B
  259.     OUT    (MDCTRL),A
  260.     RET
  261.  
  262. ;Turn DTR OFF
  263. DTROFF:
  264.     LD    A,00110101B
  265.     OUT    (MDCTRL),A
  266.     RET
  267.  
  268. ;Initialise the uart
  269. INIT:
  270.     LD    HL,2        ; get parameters
  271.     ADD    HL,SP
  272.     EX    DE,HL
  273.     CALL    GETPARM        ; in HL and save it in ..
  274.     LD    (BRATE),HL    ; baud rate
  275.     CALL    GETPARM
  276.     LD    (PARITY),HL    ; parity
  277.     CALL    GETPARM
  278.     LD    (DATA),HL    ; data bits (BINARY 7 or 8)
  279.     CALL    GETPARM
  280.     LD    (STOP),HL    ; stop bits (BINARY 1 or 2)
  281.                 ; <== Insert your own code here
  282.     LD    A,5        ; load mspeed with the current (default)
  283.     LD    (MSPEED),A    ; brate value if the new rate is valid
  284.     LD    A,01000010B    ; reset 8251 and leave DTR on
  285.     OUT    (MDCTRL),A
  286.     LD    A,01001110B    ; 1 stop bit, parity disabled, 8 bits, X16
  287.     CALL    INIT2        ; change UART default settings 
  288.     OUT    (MDCTRL),A
  289.     LD    A,00110111B    ; FIX, no reset, RTS on, Error reset,
  290.     OUT    (MDCTRL),A    ; no break, RX enable, DTR on, TX enable
  291.     RET            ; <== End of your own code
  292.  
  293. ; Change default UART settings to those set by ZMP escape commands
  294. INIT2:
  295.     LD    E,A        ; save default settings 01001110b
  296.     LD    A,(BRATE)
  297.     CP    1        ; if 300 baud; set bit 0, X64
  298.     JR    NZ,INIT3
  299.     SET    0,E
  300.     LD    (MSPEED),A    ; change mspeed value for new baud rate
  301. INIT3:
  302.     LD    A,(DATA)
  303.     CP    7        ; if 7 data bits; reset bit 2
  304.     JR    NZ,INIT4
  305.     RES    2,E
  306. INIT4:
  307.     LD    A,(PARITY)
  308.     CP    'O'        ; if Odd parity; set bit 4, reset bit 5
  309.     JR    NZ,INIT5
  310.     SET    4,E
  311.     RES    5,E
  312. INIT5:
  313.     CP    'E'        ; if Even parity; set bits 4 and 5
  314.     JR    NZ,INIT6
  315.     SET    4,E
  316.     SET    5,E
  317. INIT6:
  318.     LD    A,(STOP)
  319.     CP    2        ; if 2 stop bits; set bit 7
  320.     JR    NZ,INIT7
  321.     SET    7,E
  322. INIT7:
  323.     LD    A,E        ; load new mode back in register a
  324.     RET
  325.  
  326. ;--------------------------------------------------------------------------
  327.  
  328. STOP:    DW    1        ; stop bits:  1 or 2
  329. PARITY:    DW    'N'        ; parity:     N, O or E
  330. DATA:    DW    8        ; data bits:  7 or 8
  331. BRATE:    DW    5        ; baud rate:  see below
  332.  
  333. ;--------------------------------------------------------------------------
  334. ; Values of brate for each baud rate allowed
  335. ;
  336. ; brate   baud rate       brate   baud rate       brate   baud rate
  337. ;   0        110            5       1200            9       19200
  338. ;   1        300            6       2400           10       38400
  339. ;   2        450            7       4800           11       57600
  340. ;   3        600            8       9600           12       76800
  341. ;   4        710
  342. ;
  343. ; Set the port. ZMP supplies either 0 or 1 as a parameter.
  344. ;
  345. setport:
  346.     ld    hl,2        ; get port number
  347.     add    hl,sp
  348.     ex    de,hl
  349.     call    getparm        ; in HL (values are 0 and 1)
  350.  
  351.                 ; <== Insert your own code here
  352.  
  353.                 ; <== End of your own code
  354.     ret
  355. ;
  356. ;============================================================================
  357. ;    Video terminal sequences for the Sanyo MBC-1200/1250
  358. ;Cursor addressing: 
  359. CURSADD:
  360.     LD    HL,2        ; get parameters
  361.     ADD    HL,SP
  362.     EX    DE,HL
  363.     CALL    GETPARM        ; in HL
  364.     LD    (ROW),HL    ; row
  365.     CALL    GETPARM
  366.     LD    (COL),HL    ; column
  367.                 ; <== Insert your own code here
  368.                 ; using values in row and col
  369.     CALL    PRINT
  370.     DB    ESC,'=',0    ; Sanyo leadin characters
  371.     LD    A,(ROW)        ; row first
  372.     ADD    A,' '        ; add offset
  373.     CALL    COUT
  374.     LD    A,(COL)        ; same for column
  375.     ADD    A,' '
  376.     CALL    COUT
  377.                 ; <== end of your own code
  378.     RET
  379.  
  380. ROW:    DW    0        ; row
  381. COL:    DW    0        ; column
  382.  
  383. ;Clear screen:
  384. CLS:
  385.     CALL    PRINT
  386.     DB    1AH,0
  387.     RET
  388.  
  389. ;Inverse video on:
  390. INVON:
  391.     CALL    PRINT
  392.     DB    ESC,'t4',0
  393.     RET
  394.  
  395. ;Inverse video off:
  396. INVOFF:
  397.     CALL    PRINT
  398.     DB    ESC,'t0',0
  399.     RET
  400.  
  401. ;Turn off cursor:
  402. HIDE:
  403.     CALL    PRINT
  404.     DB    ESC,'E',0
  405.     RET
  406.  
  407. ;Turn on cursor:
  408. SHOW:
  409.     CALL    PRINT
  410.     DB    ESC,'D',0
  411.     RET
  412.  
  413. ;Save cursor position:
  414. SAVECU:
  415.     RET
  416.  
  417. ;Restore cursor position:
  418. RESCU:
  419.     RET
  420.  
  421. ;****************************************************************************
  422.  
  423. ;Service modem interrupt:
  424. MINT:
  425.     RET            ; Not used by the Sanyo MBC-1200/1250
  426.  
  427. ;Initialise interrupt vectors:
  428. INVEC:
  429.     RET            ; ditto
  430.  
  431. ;De-initialise interrupt vectors:
  432. DINVEC:
  433.     RET            ; ditto
  434.  
  435. ;****************** End of user-defined code ********************************
  436. ;        Do not change anything below here.
  437.  
  438. ;Modem character test for 100 ms
  439. MRD:
  440.     PUSH    BC        ; save bc
  441.     LD    BC,100        ; set limit
  442. MRD1:
  443.     CALL    MIRDY        ; char at modem?
  444.     JR    NZ,MRD2        ; yes, exit
  445.     LD    HL,1        ; else wait 1ms
  446.     CALL    WAITHLMS
  447.     DEC    BC        ; loop till done
  448.     LD    A,B
  449.     OR    C
  450.     JR    NZ,MRD1
  451.     LD    HL,0        ; none there, result=0
  452.     XOR    A
  453. MRD2:
  454.     POP    BC
  455.     RET
  456.  
  457. ; Inline print routine: destroys A and HL
  458. PRINT:
  459.     EX    (SP),HL        ; get address of string
  460. PLOOP:
  461.     LD    A,(HL)        ; get next
  462.     INC    HL        ; bump pointer
  463.     OR    A        ; done if zero
  464.     JR    Z,PDONE
  465.     CALL    COUT        ; else print
  466.     JR    PLOOP        ; and loop
  467. PDONE:
  468.     EX    (SP),HL        ; restore return address
  469.     RET            ; and quit
  470.  
  471. ;Output a character in A to the console
  472. COUT:
  473.     PUSH    BC        ; save regs
  474.     PUSH    DE
  475.     PUSH    HL
  476.     LD    E,A        ; character to E
  477.     LD    C,2
  478.     CALL    BDOS        ; print it
  479.     POP    HL
  480.     POP    DE
  481.     POP    BC
  482.     RET
  483.  
  484. ; Wait(seconds)
  485. WAIT:
  486.     LD    HL,2
  487.     ADD    HL,SP
  488.     EX    DE,HL        ; get delay size
  489.     CALL    GETPARM
  490.                 ; fall thru to..
  491. ; Wait seconds in HL
  492. WAITHLS:
  493.     PUSH    BC        ; save bc
  494.     PUSH    DE        ; de
  495.     PUSH    IX        ; and ix
  496.     LD    IX,0        ; then point ix to 0
  497.                 ; so we don't upset memory-mapped i/o
  498.  
  499. ; Calculate values for loop constants. Need to have two loops to avoid
  500. ;   16-bit overflow with clock speeds above 9 MHz.
  501.  
  502. OUTERVAL    EQU    (CLKSPD / 10) + 1
  503. INNERVAL    EQU    (6667 / OUTERVAL) * CLKSPD
  504.  
  505. WAIT10:
  506.     LD    B,OUTERVAL
  507.  
  508. WAIT11:
  509.     LD    DE,INNERVAL
  510.  
  511. WAIT12:
  512.     BIT    0,(IX)        ; time-wasters
  513.     BIT    0,(IX)
  514.     BIT    0,(IX)        ; 20 T-states each
  515.     BIT    0,(IX)
  516.     BIT    0,(IX)
  517.     BIT    0,(IX)
  518.     DEC    DE
  519.     LD    A,E
  520.     LD    A,D
  521.     OR    E
  522.     JR    NZ,WAIT12    ; 150 T-states per inner loop
  523.     DJNZ    WAIT11        ; decrement outer loop
  524.     DEC    HL        ; ok, decrement count in hl
  525.     LD    A,H
  526.     OR    L
  527.     JR    NZ,WAIT10
  528.     POP    IX        ; done -- restore ix
  529.     POP    DE        ; de
  530.     POP    BC        ; and bc
  531.     RET
  532.  
  533. ; Wait milliseconds
  534. MSWAIT:
  535.     LD    HL,2
  536.     ADD    HL,SP
  537.     EX    DE,HL        ; get delay size
  538.     CALL    GETPARM
  539.                 ; fall thru to..
  540. ; Wait milliseconds in HL
  541. WAITHLMS:
  542.     PUSH    DE
  543. W1MS0:
  544.     LD    DE,39 * CLKSPD
  545. W1MS1:
  546.     DEC    DE
  547.     LD    A,D
  548.     OR    E
  549.     JR    NZ,W1MS1
  550.     DEC    HL
  551.     LD    A,H
  552.     OR    L
  553.     JR    NZ,W1MS0
  554.     POP    DE
  555.     RET
  556.  
  557. ; Get next parameter from (de) into hl
  558. GETPARM:
  559.     EX    DE,HL        ; get address into hl
  560.     LD    E,(HL)        ; get lo
  561.     INC    HL
  562.     LD    D,(HL)        ; then hi
  563.     INC    HL        ; bump for next
  564.     EX    DE,HL        ; result in hl, address still in de
  565.     RET
  566. ;
  567. ;Get address of user-defined variables
  568. ;
  569. GETVARS:
  570.     LD    HL,USERVARS
  571.     RET
  572. USERVARS:
  573.     DW    OVERDRIVE    ; .OVR etc. drive/user
  574.     DW    OVERUSER
  575.  
  576. USED:    EQU    ($ - USERDEF)
  577. UNUSED: EQU    OVSIZE - USED
  578.      IF    ($ - USERDEF) GT OVSIZE
  579. TOOBIG:    JP    ERRVAL        ; Overlay too large!
  580.      ENDIF
  581.  
  582.     END
  583.