]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Define fifos: msg_tx_fifo, msg_rx_fifo
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 20 Oct 2014 11:19:34 +0000 (13:19 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 20 Oct 2014 11:19:34 +0000 (13:19 +0200)
avr/main.c
avr/z180-serv.c
avr/z80-if.c
include/common.h
include/z80-if.h
z180/Tupfile
z180/config.inc
z180/console.180
z180/msgfifo.180 [new file with mode: 0644]
z180/r3init.180

index ba8a6729c2612d01951c178aec27cde74d6721c3..2955630a2168f69cb88c1919914194f9c6069ad2 100644 (file)
@@ -61,6 +61,11 @@ void print_reset_reason(void)
 
 #endif
 
+ISR(INT5_vect)
+{
+       Stat |= S_MSG_PENDING;
+}
+
 static
 void setup_avr(void)
 {
@@ -99,6 +104,11 @@ void setup_avr(void)
        OCR3A = F_CPU / 1000 - 1;       /* Timer3: 1000Hz interval (OC3A) */
        TCCR3B = (0b01<<WGM32)|(0b001<<CS30); /* CTC Mode, Prescaler 1 */
        TIMSK3 = _BV(OCIE3A);           /* Enable TC2.oca interrupt */
+
+       /* INT5 falling edge */
+       EICRB = (EICRB & ~(0b11 << ISC50)) | 0b10 << ISC50;
+       /* Enable INT5 */
+       EIMSK |= _BV(INT5);
 }
 
 static
index 193b23f671d3f32bba36e587c00d2b5a5068b922..c9203263ff7c67b56e7bd30e465fb63d673224dd 100644 (file)
 
 /*--------------------------------------------------------------------------*/
 
-uint32_t z80_sram_cmp(uint32_t addr, uint32_t length, uint8_t wval, int inc)
-{
-       uint8_t rval;
-       int_fast8_t errors = 0;
-       
-       DBG_P(1, "SRAM: Check 0x%.5lx byte... ", length);
-       while (length--) {
-               if ((rval = z80_read(addr)) != wval) {
-                       if (errors == 0) { 
-                               DBG_P(1, "\nSRAM: Address   W    R\n" \
-                                        "      ------------------\n");
-                       }
-                       errors++;
-                       if (errors > 20) {
-                               DBG_P(1, "      ...\n");
-                               break;
-                       }
-                       DBG_P(1, "      0x%.5lx  0x%.2x 0x%.2x\n", addr, wval, rval);
-               }
-               addr++;
-               wval += inc;
-       }
-       DBG_P(1, "Done.\n");
-
-       return addr;
-}
-
-void z80_sram_fill(uint32_t addr, uint32_t length, uint8_t startval, int inc)
-{
-       printf("SRAM: Write 0x%.5lx byte... ", length);
-       while (length--) {
-               z80_write(addr, startval);
-               ++addr; 
-               startval += inc;
-       }
-       printf("Done.\n");
-}
-
-
-#if 0
-void z80_sram_fill_string(uint32_t addr, int length, const char *text)
-{
-       char c;
-       const char *p = text;
-
-       while (length--) {
-               z80_write(addr++, c = *p++);
-               if (c == 0)
-                       p = text;
-       }
-}
-
-
-uint32_t z80_sram_cmp_string(uint32_t addr, int length, const char *text)
-{
-       char c;
-       const char *p = text;
-
-       while (length--) {
-               c = *p++;
-               if (z80_read(addr) != c)
-                       break;
-               ++addr;
-               if (c == 0)
-                       p = text;
-       }
-       return addr;
-}
-
-const char * const qbfox = "Zhe quick brown fox jumps over the lazy dog!";
-const char * const qbcat = "Zhe quick brown fox jumps over the lazy cat!";
-
-#endif
 
 uint8_t z80_get_byte(uint32_t adr)
 {
index 3a2c18450cfaf2c7cf64526453c7b5bffddab891..d14d9d7ec3d18d57e0713cdc07241a1429885760 100644 (file)
@@ -518,7 +518,8 @@ int z80_memfifo_is_empty(const fifo_t f)
 {
        int rc = 1;
 
-       if (fifo_dsc[f].base != 0) {
+       if (((Stat & S_MSG_PENDING) || f != fifo_in) && fifo_dsc[f].base != 0)
+       {
 
                uint32_t adr = fifo_dsc[f].base + FIFO_INDEX_IN;
                uint8_t idx;
@@ -577,96 +578,3 @@ void z80_memfifo_putc(fifo_t f, uint8_t val)
        z80_write(fifo_dsc[f].base+FIFO_INDEX_IN, fifo_dsc[f].idx_in);
        z80_bus_cmd(Release);
 }
-
-/*--------------------------------------------------------------------------*/
-/*
-       TODO: Rewrite msg_fifo routines for AVR
-*/
-
-static struct {
-       uint32_t base;
-       //uint8_t  idx_out, idx_in;
-       uint16_t count;
-       uint8_t  buf[256];
-       } msg_fifo;
-
-/*--------------------------------------------------------------------------*/
-
-#if 0
-
-static void tim1_setup(void)
-{
-       RCC_APB2RSTR |= RCC_APB2RSTR_TIM1RST;
-       RCC_APB2RSTR &= ~RCC_APB2RSTR_TIM1RST;
-
-       TIM1_CR1 = 0;
-
-       TIM1_SMCR = 0
-       /*      | TIM_SMCR_ETP                  */
-       /*      | TIM_SMCR_ETF_CK_INT_N_2       */
-               | TIM_SMCR_TS_ETRF
-               | TIM_SMCR_SMS_OFF
-               ;
-
-       TIM1_DIER = TIM_DIER_TDE;
-
-
-       TIM1_CCMR1 = 0
-               | TIM_CCMR1_OC1M_FORCE_LOW
-               | TIM_CCMR1_CC1S_OUT;
-
-       TIM1_SMCR |= TIM_SMCR_SMS_TM;
-}
-
-#endif
-
-/*--------------------------------------------------------------------------*/
-
-void z80_setup_msg_fifo(void)
-{
-
-
-//     gpio_set_mode(P_BUSACK, GPIO_MODE_INPUT,
-//             GPIO_CNF_INPUT_FLOAT, GPIO_BUSACK | GPIO_IOCS1);
-
-//...
-
-//     msg_fifo.count = NELEMS(msg_fifo.buf);
-       msg_fifo.count = 0;
-       msg_fifo.base = 0;
-
-}
-
-
-void z80_init_msg_fifo(uint32_t addr)
-{
-
-DBG_P(1, "z80_init_msg_fifo: %lx\n", addr);
-
-       z80_bus_cmd(Request);
-       z80_write(addr+FIFO_INDEX_OUT, z80_read(addr+FIFO_INDEX_IN));
-       z80_bus_cmd(Release);
-       msg_fifo.base = addr;
-}
-
-
-int z80_msg_fifo_getc(void)
-{
-       int c = -1;
-
-#if 0
-       if (msg_fifo.count != (NELEMS(msg_fifo.buf) /*- DMA1_CNDTR4 */ )) {
-               c = msg_fifo.buf[msg_fifo.count];
-               if (++msg_fifo.count == NELEMS(msg_fifo.buf))
-                       msg_fifo.count = 0;
-
-               if (msg_fifo.base != 0) {
-                       z80_bus_cmd(Request);
-                       z80_write(msg_fifo.base+FIFO_INDEX_OUT, msg_fifo.count);
-                       z80_bus_cmd(Release);
-               }
-       }
-#endif
-
-       return c;
-}
index 90b02837bec55975261880ab8cd72e7a17231069..d054ad14720ff46cde1aeec6afb4f5aceefcfe70 100644 (file)
@@ -37,7 +37,7 @@ extern volatile uint_least8_t Stat;
 #endif /* __AVR__ */
 
 #define S_10MS_TO      (1<<0)
-#define S_Z180_RUNNING (2<<0)
+#define S_MSG_PENDING  (2<<0)
 
 static inline 
 void my_puts(const char *s)
index 6f6f6fadf77338bd6a3b4838d52d60200f1dd057..b4a4e6fdb9895ad468e6945e669f8ebe8d9b1831 100644 (file)
@@ -42,6 +42,3 @@ int z80_memfifo_is_full(const fifo_t f);
 uint8_t z80_memfifo_getc(const fifo_t f);
 void z80_memfifo_putc(fifo_t f, uint8_t val);
 
-void z80_setup_msg_fifo(void);
-void z80_init_msg_fifo(uint32_t addr);
-int z80_msg_fifo_getc(void);
index ebdb1d1fa1490de8239359bb1d5593107eec1c1e..fc926dee7a24b8272d150ae5857b7d510b6898cd 100644 (file)
@@ -5,7 +5,8 @@ PROG    = hdrom
 SRC    = r3init.180 
 SRC    += ddtz.180
 #SRC   += fifoio.180 msgbuf.180 ser1-i.180 console.180
-SRC    += ser1-i.180 console.180
+SRC    += msgfifo.180 ser1-i.180 console.180
+#SRC   += ser1-i.180 console.180
 SRC    += romend.180
 
 
index b5df1cc28eca8af6f8bd9af711794bb43ee3fe60..652b5ae2653a77f7159f9dd88adb212749816010 100644 (file)
@@ -41,17 +41,16 @@ CWAITROM    equ     2 shl MWI0
 DRSTNUM        equ     30h             ;DDTZ Restart vector (breakpoints)\r
 \r
 \r
-msg_fb_len     equ     256\r
-rx.buf_len     equ     20h\r
-tx.buf_len     equ     80h\r
-rx.buf_len     equ     20h\r
-tx.buf_len     equ     80h\r
+msg_rx_fifo_len        equ     256\r
+msg_tx_fifo_len        equ     256\r
 \r
 \r
 s1.rx_len      equ     256             ;Serial 1 (ASCI1) buffers\r
 s1.tx_len      equ     256             ;\r
 \r
-PMSG           equ     80h\r
+AVRINT5                equ     40h\r
+AVRINT6                equ     50h\r
+;PMSG          equ     80h\r
 \r
 ;-----------------------------------------------------\r
 ; Definition of (locical) top 2 memory pages\r
index d7b5ef68b44b79a6c2994e7250613bd39be6fdd2..9b0d5197b8dc2cbcc8be1e1015f88fe736334777 100644 (file)
@@ -8,8 +8,8 @@
 \r
 \r
        extrn   ser.init,ser.instat,ser.in,ser.out\r
-;      extrn   f.init,f.in,f.out,f.i.st\r
-;      extrn   msg.co\r
+       extrn   msginit,msg.in,msg.out,msgi.st\r
+       extrn   msg.co\r
        \r
 \r
        include config.inc\r
 ;\r
 \r
 $coninit:\r
-;      call    f.init\r
+       call    msginit\r
        call    ser.init\r
        ret\r
        \r
 $cists:\r
-;      call    f.i.st\r
-;      ret     nz\r
+       call    msgi.st\r
+       ret     nz\r
        call    ser.instat\r
        ret\r
        \r
 $ci:\r
-;      call    f.i.st\r
-;      jp      nz,f.in\r
+       call    msgi.st\r
+       jp      nz,msg.in\r
        call    ser.instat\r
        jp      nz,ser.in\r
        jr      $ci\r
@@ -41,7 +41,7 @@ $ci:
 ;      jp      f.o.st\r
        \r
 $co:\r
-;      call    msg.co\r
+       call    msg.co\r
        jp      ser.out\r
        \r
        end\r
diff --git a/z180/msgfifo.180 b/z180/msgfifo.180
new file mode 100644 (file)
index 0000000..582c219
--- /dev/null
@@ -0,0 +1,260 @@
+       page    255\r
+       .z80\r
+       \r
+       global  msg_rx_fifo,msg_tx_fifo\r
+\r
+       global  msginit,msgi.st,msg.in,msgo.st,msg.out\r
+       global  msg.sout,msg.co\r
+       \r
+       extrn   buf.init\r
+\r
+       include config.inc\r
+       include z180reg.inc\r
+\r
+;--------------------------------------------------------------\r
+\r
+       dseg\r
+\r
+       mkbuf   msg_rx_fifo,msg_rx_fifo_len\r
+       mkbuf   msg_tx_fifo,msg_tx_fifo_len\r
+\r
+\r
+\r
+;--------------------------------------------------------------\r
+\r
+       cseg\r
+\r
+;\r
+; Init buffer\r
+;\r
+       \r
+msginit:\r
+       ld      ix,msg_rx_fifo\r
+       ld      a,msg_rx_fifo.mask\r
+       call    buf.init\r
+       ld      ix,msg_tx_fifo\r
+       ld      a,msg_tx_fifo.mask\r
+       jp      buf.init\r
+\r
+;--------------------------------------------------------------\r
+\r
+msgi.st:\r
+       push    ix\r
+       ld      ix,msg_rx_fifo          ;\r
+\r
+buf.empty:\r
+       ld      a,(ix+o.in_idx)         ;\r
+       sub     (ix+o.out_idx)          ;\r
+       pop     ix\r
+       ret     z\r
+       or      0ffh\r
+       ret\r
+       \r
+;--------------------------------------------------------------\r
+\r
+msg.in:\r
+       push    ix\r
+       ld      ix,msg_rx_fifo          ;\r
+\r
+buf.get:\r
+       ld      a,(ix+o.out_idx)        ;\r
+bg.wait:\r
+       cp      (ix+o.in_idx)           ;\r
+       jr      z,bg.wait\r
+\r
+       push    hl                      ;\r
+       push    ix\r
+       pop     hl\r
+       add     a,l\r
+       ld      l,a\r
+       jr      nc,bg.nc\r
+       inc     h\r
+bg.nc:\r
+       ld      l,(hl)\r
+       \r
+       ld      a,(ix+o.out_idx)        ;\r
+       inc     a\r
+       and     (ix+o.mask)\r
+       ld      (ix+o.out_idx),a\r
+       \r
+       ld      a,l\r
+       pop     hl\r
+       pop     ix\r
+       ret\r
+\r
+;--------------------------------------------------------------\r
+\r
+msgo.st:\r
+       push    ix\r
+       ld      ix,msg_tx_fifo          ;\r
+\r
+buf.full:\r
+       ld      a,(ix+o.in_idx)         ;\r
+       inc     a\r
+       and     (ix+o.mask)\r
+       sub     (ix+o.out_idx)          ;\r
+       pop     ix\r
+       ret     z\r
+       or      0ffh\r
+       ret\r
+\r
+;--------------------------------------------------------------\r
+\r
+msg.out:\r
+       push    ix\r
+       ld      ix,msg_tx_fifo          ;\r
+\r
+buf.put:\r
+       push    hl                      ;\r
+       push    bc\r
+       push    ix\r
+       pop     hl\r
+       ld      c,(ix+o.in_idx)         ;\r
+       ld      b,0\r
+       add     hl,bc\r
+       ld      b,a\r
+\r
+       ld      a,c                     ;\r
+       inc     a\r
+       and     (ix+o.mask)\r
+bp.wait:\r
+       cp      (ix+o.out_idx)          ;\r
+       jr      z,bp.wait\r
+       ld      (hl),b\r
+       ld      (ix+o.in_idx),a\r
+       \r
+       ld      a,b\r
+       out0    (AVRINT5),a\r
+       pop     bc\r
+       pop     hl\r
+       pop     ix\r
+       ret\r
+\r
+\r
+;--------------------------------------------------------------\r
+;--------------------------------------------------------------\r
+;--------------------------------------------------------------\r
+\r
+if 0\r
+msg.out:\r
+       push    ix\r
+       ld      ix,msg_fifo             ;\r
+\r
+       push    bc\r
+       ld      b,a                     ;save char\r
+       ld      a,(ix+o.in_idx)         ;\r
+       inc     a\r
+       and     (ix+o.mask)\r
+bp.wait:\r
+       cp      (ix+o.out_idx)          ;\r
+       jr      z,bp.wait\r
+       ld      c,a\r
+       ld      a,b\r
+       out     (PMSG),a\r
+       ld      (ix+o.in_idx),c\r
+       \r
+       pop     bc\r
+       pop     ix\r
+       ret\r
+endif\r
+\r
+;--------------------------------------------------------------\r
+;\r
+; (hl): data\r
+\r
+msg.sout:\r
+       push    ix\r
+       ld      ix,msg_tx_fifo          ;\r
+\r
+       push    bc\r
+       push    de\r
+       ld      b,(hl)                  ;\r
+       inc     hl\r
+       ex      de,hl\r
+       \r
+ms.ol:\r
+       push    ix\r
+       pop     hl\r
+       ld      c,(ix+o.in_idx)         ;\r
+       ld      a,c\r
+       add     l\r
+       ld      l,a\r
+       jr      nc,ms.on\r
+       inc     h\r
+ms.on:\r
+       ld      a,c                     ;\r
+       inc     a\r
+       and     (ix+o.mask)\r
+ms.wait:\r
+       cp      (ix+o.out_idx)          ;\r
+       jr      z,ms.wait\r
+       ld      c,a\r
+       ld      a,(de)\r
+       inc     de\r
+       ld      (hl),a\r
+       ld      (ix+o.in_idx),c\r
+       djnz    ms.ol\r
+       out0    (AVRINT5),a\r
+       ex      de,hl\r
+       pop     de\r
+       pop     bc\r
+       pop     ix\r
+       ret\r
+\r
+;--------------------------------------------------------------\r
+\r
+if 0\r
+msg.sout:\r
+       push    ix\r
+       ld      ix,msg_fifo             ;\r
+       push    bc\r
+\r
+       ld      b,(hl)                  ;count\r
+       inc     hl\r
+obs_1:\r
+       ld      a,(ix+o.out_idx)        ;\r
+       sub     (ix+o.in_idx)           ;\r
+       dec     a\r
+       and     (ix+o.mask)\r
+       cp      b\r
+       jr      c,obs_1\r
+\r
+       ld      c,(hl)                  ;port address\r
+       inc     hl\r
+       ld      a,b\r
+       otir\r
+       add     (ix+o.in_idx)\r
+       and     (ix+o.mask)\r
+       ld      (ix+o.in_idx),a\r
+       pop     bc\r
+       pop     ix\r
+       ret\r
+\r
+;----------------------------------------------------------------------\r
+endif\r
+\r
+msg.co:\r
+       push    af\r
+       push    hl\r
+       ld      (buf_char),a\r
+       ld      hl,buf\r
+       call    msg.sout\r
+       pop     hl\r
+       pop     af\r
+       ret\r
+       \r
+       \r
+buf:\r
+       db      buf_end - $ - 1         ;output string length\r
+       db      081h                    ; message start token\r
+       db      buf_end - $ - 1         ; message length\r
+       db      1                       ; command\r
+       db      1                       ; subcommand\r
+buf_char:\r
+       db      0                       ; pay load\r
+buf_end:\r
+\r
+;----------------------------------------------------------------------\r
+\r
+       end\r
+\r
index 0d3e5be4613ba210ffadcdf29ef826a0edaf67b8..1936c9be0bd5de4704823fcceff31871d69f3c2c 100644 (file)
@@ -94,8 +94,8 @@ start:
 \r
        ld      a,M_NCD         ;No Clock Divide\r
        out0    (ccr),a\r
-       ld      a,M_X2CM        ;X2 Clock Multiplier\r
-       out0    (cmr),a\r
+;      ld      a,M_X2CM        ;X2 Clock Multiplier\r
+;      out0    (cmr),a\r
 \r
 ; search warm start mark\r
 \r
@@ -280,12 +280,9 @@ wstart:
 \r
        call    prt0_init\r
 \r
-\r
-;;;    call    bufferinit\r
-\r
-\r
        call    $coninit\r
 \r
+       call    bufferinit\r
 \r
 \r
 \r
@@ -301,7 +298,6 @@ wstart:
        ld e,a                  ;\r
        jp ddtz                 ;0290\r
 \r
-\r
 ;\r
 ;----------------------------------------------------------------------\r
 ;\r
@@ -317,56 +313,48 @@ buf.init:
        ret\r
 \r
 ;----------------------------------------------------------------------\r
-if 0\r
-       extrn   msginit,msg.sout,msg_fifo\r
-       extrn   tx.buf,rx.buf\r
 \r
+       extrn   msginit,msg_tx_fifo,msg_rx_fifo\r
+       extrn   msg.sout\r
 \r
 bufferinit:\r
-       call     msginit\r
 \r
-       ld      hl,buffers\r
-       ld      bc,0300h\r
-bfi_1:\r
-       ld      e,(hl)\r
-       inc     hl\r
-       ld      d,(hl)\r
-       inc     hl\r
-       push    hl\r
+       ld      de,msg_tx_fifo\r
        in0     a,cbr\r
        call    log2phys\r
        ld      (40h+0),hl\r
        ld      (40h+2),a\r
-       ld      a,c\r
+\r
+       ld      (bufdat+1),hl\r
+       ld      (bufdat+3),a\r
+       xor     a\r
        ld      (bufdat+0),a\r
        ld      hl,inimsg\r
        call    msg.sout\r
-       pop     hl\r
-       inc     c\r
-       djnz    bfi_1\r
-       ret\r
 \r
-       rept    20\r
-       db      0\r
-       endm\r
+       ld      de,msg_rx_fifo\r
+       in0     a,cbr\r
+       call    log2phys\r
+       ld      (bufdat+1),hl\r
+       ld      (bufdat+3),a\r
+       ld      a,1\r
+       ld      (bufdat+0),a\r
+       ld      hl,inimsg\r
+       call    msg.sout\r
 \r
-buffers:\r
-       dw      msg_fifo\r
-       dw      tx.buf\r
-       dw      rx.buf\r
+       ret\r
 \r
 inimsg:\r
-       db      inimsg_e - $ -2\r
-       db      PMSG\r
+       db      inimsg_e - $ - 1\r
        db      81h\r
-       db      inimsg_e - $ -1\r
+       db      inimsg_e - $ - 1\r
        db      0\r
 bufdat:\r
        db      0\r
        dw      0\r
        db      0\r
 inimsg_e:\r
-endif\r
+\r
 ;----------------------------------------------------------------------\r
 ;\r
 if 0\r
@@ -379,7 +367,7 @@ bufferinit:
        call     msginit\r
 \r
        ld      hl,buffers\r
-       ld      bc,0300h\r
+       ld      bc,0300h        ; b:count, c:buffer nr\r
 bfi_1:\r
        ld      e,(hl)\r
        inc     hl\r