home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 508.lha / IO_Expansion_Board / Includes / IOexp.i next >
Text File  |  1991-05-06  |  13KB  |  508 lines

  1. *****************************************************************************
  2. * Program:  newser.i - ©1990 by The Puzzle Factory
  3. * Function: The One & Only master include file for the I/O Expansion board.
  4. *
  5. * Author:   Jeff Lavin
  6. * History:  08/23/90 JL V0.50 Created
  7. *           11/25/90 JL V0.51 Started to add parallel stuff
  8. *           12/10/90 JL V0.51 Added some more parallel stuff
  9. *           01/13/91 JL V0.52 Changed PUTDEBUG macro slightly
  10. *
  11. * [To all: Please don't forget to bump the revision numbers if you do *any*
  12. *          modifications at all.  -Jeff]
  13. *
  14. *****************************************************************************
  15. *
  16. * Some of the following is:
  17. *
  18. *****************************************************************************
  19. *
  20. * Copyright (C) 1985, Commodore Amiga Inc.  All rights reserved.
  21. * Permission granted for non-commercial use
  22. *
  23. * asmsupp.i -- random low level assembly support routines
  24. *              used by the Commodore sample Library & Device
  25. *
  26. *****************************************************************************
  27.  
  28. ;Set Tabs           |       |                 |       |
  29.  
  30.     ifeq    __M68
  31.     fail    "Using the wrong assembler!"
  32.     endc
  33.  
  34. ;Put a message to the serial port at 9600 baud.  Used as so:
  35. ;
  36. ;    PUTDEBUG   30,<'%s/Init: called'>
  37. ;
  38. ;Parameters can be printed out by pushing them on the stack and
  39. ;adding the appropriate C printf-style % formatting commands.
  40.  
  41. PUTDEBUG     macro        ;[level,msg]
  42.     ifge    INFO_LEVEL-\1
  43.     pea    (subSysName,pc)
  44.     movem.l a0/a1/d0/d1,-(sp)
  45.     lea    (.msg\@,pc),a0    ;Point to static format string
  46.     lea    (4*4,sp),a1    ;Point to args
  47.     bsr    KPutFmt
  48.     movem.l (sp)+,d0/d1/a0/a1
  49.     addq.w    #4,sp
  50.     bra.b    .end\@
  51.  
  52. .msg\@    cstr    '%s/',\2,10
  53.     even
  54. .end\@
  55.     endc
  56.     endm
  57.  
  58. ISDEBUG    macro
  59.     ifne    INFO_LEVEL    ;If any debugging enabled at all
  60. KPutFmt    move.l    a2,-(sp)
  61.     lea    (KPutChar,pc),a2
  62.     bsr.b    KDoFmt
  63.     movea.l    (sp)+,a2
  64.     rts
  65.  
  66. KDoFmt    move.l    a6,-(sp)
  67.     movea.l    (SysBase).w,a6
  68.     SYS    RawDoFmt
  69.     movea.l    (sp)+,a6
  70.     rts
  71. KPutChar:
  72.     move.l    a6,-(sp)
  73.     movea.l    (SysBase).w,a6
  74.     SYS    RawPutChar
  75.     movea.l    (sp)+,a6
  76.     rts
  77.  
  78. subSysName    cstr    \1    ;This name for debugging use
  79.     even
  80.     endc
  81.     endm
  82.  
  83. *****************************************************************************
  84. *
  85. * Here are the includes for the serial portion of the I/O Expansion Board.
  86. * Everything from here to the end of the file is:
  87. *
  88. *      Copyright (C) 1990 by Jeff Lavin  --  All rights reserved.
  89. *      Permission granted for non-commercial use.
  90. *
  91. *****************************************************************************
  92.  
  93. *** MACROS ***
  94.  
  95.     ifnd    SYS
  96. SYS    macro
  97.     jsr    (_LVO\1,a6)
  98.     endm
  99.     endc
  100.  
  101. EXEC    macro
  102.     move.l    a1,-(sp)
  103.     move.l    a6,-(sp)
  104.     movea.l    (SysBase).w,a6
  105.     jsr    (_LVO\1,a6)
  106.     movea.l    (sp)+,a6
  107.     movea.l    (sp)+,a1
  108.     endm
  109.  
  110. Disable    macro
  111.     ifc    '\1',''
  112.     move.w    #INTF_INTEN,(_intena).l
  113.     move.l    a6,-(sp)
  114.     movea.l    (SysBase).w,a6
  115.     addq.b    #1,(IDNestCnt,a6)
  116.     movea.l    (sp)+,a6
  117.     endc
  118.     ifnc    '\1',''
  119.     movea.l    (SysBase).w,\1
  120.     move.w    #INTF_INTEN,(_intena).l
  121.     addq.b    #1,(IDNestCnt,\1)
  122.     endc
  123.     endm
  124.  
  125. Enable    macro
  126.     ifc    '\1',''
  127.     move.l    a6,-(sp)
  128.     movea.l    (SysBase).w,a6
  129.     subq.b    #1,(IDNestCnt,a6)
  130.     movea.l    (sp)+,a6
  131.     bge.s    .Enable\#
  132.     move.w    #INTF_SETCLR!INTF_INTEN,(_intena).l
  133. .Enable\#
  134.     endc
  135.     ifnc    '\1',''
  136.     movea.l    (SysBase).w,\1
  137.     subq.b    #1,(IDNestCnt,\1)
  138.     bge.s    .Enable\#
  139.     move.w    #INTF_SETCLR!INTF_INTEN,(_intena).l
  140. .Enable\#
  141.     endc
  142.     endm
  143.  
  144. Forbid    macro
  145.     move.l    a6,-(sp)
  146.     movea.l    (SysBase).w,a6
  147.     addq.b    #1,(TDNestCnt,a6)
  148.     movea.l    (sp)+,a6
  149.     endm
  150.  
  151. Permit    macro
  152.     movem.l    d0/d1/a0/a1/a6,-(sp)
  153.     movea.l    (SysBase).w,a6
  154.     SYS    Permit
  155.     movem.l    (sp)+,d0/d1/a0/a1/a6
  156.     endm
  157.  
  158. PREFFILE    macro
  159.     cstr    'S:Serial-Preferences'
  160.     even
  161.     endm
  162.  
  163. MYDEVNAME    macro
  164.     cstr    'newser.device'
  165.     even
  166.     endm
  167.  
  168.  
  169. MYIDENT    macro
  170.     cstr    'newser alpha test version 1.0 (17 Aug 1990)',13,10
  171.     even
  172.     endm
  173.  
  174. MYUNITNAME1         macro
  175.     cstr    'SER1:'
  176.     even
  177.     endm
  178.  
  179. MYUNITNAME2         macro
  180.     cstr    'SER2:'
  181.     even
  182.     endm
  183.  
  184. MYUNITNAME3         macro
  185.     cstr    'SER3:'
  186.     even
  187.     endm
  188.  
  189. MYUNITNAME4         macro
  190.     cstr    'SER4:'
  191.     even
  192.     endm
  193.  
  194. PARDEVNAME    macro
  195.     cstr    'eightbit.device'
  196.     even
  197.     endm
  198.  
  199.  
  200. PARIDENT    macro
  201.     cstr    'eightbit alpha test version 1.0 (10 Dec 1990)',13,10
  202.     even
  203.     endm
  204.  
  205. PARUNITNAME1    macro
  206.     cstr    'PAR1:'
  207.     even
  208.     endm
  209.  
  210. PARUNITNAME2    macro
  211.     cstr    'PAR2:'
  212.     even
  213.     endm
  214.  
  215. PARUNITNAME3    macro
  216.     cstr    'PAR3:'
  217.     even
  218.     endm
  219.  
  220. PARUNITNAME4    macro
  221.     cstr    'PAR4:'
  222.     even
  223.     endm
  224.  
  225. *** EQUATES ***
  226.  
  227.     ifnd    SysBase
  228. SysBase    equ    4
  229.     endc
  230.  
  231. MYPROCSTACKSIZE    equ    $900    ;Stack size for the task we will create
  232.  
  233. MYPRI    equ    0    ;Used for configuring the roms
  234.  
  235. VERSION    equ    1    ;A major version number.
  236.  
  237. REVISION    equ    0    ;A particular revision
  238.  
  239. MYDEV_END    equ    CMD_NONSTD+2    ;Number of device comands 
  240.  
  241. MD_NUMUNITS    equ    4    ;Maximum number of units in this device
  242.  
  243. *** New SerialPrefs Structure ***
  244.  
  245. UnitPrefs    clrso
  246. up_BufSize    so.w    1    ;0 to 7
  247. up_BaudRate    so.w    1    ;0 to 15
  248. up_WordLen    so.b    1    ;0=5, 1=6, 2=7, 3=8
  249. up_StopBits    so.b    1    ;0=1, 1=2
  250. up_Parity    so.b    1    ;0=Odd, 1=Even, 2=Mark, 3=Space, 4=None
  251. up_Shake    so.b    1    ;0=RTS/CTS, 1=xON/xOFF
  252. up_Sizeof    soval
  253.  
  254. SerialPrefs    clrso
  255. sp_Unit01    so.b    up_Sizeof    ;For ACIA 0, Unit 1
  256. sp_Unit02    so.b    up_Sizeof    ;For ACIA 0, Unit 2
  257. sp_Unit11    so.b    up_Sizeof    ;For ACIA 1, Unit 1
  258. sp_Unit12    so.b    up_Sizeof    ;For ACIA 1, Unit 2
  259. sp_Sizeof    soval
  260.  
  261. serprefs    clrso
  262. prefs_CTLCHAR    so.l    1    ;Control char's (order = xON,xOFF,rsvd,rsvd)
  263. prefs_RBUFLEN    so.l    1    ;Length in bytes of serial port's read buffer
  264. prefs_EXTFLAGS    so.l    1    ;Additional serial flags
  265. prefs_BAUD    so.l    1    ;Baud rate requested (true baud)
  266. prefs_BRKTIME    so.l    1    ;Duration of break signal in MICROseconds
  267. prefs_TERMARRAY    so.b    TERMARRAY_SIZE    ;Termination character array
  268. prefs_READLEN    so.b    1    ;Bits per read char (bit count)
  269. prefs_WRITELEN    so.b    1    ;Bits per write char (bit count)
  270. prefs_STOPBITS    so.b    1    ;Stopbits for read (count)
  271. prefs_SERFLAGS    so.b    1    ;See SERFLAGS bit definitions
  272. serprefs_sizeof    soval
  273.  
  274. MyDev    setso    LIB_SIZE
  275. md_Flags    so.b    1
  276. md_Pad1    so.b    1
  277. md_SysLib    so.l    1
  278. md_SegList    so.l    1
  279. md_Units    so.b    MD_NUMUNITS*4
  280. prefs_unit0    so.b    serprefs_sizeof    ;The reason why prefs are in this
  281. prefs_unit1    so.b    serprefs_sizeof    ;structure instead of the unit structure
  282. prefs_unit2    so.b    serprefs_sizeof    ;is that the pref settings should be saved
  283. prefs_unit3    so.b    serprefs_sizeof    ;across CloseDevice calls (which usually
  284. MyDev_Sizeof    soval        ;causes the unit to be dumped).
  285.  
  286. MyDevUnit    setso    UNIT_SIZE    ;Odd # longwords
  287. mdu_wport    so.b    MP_SIZE    ;MsgPort for write task
  288. MDU_FLAGS    so.b    1
  289. IERstate    so.b    1    ;Current state of IER used as a mask
  290. mdu_UnitNum    so.b    1
  291. frstate    so.b    1    ;This var mirrors a write-only register
  292. mdu_SysLib    so.l    1    ;Copy of location 4
  293. mdu_Device    so.l    1    ;Ptr to main device struct
  294. mdu_rstack    so.b    MYPROCSTACKSIZE    ;For read task
  295. mdu_wstack    so.b    MYPROCSTACKSIZE    ;For write task
  296. mdu_rtcb    so.b    TC_SIZE    ;Task Control Block (TCB) for read task
  297. mdu_wtcb    so.b    TC_SIZE    ;Task Control Block (TCB) for write task
  298. mdu_is    so.b    IS_SIZE    ;Interrupt structure
  299. timerport    so.b    MP_SIZE
  300. timeriorequest    so.b    IOTV_SIZE
  301. AltBuf    so.b    64    ;64-byte alternate buffer
  302. readsig    so.l    1    ;Read task signals
  303. readabortsig    so.l    1
  304. tdresig    so.l    1    ;Transmit buffer empty - put another byte
  305. dsrsig    so.l    1    ;Transition on DSR - used for handshaking (if enabled)
  306. writeabortsig    so.l    1
  307. xonsig    so.l    1    ;Comes from read task, and indicates xon received
  308. breaksig    so.l    1    ;This is an Exec exception signal
  309. head    so.l    1    ;Ptr to start of circular buffer (logical)
  310. tail    so.l    1    ;Ptr to end of circular buffer (logical)
  311. startbuf    so.l    1    ;Ptr to physical start of input buffer
  312. endbuf    so.l    1    ;Ptr to physical end of input buffer
  313. ReadRequestPtr    so.l    1
  314. WriteRequestPtr    so.l    1
  315. breakiorequest    so.l    1
  316. xstate    so.b    1    ;Zero if 'x-off' received, else $FF
  317. ISRcopy    so.b    1    ;Used for read error diagnosis
  318. CSRcopy    so.b    1    ;Used for read error diagnosis
  319. Exclusive    so.b    1    ;True if someone has exclusive access to this unit
  320. daciabase    so.l    1
  321. mdu_prefs    so.l    1    ;Ptr to prefs for this unit (in MyDev)
  322. MyDevUnit_Sizeof    soval
  323.  
  324. ;Note that we have a single unit structure used by both the read and write
  325. ;tasks (and the interrupt routine).
  326.  
  327. * UNIT_FLAG definitions:
  328.  
  329.     BITDEF    UNIT,INREADTASK,0    
  330.     BITDEF    UNIT,INWRITETASK,1
  331.     BITDEF    UNIT,READACTIVE,2
  332.     BITDEF    UNIT,WRITEACTIVE,3
  333.     BITDEF    UNIT,BREAKACTIVE,4
  334.     BITDEF    UNIT,INBREAK,5
  335.  
  336. ;INBREAK is used by the queued break routine to protect against immediate breaks
  337. ;(a rather unlikely scenereo, but it might happen; who knows?)
  338.  
  339. * Bit definitions for MDU_FLAGS
  340.  
  341.     BITDEF    MDU,STOPPED,2    ;State bit for unit stopped
  342.     BITDEF    MDU,V,3    ;Buffer overflow flag - set in int routine if an overflow occurs
  343.  
  344. * Bit definitions for ioflags
  345.  
  346.     BITDEF    ioflags,Active,4    ;IO request in progress
  347.     BITDEF    ioflags,Ignore,5    ;Ignore this IO request
  348.  
  349. * Equates & bit defs for IERstate
  350.  
  351. READINT    equ    $87
  352. READINTMASK    equ    $7
  353.  
  354. HANDINT    equ    $88
  355. HANDINTMASK    equ    $8
  356.  
  357. WRITEINT    equ    $C0
  358. WRITEINTMASK    equ    $40
  359.  
  360. WRITEOFF    equ    $40
  361. WRITEOFFMASK    equ    $BF
  362.  
  363. *** The Hardware ***
  364.  
  365. _custom    equ    $DFF000
  366. _intena    equ    _custom+intena
  367.  
  368. ;The ACIAs are located at $400 byte boundaries beginning at ACIA_Base:
  369. ;
  370. ; Unit1    equ    $BF9000    ;65C52 DACIA chip 1, unit 1
  371. ; Unit2    equ    $BF9400    ;65C52 DACIA chip 1, unit 2
  372. ; Unit3    equ    $BF9800    ;65C52 DACIA chip 2, unit 1
  373. ; Unit4    equ    $BF9C00    ;65C52 DACIA chip 2, unit 2
  374.  
  375. ACIA_Base    equ    $BF9000    ;Base address of all units
  376. ACIA0    equ    $0000    ;Offset of 1st chip
  377. ACIA1    equ    $0800    ;Offset of 2nd chip
  378. UNIT2    equ    $0400    ;Offset of 2nd unit
  379.  
  380. IER    equ    $0000    ;Interrupt Enable Register
  381. ISR    equ    $0000    ;Interrupt Status Register
  382. CTR    equ    $0100    ;Control Register
  383. FMR    equ    $0100    ;Format Register
  384. CSR    equ    $0100    ;Control Status Register
  385. CDR    equ    $0200    ;Compare Data Register
  386. ACR    equ    $0200    ;Auxilliary Control Register
  387. TDR    equ    $0300    ;Transmit Data Register
  388. RDR    equ    $0300    ;Receive Data Register
  389.  
  390. * Interrupt Status Registers (ISR1=0, ISR2=4) Read only
  391.  
  392.     BITDEF    ISR,SETCLR,7    ;Any bit set
  393.     BITDEF    ISR,TDRE,6    ;Transmit Data Register Empty
  394.     BITDEF    ISR,CTST,5    ;Transition on *CTS Line
  395.     BITDEF    ISR,DCDT,4    ;Transition on *DCD Line
  396.     BITDEF    ISR,DSRT,3    ;Transition on *DSR Line
  397.     BITDEF    ISR,PAR,2    ;Parity status
  398.     BITDEF    ISR,FEOB,1    ;Frame error, Overrun, Break
  399.     BITDEF    ISR,RDRF,0    ;Receive Data Register Full
  400.  
  401. * Interrupt Enable Registers (IER1=0, IER2=4) Write only
  402.  
  403.     BITDEF    IER,SETCLR,7    ;Same as above
  404.     BITDEF    IER,TDRE,6
  405.     BITDEF    IER,CTST,5
  406.     BITDEF    IER,DCDT,4
  407.     BITDEF    IER,DSRT,3
  408.     BITDEF    IER,PAR,2
  409.     BITDEF    IER,FEOB,1
  410.     BITDEF    IER,RDRF,0
  411.  
  412. * Control Status Registers (CSR1=1, CSR2=5) Read only
  413.  
  414.     BITDEF    CSR,FE,7    ;Framing Error
  415.     BITDEF    CSR,TUR,6    ;Transmitter Underrun
  416.     BITDEF    CSR,CTSL,5    ;*CTS Level
  417.     BITDEF    CSR,DCDL,4    ;*DCD Level
  418.     BITDEF    CSR,DSRL,3    ;*DSR Level
  419.     BITDEF    CSR,RBRK,2    ;Receive Break
  420.     BITDEF    CSR,DTRL,1    ;*DTR Level
  421.     BITDEF    CSR,RTSL,0    ;*RTS Level
  422.  
  423. * Control Registers (CR1=1, CR2=5) Write only
  424.  
  425.     BITDEF    CR,CTRL,7    ;1=Access FMR,  0=Access CTR
  426.     BITDEF    CR,AUX,6    ;1=Access ACR,  0=Access CDR
  427.     BITDEF    CR,STOP2,5    ;1=2 stop bits, 0=1 stop bit
  428.     BITDEF    CR,ECHO,4    ;1=Echo mode,   0=Echo mode disabled
  429.  
  430. Baud_50    equ    %00000000    ;Bits 3-0
  431. Baud_110    equ    %00000001
  432. Baud_134    equ    %00000010
  433. Baud_150    equ    %00000011
  434. Baud_300    equ    %00000100
  435. Baud_600    equ    %00000101
  436. Baud_1200    equ    %00000110
  437. Baud_1800    equ    %00000111
  438. Baud_2400    equ    %00001000
  439. Baud_3600    equ    %00001001
  440. Baud_4800    equ    %00001010
  441. Baud_7200    equ    %00001011
  442. Baud_9600    equ    %00001100
  443. Baud_19200    equ    %00001101
  444. Baud_38400    equ    %00001110
  445. Baud_EXT    equ    %00001111
  446.  
  447. * Format Registers (FR1=1, FR2=5) Write only
  448.  
  449.     BITDEF    FR,FRMT,7    ;1=Access FR, 0=Access CR
  450.  
  451. WORDLEN_5    equ    %00000000    ;Bits 5-6
  452. WORDLEN_6    equ    %00100000
  453. WORDLEN_7    equ    %01000000
  454. WORDLEN_8    equ    %01100000
  455.  
  456. PAR_ODD    equ    %00000000    ;Bits 3-4
  457. PAR_EVEN    equ    %00001000
  458. PAR_MARK    equ    %00010000
  459. PAR_SPACE    equ    %00011000
  460.  
  461.     BITDEF    FR,PAR,2    ;1=Parity as specified in bits 3-4
  462.     BITDEF    FR,DTR,1    ;1=Set DTR hi, 0=Set DTR lo
  463.     BITDEF    FR,RTS,0    ;1=Set RTS hi, 0=Set RTS lo
  464.  
  465. * Compare Data Register  (CDR1=2, CDR2=6) Write only
  466.  
  467. ;Bit 6 of Control Register must be 0.  By writing a value into this
  468. ;register, the DACIA is put into the compare mode.  In this mode the Receive
  469. ;Data Register Full bit is inhibited until a character is received that
  470. ;matches the value in this register.  The next character is then received
  471. ;normally.
  472.  
  473. * Auxiliary Control Registers (ACR1=2, ACR2=6) Write only
  474.  
  475. ;Bit 6 of Control Register must be 1.
  476.  
  477.     BITDEF    ACR,BRK,1    ;Transmit break
  478.     BITDEF    ACR,ARM,0    ;Address recognition mode
  479.  
  480. *****************************************************************************
  481. *
  482. * Here are the includes for the parallel portion of the I/O Expansion Board.
  483. *
  484. *****************************************************************************
  485.  
  486. VIA_Base    equ    $BF1000    ;Base address of all units
  487. VIA0    equ    $0000    ;VIA #0 Base offset
  488. VIA1    equ    $4000    ;VIA #1 Base offset
  489.  
  490. ORB    equ    $0000    ;I/O Register B
  491. ORA    equ    $0100    ;I/O Register A
  492. DDRB    equ    $0200    ;Data Direction Register B
  493. DDRA    equ    $0300    ;Data Direction Register A
  494. T1CL    equ    $0400    ;Timer #1 Counter (lower 8 bits)
  495. T1CH    equ    $0500    ;Timer #1 Counter (upper 8 bits)
  496. T1LL    equ    $0600    ;Timer #1 Latch (lower 8 bits)
  497. T1LH    equ    $0700    ;Timer #1 Latch (upper 8 bits)
  498. T2CL    equ    $0800    ;Timer #2 Counter (lower 8 bits)
  499. T2CH    equ    $0900    ;Timer #2 Counter (upper 8 bits)
  500. SHFTR    equ    $0A00    ;Shift Register
  501. AUXCR    equ    $0B00    ;Auxiliary Control Register
  502. PERCR    equ    $0C00    ;Peripheral Control Register
  503. INTFR    equ    $0D00    ;Interrupt Flag Register
  504. INTER    equ    $0E00    ;Interrupt Enable Register
  505. ORAF    equ    $0F00    ;I/O Register A (no handshake)
  506.  
  507. ;End of File
  508.