;------------------------------------------------------------------------------ ; Z7.Z80 - Monitor seriale per newTSP ; By Claudio Fin 1990 - Versione aggiornata 2013/2014 ;------------------------------------------------------------------------------ ; Comunicazione: 9600, N, 8, 2 ; Utilizzo bit porta I/O interna (indirizzo 128): ; Input bit 7: rx seriale (1=riposo) ; Input bit 6: pulsante ESC (0=premuto) ; Input bit 5: ricezione i2c SDA ; Input bit 4: ricezione i2c SCL ; Output bit 7: tx seriale (1=riposo) ; Output bit 6: LED (1=acceso) ; Output bit 5: trasmissione i2c (1=riposo) ; Output bit 4: clock i2c (1=riposo) ;------------------------------------------------------------------------------ io_port .equ 128 ; Indirizzo porta I/O interna ram .equ 32768 ; Indirizzo inizio RAM ramtop .equ 65535 ; Indirizzo fine RAM vars .equ ramtop - 4 ; Indirizzo variabili di sistema out_val .equ vars + 4 ; Indirizzo valore comune di uscita .define sda_bit 5 .define scl_bit 4 .define rx_bit 7 .define tx_bit 7 .define led_bit 6 .define puls_bit 6 .org 0 ;------------------------------------------------------------------------------ ; Salti alla pagina 0 della RAM per eventuale uso RST e interrupt ; Le chiamate RST 08H e RST 10H sono dedicate alle subroutine di ; ricezione e trasmissione seriale software usabili anche da applicativo. ;------------------------------------------------------------------------------ JP test ; RST 00H - reset .text "....." JP rx ; RST 08H - ricezione seriale .text "....." JP tx ; RST 10H - trasmissione seriale .text "....." JP ram + 24 ; RST 18H .text "....." JP ram + 32 ; RST 20H .text "....." JP ram + 40 ; RST 28H .text "....." JP ram + 48 ; RST 30H .text "....." JP ram + 56 ; RST 38H - interrupt INT .text "....." .text "Author Claudio Fin 1990/2014...." .text "....." JP ram + 102 ; NMI 66H ;------------------------------------------------------------------------------ ; Test e azzeramento RAM ;------------------------------------------------------------------------------ test: LD A,0b11110000 OUT (io_port),A LD HL,ram LD BC,ramtop - ram + 1 ram_c: LD A,255 LD (HL),A CP (HL) JP NZ,errormem XOR A LD (HL),A CP (HL) JP NZ,errormem INC HL DEC BC LD A,B OR C JR NZ,ram_c JR init errormem: DEC HL ; Usa il bit 4 di HL per lampeggio LED LD A,0b11110000 BIT 4,H JR NZ,errormem1 RES led_bit,A errormem1: OUT (io_port),A JR errormem ;------------------------------------------------------------------------------ ; Impostazione stack pointer, variabili sistema, uscite ;------------------------------------------------------------------------------ init: LD SP,vars ; IMPOSTA STACK POINTER LD A,205 ; CODICE CALL LD (vars),A LD A,201 ; CODICE RET LD (vars+3),A LD A,11110000B ; VALORI DI RIPOSO USCITE LD (out_val),a OUT (io_port),a ;------------------------------------------------------------------------------ ; Ciclo principale del programma ;------------------------------------------------------------------------------ main: CALL rx JR NC,main_err CP 31 JR C,main_err ; SE RICEVUTO < 31 ERRORE CALL Z,sync CP 32 CALL Z,load CP 33 CALL Z,dump CP 34 CALL Z,exec CP 35 JR NC,main_err ; SE RICEVUTO > 34 ERRORE JR main main_err: CALL error JR main ;------------------------------------------------------------------------------ ; Bytes di ritorno per controllo sincronizzazione 'OK' ;------------------------------------------------------------------------------ sync: PUSH AF LD A,'O' CALL tx LD A,'K' CALL tx POP AF RET ;------------------------------------------------------------------------------ ; Load dati da linea seriale ;------------------------------------------------------------------------------ load: PUSH AF PUSH BC PUSH HL CALL rx JR NC,load_err LD L,A CALL rx JR NC,load_err LD H,A CALL rx JR NC,load_err LD C,A CALL rx JR NC,load_err LD B,A load_1: CALL rx JR NC,load_err LD (HL),A INC HL DEC BC LD A,B OR C JR NZ,load_1 fine_load: POP HL POP BC POP AF RET load_err: CALL error JR fine_load ;------------------------------------------------------------------------------ ; Dump dati su linea seriale ;------------------------------------------------------------------------------ dump: PUSH AF PUSH BC PUSH HL CALL rx JR NC,dump_err LD L,A CALL rx JR NC,dump_err LD H,A CALL rx JR NC,dump_err LD C,A CALL rx JR NC,dump_err LD B,A dump_1: PUSH BC LD A,(HL) CALL tx INC HL POP BC DEC BC LD A,B OR C JR NZ,dump_1 fine_dump: POP HL POP BC POP AF RET dump_err: CALL error JR fine_dump ;------------------------------------------------------------------------------ ; CALL a indirizzo ;------------------------------------------------------------------------------ exec: PUSH AF CALL rx JR NC,exec_err LD (vars+1),A CALL rx JR NC,exec_err LD (vars+2),A CALL vars fine_exec: POP AF RET exec_err: CALL error JR fine_exec ;------------------------------------------------------------------------------ ; Segnalazione errore con safe write, si esce premendo ESC ;------------------------------------------------------------------------------ error: EX AF,AF' EXX error1: DEC HL ; Usa il bit 4 di HL per lampeggio LED LD A,(out_val) BIT 4,H JR NZ,error2 RES led_bit,A error2: OUT (io_port),A IN A,(io_port) BIT puls_bit,A JR NZ,error1 EXX EX AF,AF' RET ;------------------------------------------------------------------------------ ; Ricezione byte dalla linea seriale (9600, N, 8, 1, clock=4MHz) ; Lampeggio LED e safe write output ausiliari, si richiama anche con RST 08H ; Input: nessuno ; Output: Cf=1 A=byte ricevuto ; Cf=0 errore in ricezione ; Richiama: niente ;------------------------------------------------------------------------------ rx: EXX LD C,io_port rx_0: DEC HL ; USA IL BIT 7 DI HL PER LAMPEGGIO LED LD A,(out_val) BIT 7,H JR NZ,rx_1 RES led_bit,A rx_1: OUT (C),A IN A,(C) ; CAMPIONA LA LINEA IN ATTESA DELLO START JP M,rx_0 LD B,12 DJNZ $ ; PAUSA MEZZO BIT IN A,(C) ; RILEGGE START PER CONFERMA JP P,rx_e AND A ; RESETTA CF RET ; STOP ERRATO ESCE CON CF = 0 rx_e: LD B,8 ; CICLO DI LETTURA 8 BIT rx_c: PUSH BC LD B,28 DJNZ $ ; PAUSA 1 BIT POP BC IN A,(C) ; LEGGE BIT DATI RL A RR E DJNZ rx_c LD B,29 DJNZ $ ; PAUSA 1 BIT IN A,(C) ; LEGGE BIT DI STOP RLCA ; LO SPOSTA NEL CF LD A,E EXX RET ;------------------------------------------------------------------------------ ; Trasmissione byte su linea seriale con safe write output ausiliari, ; si richiama anche con RST 10H ; INPUT: A=byte ;------------------------------------------------------------------------------ tx: PUSH AF PUSH BC LD C,A LD A,(out_val) RES tx_bit,A OUT (io_port),A ; TRASMETTE BIT DI START LD B,25 ; RITARDO 1 BIT DJNZ $ XOR 0 ; DELAY LD B,10 ; 10 BIT DA TRASMETTERE tx_3: LD A,(out_val) SCF ;SETTA CARRY PER I BIT DI STOP RR C JR C,tx_2 RES tx_bit,A JR tx_4 tx_2: XOR 0 ; DELAY SET tx_bit,A tx_4: OUT (io_port),A EXX LD B,24 ; RITARDO 1 BIT DJNZ $ EXX DJNZ tx_3 POP BC POP AF RET