Sigrid Haflínudóttirfirst dirty version of the portd7ad0686 years agoHistory
2801 lines · 56.6 KB · C
RawDownload
/*	SCCEMDEV.c 	Copyright (C) 2012 Philip Cummins, Weston Pawlowski,		Michael Fort, Paul C. Pratt 	You can redistribute this file and/or modify it under the terms	of version 2 of the GNU General Public License as published by	the Free Software Foundation.  You should have received a copy	of the license along with this file; see the file COPYING. 	This file is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	license for more details.*/ /*	Serial Communications Controller EMulated DEVice 	additions for LocalTalk networking support		Copyright 2011-2012, Michael Fort		enabled with "EmLocalTalk" 	-- original description: -- 	Emulates the Z8530 SCC found in the Mac Plus.		But only the minimum amount needed to emulate		normal operation in a Mac Plus with nothing		connected to the serial ports.		(and not even that much is complete yet) 	This code adapted from "SCC.c" in vMac by Philip Cummins.	With additional code by Weston Pawlowski from the Windows	port of vMac. 	Further information was found in the	"Zilog SCC/ESCC User's Manual".*/ #ifndef AllFiles#include "SYSDEPNS.h" #include "MYOSGLUE.h"#include "EMCONFIG.h"#include "GLOBGLUE.h"#endif #include "SCCEMDEV.h" /*	ReportAbnormalID unused 0x0721, 0x0722, 0x074D - 0x07FF*/ #define SCC_dolog (dbglog_HAVE && 0)#define SCC_TrackMore 0 /* Just to make things a little easier */#define Bit0 1#define Bit1 2#define Bit2 4#define Bit3 8#define Bit4 16#define Bit5 32#define Bit6 64#define Bit7 128 /* SCC Interrupts */#define SCC_A_Rx       8 /* Rx Char Available */#define SCC_A_Rx_Spec  7 /* Rx Special Condition */#define SCC_A_Tx_Empty 6 /* Tx Buffer Empty */#define SCC_A_Ext      5 /* External/Status Change */#define SCC_B_Rx       4 /* Rx Char Available */#define SCC_B_Rx_Spec  3 /* Rx Special Condition */#define SCC_B_Tx_Empty 2 /* Tx Buffer Empty */#define SCC_B_Ext      1 /* External/Status Change */ typedef struct {	blnr TxEnable;	blnr RxEnable;	blnr TxIE; /* Transmit Interrupt Enable */	blnr TxUnderrun;	blnr SyncHunt;	blnr TxIP; /* Transmit Interrupt Pending */#if EmLocalTalk	ui3r RxBuff;#endif#if EmLocalTalk	/* otherwise TxBufferEmpty always true */	/*		though should behave as went false		for an instant when write to transmit buffer	*/	blnr TxBufferEmpty;#endif#if EmLocalTalk || SCC_TrackMore	blnr ExtIE;#endif#if SCC_TrackMore	blnr WaitRqstEnbl;#endif#if SCC_TrackMore	blnr WaitRqstSlct;#endif#if SCC_TrackMore	blnr WaitRqstRT;#endif#if SCC_TrackMore	blnr PrtySpclCond;#endif#if SCC_TrackMore	blnr PrtyEnable;#endif#if SCC_TrackMore	blnr PrtyEven;#endif#if SCC_TrackMore	blnr RxCRCEnbl;#endif#if SCC_TrackMore	blnr TxCRCEnbl;#endif#if SCC_TrackMore	blnr RTSctrl;#endif#if SCC_TrackMore	blnr SndBrkCtrl;#endif#if SCC_TrackMore	blnr DTRctrl;#endif#if EmLocalTalk || SCC_TrackMore	blnr AddrSrchMd;#endif#if SCC_TrackMore	blnr SyncChrLdInhb;#endif#if SCC_TrackMore	ui3r ClockRate;#endif#if SCC_TrackMore	ui3r DataEncoding;#endif#if SCC_TrackMore	ui3r TRxCsrc;#endif#if SCC_TrackMore	ui3r TClkSlct;#endif#if SCC_TrackMore	ui3r RClkSlct;#endif#if SCC_TrackMore	ui3r RBitsPerChar;#endif#if SCC_TrackMore	ui3r TBitsPerChar;#endif#if EmLocalTalk || SCC_TrackMore	ui3r RxIntMode;#endif#if EmLocalTalk || SCC_TrackMore	blnr FirstChar;#endif#if EmLocalTalk || SCC_TrackMore	ui3r SyncMode;#endif#if SCC_TrackMore	ui3r StopBits;#endif#if 0 /* AllSent always true */	blnr AllSent;#endif#if 0 /* CTS always false */	blnr CTS; /* input pin, unattached, so false? */#endif#if 0 /* DCD always false */	blnr DCD; /* Data Carrier Detect */		/*			input pin for mouse interrupts. but since			not emulating mouse this way, leave false.		*/#endif#if EmLocalTalk	/* otherwise RxChrAvail always false */	blnr RxChrAvail;#endif#if 0 /* RxOverrun always false */	blnr RxOverrun;#endif#if 0 /* CRCFramingErr always false */	blnr CRCFramingErr;#endif#if EmLocalTalk	/* otherwise EndOfFrame always false */	blnr EndOfFrame;#endif#if 0 /* ParityErr always false */	blnr ParityErr;#endif#if 0 /* ZeroCount always false */	blnr ZeroCount;#endif#if 0 /* BreakAbort always false */	blnr BreakAbort;#endif#if 0 /* SyncHuntIE usually false */	blnr SyncHuntIE;#endif#if SCC_TrackMore /* don't care about CTS_IE */	blnr CTS_IE;#endif#if SCC_TrackMore	blnr CRCPreset;#endif#if SCC_TrackMore	blnr BRGEnbl;#endif#if 0 /* don't care about DCD_IE, always true */	blnr DCD_IE;#endif#if SCC_TrackMore /* don't care about BreakAbortIE */	blnr BreakAbortIE;#endif#if SCC_TrackMore /* don't care about Baud */	ui3r BaudLo;	ui3r BaudHi;#endif} Channel_Ty; typedef struct {	Channel_Ty a[2]; /* 0 = channel A, 1 = channel B */	int SCC_Interrupt_Type;	int PointerBits;	ui3b InterruptVector;	blnr MIE; /* master interrupt enable */#if SCC_TrackMore	blnr NoVectorSlct;#endif#if 0 /* StatusHiLo always false */	blnr StatusHiLo;#endif} SCC_Ty; LOCALVAR SCC_Ty SCC; #if 0LOCALVAR int ReadPrint;LOCALVAR int ReadModem;#endif #if EmLocalTalkstatic int rx_data_offset = 0;	/* when data pending, this is used */#endif EXPORTFUNC blnr SCC_InterruptsEnabled(void){	return SCC.MIE;} /* ---- */ /* Function used to update the interrupt state of the SCC */LOCALPROC CheckSCCInterruptFlag(void){#if 0 /* ReceiveAInterrupt always false */	blnr ReceiveAInterrupt = falseblnr		/*			also dependeds on WR1, bits 3 and 4, but			this doesn't change that it's all false		*/#if EmLocalTalk		/* otherwise RxChrAvail always false */		| SCC.a[0].RxChrAvail#endif#if 0 /* RxOverrun always false */		| SCC.a[0].RxOverrun#endif#if 0 /* CRCFramingErr always false */		| SCC.a[0].CRCFramingErr#endif#if EmLocalTalk		/* otherwise EndOfFrame always false */		| SCC.a[0].EndOfFrame#endif#if 0 /* ParityErr always false */		| SCC.a[0].ParityErr#endif		;#endif#if 0	blnr TransmitAInterrupt = SCC.a[0].TxBufferEmpty;	/*		but probably looking for transitions not		current value	*/#endif#if 0	blnr ExtStatusAInterrupt = 0#if 0 /* ZeroCount always false */		| SCC.a[0].ZeroCount#endif		/* probably want transition for these, not value */#if 0 /* DCD always false */		| SCC.a[0].DCD /* DCD IE always true */#endif#if 0 /* CTS always false */		| SCC.a[0].CTS /* would depend on CTS_IE */#endif		| SCC.a[0].SyncHunt /* SyncHuntIE usually false */		| SCC.a[0].TxUnderrun /* Tx underrun/EOM IE always false */#if 0 /* BreakAbort always false */		| SCC.a[0].BreakAbort#endif		;#endif	ui3b NewSCCInterruptRequest; #if EmLocalTalk	blnr ReceiveBInterrupt = falseblnr;	blnr RxSpclBInterrupt = falseblnr		/* otherwise EndOfFrame always false */		| SCC.a[1].EndOfFrame		;#endif #if EmLocalTalk	switch (SCC.a[1].RxIntMode) {		case 0:			/* disabled */			RxSpclBInterrupt = falseblnr;			break;		case 1:			/* Rx INT on 1st char or special condition */			if (SCC.a[1].RxChrAvail && SCC.a[1].FirstChar) {				ReceiveBInterrupt = trueblnr;			}			break;		case 2:			/* INT on all Rx char or special condition */			if (SCC.a[1].RxChrAvail) {				ReceiveBInterrupt = trueblnr;			}			break;		case 3:			/* Rx INT on special condition only */			break;	}#endif 	/* Master Interrupt Enable */	if (! SCC.MIE) {		SCC.SCC_Interrupt_Type = 0;	} else#if 0	/* External Interrupt Enable */	if (SCC.a[1].ExtIE) {		/* DCD Interrupt Enable */		if (SCC.a[1].DCD_IE && 0) { /* dcd unchanged */			SCC.SCC_Interrupt_Type = ??;		}	}#endif	if (SCC.a[0].TxIP && SCC.a[0].TxIE) {		SCC.SCC_Interrupt_Type = SCC_A_Tx_Empty;	} else#if EmLocalTalk	if (ReceiveBInterrupt) {		SCC.SCC_Interrupt_Type = SCC_B_Rx;	} else	if (RxSpclBInterrupt) {		SCC.SCC_Interrupt_Type = SCC_B_Rx_Spec;	} else#endif	if (SCC.a[1].TxIP && SCC.a[1].TxIE) {		SCC.SCC_Interrupt_Type = SCC_B_Tx_Empty;	} else	{		SCC.SCC_Interrupt_Type = 0;	} 	NewSCCInterruptRequest = (SCC.SCC_Interrupt_Type != 0) ? 1 : 0;	if (NewSCCInterruptRequest != SCCInterruptRequest) {#if SCC_dolog		dbglog_WriteSetBool("SCCInterruptRequest change",			NewSCCInterruptRequest); 		dbglog_StartLine();		dbglog_writeCStr("SCC.SCC_Interrupt_Type <- ");		dbglog_writeHex(SCC.SCC_Interrupt_Type);		dbglog_writeReturn();#endif		SCCInterruptRequest = NewSCCInterruptRequest;#ifdef SCCinterruptChngNtfy		SCCinterruptChngNtfy();#endif	}} LOCALPROC SCC_InitChannel(int chan){	/* anything not done by ResetChannel */ 	SCC.a[chan].SyncHunt = trueblnr;#if 0 /* DCD always false */	SCC.a[chan].DCD = falseblnr; /* input pin, reset doesn't change */#endif#if 0 /* CTS always false */	SCC.a[chan].CTS = falseblnr; /* input pin, reset doesn't change */#endif#if 0 /* AllSent always true */	SCC.a[chan].AllSent = trueblnr;#endif#if SCC_TrackMore /* don't care about Baud */	SCC.a[chan].BaudLo = 0;	SCC.a[chan].BaudHi = 0;#endif#if 0 /* BreakAbort always false */	SCC.a[chan].BreakAbort = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].BRGEnbl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].TRxCsrc = 0;#endif#if SCC_TrackMore	SCC.a[chan].TClkSlct = 1;#endif#if SCC_TrackMore	SCC.a[chan].RClkSlct = 0;#endif} LOCALPROC SCC_ResetChannel(int chan){/* RR 0 */#if EmLocalTalk	SCC.a[chan].RxBuff = 0;#endif#if EmLocalTalk	/* otherwise RxChrAvail always false */	SCC.a[chan].RxChrAvail = falseblnr;#endif#if 0 /* ZeroCount always false */	SCC.a[chan].ZeroCount = falseblnr;#endif#if EmLocalTalk	/* otherwise TxBufferEmpty always true */	SCC.a[chan].TxBufferEmpty = trueblnr;#endif	SCC.a[chan].TxUnderrun = trueblnr;/* RR 1 */#if 0 /* ParityErr always false */	SCC.a[chan].ParityErr = falseblnr;#endif#if 0 /* RxOverrun always false */	SCC.a[chan].RxOverrun = falseblnr;#endif#if 0 /* CRCFramingErr always false */	SCC.a[chan].CRCFramingErr = falseblnr;#endif#if EmLocalTalk	/* otherwise EndOfFrame always false */	SCC.a[chan].EndOfFrame = falseblnr;#endif/* RR 3 */#if EmLocalTalk || SCC_TrackMore	SCC.a[chan].ExtIE = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].RxCRCEnbl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].TxCRCEnbl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].RTSctrl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].SndBrkCtrl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].DTRctrl = falseblnr;#endif#if EmLocalTalk || SCC_TrackMore	SCC.a[chan].AddrSrchMd = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].SyncChrLdInhb = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].WaitRqstEnbl = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].WaitRqstSlct = falseblnr;#endif#if SCC_TrackMore	SCC.a[chan].WaitRqstRT = falseblnr;

Lines 1–500 of 2801.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t