; ports description and include file
 
;for NeoGS software projects, v0.3
 
;
 
; bits degisnation:
 
; B_* - bit position (0,1,2,3,4,5,6,7),
 
; M_* - bit mask (1,2,4,8,#10,#20,#40,#80)
 
; C_* - constants to be used
 
;
 
; part of NeoGS project
 
;
 
; (c) 2008 NedoPC
 
 
 
;ZX-side ports
 
 
 
GSCOM=0xBB ;write-only, command for NGS
 
 
 
GSSTAT=0xBB ;read-only, command and data bits
 
                ; (positions given immediately below)
 
 
 
B_CBIT=0 ;Command   position
 
M_CBIT=1 ;       BIT        and mask
 
 
 
B_DBIT=7   ;Data   position
 
M_DBIT=0x80 ;    BIT        and mask
 
 
 
 
 
GSDAT=0xB3 ; read-write, data transfer register for NGS
 
 
 
GSCTR=0x33 ; write-only, control register for NGS:
 
                ;constants available given immediately below
 
 
 
C_GRST=0x80 ; reset constant to be written into GSCTR
 
C_GNMI=0x40 ; NMI constant to be written into GSCTR
 
C_GLED=0x20 ; LED toggle constant
 
 
 
 
 
;GS-side ports
 
 
 
MPAG=0x00 ; write-only, Memory PAGe port
 
                ;(big pages at 8000-FFFF or small at 8000-BFFF)
 
MPAGEX=0x10 ; write-only, Memory PAGe EXtended
 
                ;(only small pages at C000-FFFF)
 
 
 
ZXCMD=0x01 ; read-only, ZX CoMmanD port: here is the byte
 
                ;written by ZX into GSCOM
 
 
 
ZXDATRD=0x02 ; read-only, ZX DATa ReaD: a byte written by ZX
 
                ;into GSDAT appears here;
 
                ; upon reading this port, data bit is cleared
 
 
 
ZXDATWR=0x03 ; write-only, ZX DATa WRite: a byte written here
 
                ;is available for ZX in GSDAT;
 
                ; upon writing here, data bit is set
 
 
 
ZXSTAT=0x04 ; read-only, read ZX STATus:
 
                ;command and data bits.
 
               ;positions are defined by *_CBIT and *_DBIT above
 
 
 
CLRCBIT=0x05 ; read-write, upon either reading or writing
 
                ;this port, the Command BIT is CLeaRed
 
 
 
VOL1=0x06 ; write-only, volumes for sound channels 1-8
 
VOL2=0x07
 
VOL3=0x08
 
VOL4=0x09
 
VOL5=0x16
 
VOL6=0x17
 
VOL7=0x18
 
VOL8=0x19
 
 
 
; following two ports are useless and very odd. They have been
 
;made just because they were on the original GS and for that
 
; strange case when somebody too crazy have used them.
 
;Nevertheless, DO NOT USE THEM! They can disappear or even
 
;radically change functionality in future firmware releases.
 
DAMNPORT1=0x0A ; writing or reading this port sets data bit
 
                  ;to the inverse of bit 0 into MPAG port
 
DAMNPORT2=0x0B ; the same as DAMNPORT1, but instead command
 
           ;bit involved, which is made equal to 5th bit of VOL4
 
 
 
LEDCTR=0x01 ; write-only, controls on-board LED.
 
                ;D0=0 - LED is on, D0=1 - LED is off
 
                ; reset state is LED on.
 
 
 
GSCFG0=0x0F ; read-write, GS ConFiG port 0:
 
                ;acts as memory cell, reads previously written
 
                ;value. Bits and fields follow:
 
 
 
B_NOROM=0 ; =0 - there is ROM everywhere except 4000-7FFF,
 
              ; =1 - the RAM is all around
 
M_NOROM=1
 
 
 
B_RAMRO=1 ; =1 - ram absolute addresses 0000-7FFF
 
               ;(zeroth big page) are write-protected
 
M_RAMRO=2
 
 
 
B_8CHANS=2 ; =1 - 8 channels mode
 
M_8CHANS=4
 
 
 
B_EXPAG=3 ; =1 - extended paging: both MPAG and MPAGEX are
 
               ;used to switch two memory windows
 
M_EXPAG=8
 
 
 
B_CKSEL0=4   ;these bits should be set according to the
 
                 ;C_**MHZ constants below
 
M_CKSEL0=0x10
 
B_CKSEL1=5
 
M_CKSEL1=0x20
 
 
 
C_10MHZ=0x30
 
C_12MHZ=0x10
 
C_20MHZ=0x20
 
C_24MHZ=0x00
 
 
 
B_PAN4CH=6  ; =1 - 4 channels, panning
 
;(every channel is on left and right with two volumes)
 
M_PAN4CH=0x40
 
 
 
B_SETNCLR=7
 
M_SETNCLR=0x80
 
 
 
 
 
SCTRL=0x11 ;Serial ConTRoL: read-write,
 
                ;read: current state of below bits,
 
                ;write - see GS_info
 
 
 
B_SDNCS=0
 
M_SDNCS=1
 
 
 
B_MCNCS=1
 
M_MCNCS=2
 
 
 
B_MPXRS=2
 
M_MPXRS=4
 
 
 
B_MCSPD0=3
 
M_MCSPD0=8
 
 
 
B_MDHLF=4
 
M_MDHLF=0x10
 
 
 
B_MCSPD1=5
 
M_MCSPD1=0x20
 
 
 
 
 
SSTAT=0x12 ;Serial STATus:
 
              ;read-only, reads state of below bits
 
 
 
B_MDDRQ=0
 
M_MDDRQ=1
 
 
 
B_SDDET=1
 
M_SDDET=2
 
 
 
B_SDWP=2
 
M_SDWP=4
 
 
 
B_MCRDY=3
 
M_MCRDY=8
 
 
 
 
 
SD_SEND=0x13 ;SD card SEND, write-only,
 
          ;when written, byte transfer starts with written byte
 
SD_READ=0x13 ;SD card READ, read-only,
 
          ;reads byte received in previous byte transfer
 
SD_RSTR=0x14 ;SD card Read and STaRt, read-only, reads
 
;previously received byte and starts new byte transfer with #FF
 
 
 
MD_SEND=0x14 ;Mp3 Data SEND, write-only,
 
          ;sends byte to the mp3 data interface
 
 
 
MC_SEND=0x15 ;Mp3 Control SEND, write-only,
 
          ;sends byte to the mp3 control interface
 
MC_READ=0x15 ;Mp3 Control READ, read-only,
 
;reads byte that was received during previous sending of byte
 
 
 
DMA_MOD=0x1B
 
DMA_HAD=0x1C
 
DMA_MAD=0x1D
 
DMA_LAD=0x1E
 
DMA_CST=0x1F
 
 
 
;Послать код команды в регистр команд
 
        MACRO SC cmd
 
        LD A,cmd
 
        OUT (GSCOM),A
 
        ENDM 
 
 
 
;Ожидание сброса Command bit
 
        MACRO WC
 
        ;LOCAL 
 
;WCLP    
 
        IN A,(GSCOM)
 
        RRCA 
 
        JR C,$-3;WCLP
 
        ;ENDL 
 
        ENDM 
 
 
 
;Послать данные в регистр данных
 
        MACRO SD data
 
        LD A,data
 
        OUT (GSDAT),A
 
        ENDM 
 
 
 
;Ожидание сброса Data bit
 
;по сути,ожидание,пока GS не примет посланные ему данные
 
        MACRO WD
 
        ;LOCAL 
 
;WDLP    
 
        IN A,(GSCOM)
 
        RLCA 
 
        JR C,$-3;WDLP
 
        ;ENDL 
 
        ENDM 
 
 
 
;Принять данные из регистра данных
 
        MACRO GD
 
        IN A,(GSDAT)
 
        ENDM 
 
 
 
;Ожидание установки Data bit
 
;по сути,ожидание очередных данных от GS
 
        MACRO WN
 
        ;LOCAL 
 
;WNLP
 
        IN A,(GSCOM)
 
        RLCA 
 
        JR NC,$-3;WNLP
 
        ;ENDL 
 
        ENDM