From 49a5f06233e92c28feaf0b42d2b0521b1ebf5bd9 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 10 Dec 2015 19:31:52 +0100 Subject: [PATCH] Inquire AVR-CP/M firmware version --- cpxac.asm | 499 ++++++++++++++++++++++++++++++++++------------------- cpxtyp.asm | 30 ++-- 2 files changed, 337 insertions(+), 192 deletions(-) diff --git a/cpxac.asm b/cpxac.asm index 611f22a..f8763c8 100644 --- a/cpxac.asm +++ b/cpxac.asm @@ -1,6 +1,10 @@ IF NOT lasm .printx * CPXAC.ASM * ENDIF ;NOT lasm +IF lasm +.printx Error: Z80 macro assembler (i.e. M80) required + END +ENDIF ;lasm ; KERMIT - (Celtic for "FREE") ; ; This is the CP/M-80 implementation of the Columbia University @@ -24,7 +28,7 @@ ENDIF ;NOT lasm ; ; Keep module name, edit number, and last revision date in memory. ; -family: db 'CPXCP.ASM (1) 3-DEC-2015$' ; First entry for V4.11 +family: db 'CPXCA.ASM (1) 3-DEC-2015$' ; First entry for V4.11 ; ; Assembly time message to let me know I'm building the right version. @@ -37,6 +41,8 @@ family: db 'CPXCP.ASM (1) 3-DEC-2015$' ; First entry for V4.11 SC16IS740_ADDR equ 90H ;SC16IS740 I2C address. (8bit, A0=VDD, A1=VDD) OUTSIZE equ 64 +VERSION_MIN equ 0304H ;Minimum AVR-CP/M firmware version required + ; Virtual I2C Interface VI2C_STAT equ 05h @@ -89,15 +95,306 @@ I2C_UART_XOFF1 equ I2C_UART_PORT+06H ;R/W Xoff1 word I2C_UART_XOFF2 equ I2C_UART_PORT+07H ;R/W Xoff2 word - z80 set TRUE ;This one emulates an Z80. - .z80 +;---------------------------------------------------------------------- +; Macros +;---------------------------------------------------------------------- + +; make a message table +; usage: +; label: mkmsgtab + +mkm_tab macro x +n?msg defl 0 + irp y, +n?msg defl n?msg+1 + endm + db n?msg + irp y, + db '&y','$' + endm + endm + +; make a message table +; usage: +; label: mkmsgtab + +mkms_tab macro x +n?msg defl 0 + irp y, +n?msg defl n?msg+1 + endm + db n?msg + irp y, + ifnb + db y,'$' + else + db '$' + endif + endm + endm + +;---------------------------------------------------------------------- +; Messages +;---------------------------------------------------------------------- + +umsg_tab: + ; 0 1 2 3 4 5 + mkms_tab <'UART',,' not', ' detected',', crystal frequency: ','!'> + +fmsg_tab: + mkm_tab +fdim_msg: + db ' MHz.',cr,lf,'$' +fw_msg: + db 'AVR firmware to old, at least version 3.4 neded.','$' +exit_msg: + db cr,lf,'Exiting!',cr,lf,'$' + +;---------------------------------------------------------------------- +; Utilities +;---------------------------------------------------------------------- + +; Print message from table +; +; hl: message table address +; first byte is number of table entries +; a: number of message to print (0 based, index in table) +; +; If index is out of range, print message #0 + +pdecoded: + push bc + push de + push hl + ld bc,0 + cp (hl) ; number of messages in table + jr c,pdc_1 + ld a,c +pdc_1: + inc hl + ld e,a + ld a,'$' + inc e + jr pdc_2 +pdc_nxt_str: + cpir +pdc_2: + dec e + jr nz,pdc_nxt_str + ex de,hl + call prtstr + pop hl + pop de + pop bc + ret + +;---------------------------------------------------------------------- +; output bytes to ports +; +; hl: tables of port,value pairs: +; db n ;number of pairs +; db port1,val1, port2,val2,... portn,valn +; ... +; db 0 ; Terminate table + +ioinil: + push bc + ld b,(hl) ;count + inc hl +io1_lp: + ld c,(hl) ;port address + inc hl + outi + jr nz,io1_lp + pop bc + ret + +;---------------------------------------------------------------------- + +vi2c_setup_chk: + ld hl,chkbuf +vi2c_setup: + out (VI2C_BLEN),a + ld a,h + out (VI2C_ADR+1),a + ld a,l + out (VI2C_ADR+0),a + ret + +;---------------------------------------------------------------------- + +prspeedmsg: + ld hl,fmsg_tab + call pdecoded + ld de,fdim_msg + call prtstr + ret + +;---------------------------------------------------------------------- +; +;---------------------------------------------------------------------- + +fw_check: + ld bc,000CH ; + out (c),b ;write 0 to version port + in a,(c) + cp 1 ;result should be 0 + ret nc ;exit (a != 0) if it wasn't + inc b + out (c),b + in h,(c) ;get MAJOR + inc b + out (c),b + in l,(c) ;get MINOR + ld de,VERSION_MIN + xor a ;clear carry + sbc hl,de + sbc a,a ;z if hl >= VERSION_MIN + ret + +;---------------------------------------------------------------------- + +uart_check: + ld a,3 ;2 byte + SLA + call vi2c_setup_chk + ld a,2 ;write cmd + out (VI2C_CTRL),a +uc_0: + in a,(VI2C_CTRL) ;do: get i2c result + bit 7,a ; + jr nz,uc_0 ;while busy + cp 0FH + jr nz,uc_err ;error in transaction + in a,(VI2C_BLEN) + cp 3 + jr nz,uc_err + + inc hl + inc hl + in a,(I2C_UART_SPR) + cp (hl) + jr nz,uc_err + ld (hl),42H + ld a,2 + out (VI2C_CTRL),a + in a,(I2C_UART_SPR) + cp (hl) + jr nz,uc_err + xor a + jr uc_1 +uc_err: + ld a,1 +uc_1: + ld c,a + ld hl,umsg_tab + xor a + call pdecoded + ld a,1 + add a,c + call pdecoded + ld a,3 + call pdecoded + ld a,4 + add a,c + call pdecoded + ld a,c + or a + ret + +;---------------------------------------------------------------------- + +chkbuf: + db SC16IS740_ADDR + db (I2C_UART_SPR - I2C_UART_PORT) shl 3 ;address of scratch pad register + db 5AH + +;---------------------------------------------------------------------- + +speedtest: + ld hl,spt_tab ;init UART in loop back mode + call ioinil ; and fill tx fifo with 60 chars + + in a,(I2C_UART_MSR) ;Clear Modem Status Register + in a,(I2C_UART_LSR) ;Clear Line Status Register + in a,(I2C_UART_RHR) ;Clear Receiver Buffers + in a,(I2C_UART_RHR) + + ld a,2 ;start write transaction + out (VI2C_CTRL),a + + ; get time stamp + in a,(41H) ;lsb ms + ld e,a + in a,(42H) ;msb ms + ld d,a + in a,(43H) ;lsb seconds + ld c,a + +spt_1: + in a,(I2C_UART_RXLVL) ;wait till all 60 char in rx fifo + cp 60 + jr nz,spt_1 + + ; get 2nd time stamp + in a,(41H) ;lsb ms + ld l,a + in a,(42H) ;msb ms + ld h,a + in a,(43H) ;lsb seconds + sub c ;seconds diff + jr z,spt_3 + ld bc,1000 +spt_2: ;convert s to ms + add hl,bc + dec a + jr nz,spt_2 +spt_3: + sbc hl,de ;hl = elapsed time (ms) for 60 chars + ld d,h + ld e,l + inc hl + srl h + rr l + ld bc,500 + add hl,bc + + xor a ;clear carry +spt_4: + inc a + sbc hl,de + jr nc,spt_4 + dec a + ret + +spt_tab: + db (spt_tab_end - ($+1))/2 + db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit + db I2C_UART_DLL, low 96 ;1200 bit/s at 1.832 MHz + db I2C_UART_DLH, high 96 ;Out to the MSB divisor port + db I2C_UART_LCR, 03H ;Disable Divisor Access Latch + db I2C_UART_FCR, 07H ;Clear and enable fifos + db I2C_UART_MCR, 10H ;Enable loopback + db I2C_UART_IER, 0 ;Set no interrupts + db VI2C_ADR+0, low outbuf + db VI2C_ADR+1, high outbuf + db VI2C_BLEN, 60+2 +spt_tab_end: + +;---------------------------------------------------------------------- +; +;---------------------------------------------------------------------- sysxin: ; continuation of system initialisation from sysinit + call fw_check + jr nz,si_exit_f + call uart_check + jr nz,si_exit call speedtest + ld (clk_div),a call prspeedmsg ld hl,6 ;set default baud rate @@ -109,49 +406,19 @@ sysxin: ; continuation of system initialisation from sysinit out (I2C_UART_MCR),a ret -; ld a,07H ;Enable and clear fifos -; out (I2C_UART_FCR),a ; -; ld a,03H ;8N1 -; out (I2C_UART_LCR),a ; - -prspeedmsg: - push af - ld de,freqmsg +si_exit_f: + ld de,fw_msg call prtstr - pop af - cp 13+1 - jr c,$+3 - xor a - ld e,a - ld d,0 - ld hl,fm_tab - add hl,de - add hl,de - ld e,(hl) - inc hl - ld d,(hl) - call prtstr - ld de,fdimmsg +si_exit: + ld de,exit_msg call prtstr - ret - -mkftab macro x - irp y, -fm&y: - db '&y','$' - endm -fm_tab: - irp y, - dw fm&y - endm - endm + jp 0 -freqmsg: - db 'UART crystal frequency: ','$' - mkftab -fdimmsg: - db ' MHz.',cr,lf,'$' +; ld a,07H ;Enable and clear fifos +; out (I2C_UART_FCR),a ; +; ld a,03H ;8N1 +; out (I2C_UART_LCR),a ; ; @@ -366,7 +633,7 @@ spdtbl: db 15 ; Number of entries db 5,'38400$' dw 3 db 3,'450$' - dw 288 + dw 256 db 4,'4800$' dw 24 db 5,'57600$' @@ -386,98 +653,6 @@ sphtbl: db cr,lf,' 110 300 600 2400 9600 28800 57600' db cr,lf,' 75 150 450 1200 4800 19200 38400 115200$' -speedtest: - ld hl,spt_tab - call ioinil - - in a,(I2C_UART_MSR) ;Clear Modem Status Register - in a,(I2C_UART_LSR) ;Clear Line Status Register - in a,(I2C_UART_RHR) ;Clear Receiver Buffers - in a,(I2C_UART_RHR) - - ld a,2 ;start write transaction - out (VI2C_CTRL),a - - ; get time stamp - in a,(41H) ;lsb ms - ld e,a - in a,(42H) ;msb ms - ld d,a - in a,(43H) ;lsb seconds - ld c,a - -spt_1: - in a,(I2C_UART_RXLVL) - cp 60 - jr nz,spt_1 - - ; get 2nd time stamp - in a,(41H) ;lsb ms - ld l,a - in a,(42H) ;msb ms - ld h,a - in a,(43H) ;lsb seconds - sub c - jr z,spt_3 - ld bc,1000 -spt_2: - add hl,bc - dec a - jr nz,spt_2 -spt_3: - sbc hl,de - ld d,h - ld e,l - inc hl - srl h - rr l - ld bc,500 - add hl,bc - - xor a ;clear carry -spt_4: - inc a - sbc hl,de - jr nc,spt_4 - dec a - ld (clk_div),a - ret - -spt_tab: - db (spt_tab_end - ($+1))/2 - db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit - db I2C_UART_DLL, low 96 ;1200 bit/s at 1.832 MHz - db I2C_UART_DLH, high 96 ;Out to the MSB divisor port - db I2C_UART_LCR, 03H ;Disable Divisor Access Latch - db I2C_UART_FCR, 07H ;Clear and enable fifos - db I2C_UART_MCR, 10H ;Enable loopback - db I2C_UART_IER, 0 ;Set no interrupts - db VI2C_ADR+0, low outbuf - db VI2C_ADR+1, high outbuf - db VI2C_BLEN, 60+2 -spt_tab_end: - -;---------------------------------------------------------------------- -; output bytes to ports -; -; hl: tables of port,value pairs: -; db n ;number of pairs -; db port1,val1, port2,val2,... portn,valn -; ... -; db 0 ; Terminate table - -ioinil: - push bc - ld b,(hl) ;count - inc hl -io1_lp: - ld c,(hl) ;port address - inc hl - outi - jr nz,io1_lp - pop bc - ret - ; ; This is the system-dependent SET PORT command. ; HL contains the argument from the command table. @@ -501,11 +676,7 @@ selmdm: ret selcon: -IF 1 jr omflush -ELSE - ret -ENDIF ; ; Get character from console, or return zero. @@ -534,15 +705,6 @@ outcon: ; returns nonskip; bc, de, hl preserved. ; outmdm: -IF 0 - in a,(I2C_UART_LSR) ;Get the output done flag. - and TXRDY ;Is it set? - jr z,outmdm ;If not, loop until it is. - ld a,e - out (I2C_UART_THR),a ;Output it. -ENDIF -IF 1 - push hl ld hl,(outptr) ld (hl),e ;return buffered char @@ -607,35 +769,21 @@ omfex: pop bc pop hl ret -ENDIF + ; ; get character from modem; return zero if none available. ; for IOBYT systems, the modem port has already been selected. ; destroys bc, de, hl. ; inpmdm: -if 0 - in a,(I2C_UART_LSR) ;Get the port status into A. - and RXRDY ;See if the input ready bit is on. - ret z ;If not then return. - - in a,(I2C_UART_MCR) ;debug - xor RTS - out (I2C_UART_MCR),a - - in a,(I2C_UART_RHR);If so, get the char. - ret -endif - -if 1 - ld a,(inpcnt) + ld a,(inpcnt) ;any buffered chars? dec a - jp m,imdrdi2c ;buffer empty - ld (inpcnt),a + jp m,imdrdi2c ;no, buffer empty + ld (inpcnt),a ;save updated buffer counter ld hl,(inpptr) - ld a,(hl) ;return buffered char + ld a,(hl) ;return buffered char inc hl - ld (inpptr),hl + ld (inpptr),hl ;save buffer pointer ret imdrdi2c: @@ -645,16 +793,12 @@ imdrdi2c: ; prepare fifo read inc a ;+ slave address - ld (VI2C_BLEN),a ld hl,inbuf - ld a,h - out (VI2C_ADR+1),a - ld a,l - out (VI2C_ADR+0),a + call vi2c_setup inc hl ld (hl),0 ;select subaddr 0 (RHR) for next read ld a,3 ;write 1 byte (subaddr.), then read fifo - ld (VI2C_CTRL),a + out (VI2C_CTRL),a in a,(VI2C_CTRL) ;get i2c result xor 01h and 11h ;transfer completed? @@ -666,16 +810,14 @@ imdrdi2c: ld (inpcnt),a ;save new buffer count ld a,(hl) inc hl - ld (inpptr),hl + ld (inpptr),hl ;save buffer pointer ret imrdex: xor a ret -endif .8080 - ; ; flsmdm - flush comm line. ; Modem is selected. @@ -734,10 +876,12 @@ clrlin: lxi d,eralin clrtop: lxi d,erascr jmp prtstr +;---------------------------------------------------------------------- sysver: db 'AVR-CP/M' db '$' +;---------------------------------------------------------------------- clk_div: db 1 ;default div @@ -756,6 +900,7 @@ outbuf: db 0 ;RHR subaddress ds OUTSIZE +;---------------------------------------------------------------------- IF lasm LINK CPXVDU.ASM ; get terminal defs etc diff --git a/cpxtyp.asm b/cpxtyp.asm index 1acf241..bc75323 100644 --- a/cpxtyp.asm +++ b/cpxtyp.asm @@ -68,16 +68,16 @@ ; edit of 10 Apr 87 by C W Rose ; Amended code for pci2651 to handle Telecom Merlin M2215. ; (8085 at 5 MHz, 2651 USART, port TTY1:, Ampro 230 terminal equivalent). -; +; ; edit of 13 Jul 1987 by C W Rose ; Added Micromint SB180 with 6/9 MHz. option. ; -; edit 22, 15th July, 1987 by OBSchou for David Moore. +; edit 22, 15th July, 1987 by OBSchou for David Moore. ; David submitted a paper copy of Kermit 4.05 overlay for a Teletek ; system: I have (hopefully) correctly appended his code. He also ; send in the code for ADM 22 terminals. ; -; edit 21, 14 July, 1986 by OBSchou for John Shearwood of Birmingham +; edit 21, 14 July, 1986 by OBSchou for John Shearwood of Birmingham ; University. His edits: ; edit of Apr 7th, 1987 by JA Shearwood. Added entry for Cifer Aux port ; edit of Mar 24 1987 by JA Shearwood, Birmingham. Added code for Cifer @@ -98,7 +98,7 @@ ; [Note: Martins CPXFRK is another version of CPXSWT.ASM] ; ; -; edit 20, 21 May 1987 by OBSchou for Colin Burns of the Institute +; edit 20, 21 May 1987 by OBSchou for Colin Burns of the Institute ; of Neurological Sciences, Glasgow. Added flag for Hazeltine 1500 ; VDU (h1500) ; @@ -108,7 +108,7 @@ ; Manchester University. NCR code is similar to the PCI2651 code, so ; NCRDMV chains to CPXTOR.ASM. CPC cahins to the modified CPXPCW file ; as submitted by Chris. *** NOTE *** All Amstrad versions require -; CP/M 3, so the 664 version must both have the system upgraded to +; CP/M 3, so the 664 version must both have the system upgraded to ; CP/M 3 and have an aditional RAM pack. All Amstrad systems require ; a serial interface. ; @@ -116,15 +116,15 @@ ; * * * Here Begineth kermit-80 Version 4.09 * * * ; ; Biggest change is the overlay address has been moved (again) to 6000h -; and the files have all been diced into families. M80 (almost) back +; and the files have all been diced into families. M80 (almost) back ; in, though I have found some bugs. Will worry about those later. -; CPXSYS.ASM (CP4SYS.ASM in V4.05) now is a family file as well. +; CPXSYS.ASM (CP4SYS.ASM in V4.05) now is a family file as well. ; ; Comments and all that would be much appreciated. ; ; Bertil Schou, ; The Computer Centre, -; Loughborough University of Technology, +; Loughborough University of Technology, ; Loughborough ; Leicestershire, LE11 3TU ; Great Britain @@ -140,14 +140,14 @@ ; file being assembled. I hope. ; ; edit 16 Dec 1st, 1986 by OBSchou. Added entry for Amstrad PCW range (PCW) -; Code in Family file CPXPCW.ASM, submitted by Ian Young of Lattice +; Code in Family file CPXPCW.ASM, submitted by Ian Young of Lattice ; Logic Systems. ; ; Edit 15 June 20 1986. Had to chand org address to 5000h to give room for ; multi-fcb space for DIR command and other additions in the system ; indepentent part. This starts Kermit-80 version 4.08... ; -; Edit 14: March 20, 1986 by OBSchou Loughborough University for +; Edit 14: March 20, 1986 by OBSchou Loughborough University for ; B Robertson, Aberdeen Univ. Computing Centre. ; Add support for APPLE II with serial cards based on the 6850 ACIA. ; Mod 380Z support to allow both MDS (5 1/4" discs) and FDS (8" discs) @@ -160,9 +160,9 @@ ; edit 12 5 Febuary, 1986 by OBSchou ; merged in conditionals for Epson PX8 (px8). Code from Tony Addyman ; Salford University, England. -; Added code from other contibutors for Basic Northstar (basicns), +; Added code from other contibutors for Basic Northstar (basicns), ; Access-Matrix (access), US Micro Sales s1008 (s1008), -; Micro Mate (mmate), A.C.E. Discovery (disc). +; Micro Mate (mmate), A.C.E. Discovery (disc). ; These I cannot test: please send comments back if these are buggy. ; ; edit 11 29 January 1985 by OBSchou @ multics.lut.ac.uk @@ -362,7 +362,7 @@ hp125 EQU FALSE ;[MF]HP-125 Business Assistant, 8-bit data ; thru Data Comm 2 (requires 8th-bit quoting ; for binary transfers on Data Comm 2) ; set VT52 TRUE -mbee EQU FALSE ; Microbee Systems - Microbee +mbee EQU FALSE ; Microbee Systems - Microbee avrcpm EQU TRUE ;AVR-CP/M (terminal required) @@ -512,7 +512,7 @@ ENDIF;sb9 IF hp125 OR telcon cpuspd SET 40 ;[MF]HP125 or TELCON -ENDIF;hp125 OR telcon +ENDIF;hp125 OR telcon IF mbee cpuspd SET 33 ; Microbee has 3.375MHz Z80 @@ -523,7 +523,7 @@ IF FALSE ; assume all systems are not z80 based ;z80 SET FALSE ENDIF ;FALSE -; Now, lets see what family we are assembling for. Reset all +; Now, lets see what family we are assembling for. Reset all ; family file to FALSE torfam SET FALSE ; not Torch family file -- 2.39.2