diff options
-rw-r--r-- | avr/main.c | 10 | ||||
-rw-r--r-- | avr/z180-serv.c | 73 | ||||
-rw-r--r-- | avr/z80-if.c | 96 | ||||
-rw-r--r-- | include/common.h | 2 | ||||
-rw-r--r-- | include/z80-if.h | 3 | ||||
-rw-r--r-- | z180/Tupfile | 3 | ||||
-rw-r--r-- | z180/config.inc | 11 | ||||
-rw-r--r-- | z180/console.180 | 16 | ||||
-rw-r--r-- | z180/msgfifo.180 | 260 | ||||
-rw-r--r-- | z180/r3init.180 | 60 |
10 files changed, 312 insertions, 222 deletions
@@ -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 diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 193b23f..c920326 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -17,79 +17,6 @@ /*--------------------------------------------------------------------------*/ -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) { diff --git a/avr/z80-if.c b/avr/z80-if.c index 3a2c184..d14d9d7 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -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; -} diff --git a/include/common.h b/include/common.h index 90b0283..d054ad1 100644 --- a/include/common.h +++ b/include/common.h @@ -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) diff --git a/include/z80-if.h b/include/z80-if.h index 6f6f6fa..b4a4e6f 100644 --- a/include/z80-if.h +++ b/include/z80-if.h @@ -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); diff --git a/z180/Tupfile b/z180/Tupfile index ebdb1d1..fc926de 100644 --- a/z180/Tupfile +++ b/z180/Tupfile @@ -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 diff --git a/z180/config.inc b/z180/config.inc index b5df1cc..652b5ae 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -41,17 +41,16 @@ CWAITROM equ 2 shl MWI0 DRSTNUM equ 30h ;DDTZ Restart vector (breakpoints)
-msg_fb_len equ 256
-rx.buf_len equ 20h
-tx.buf_len equ 80h
-rx.buf_len equ 20h
-tx.buf_len equ 80h
+msg_rx_fifo_len equ 256
+msg_tx_fifo_len equ 256
s1.rx_len equ 256 ;Serial 1 (ASCI1) buffers
s1.tx_len equ 256 ;
-PMSG equ 80h
+AVRINT5 equ 40h
+AVRINT6 equ 50h
+;PMSG equ 80h
;-----------------------------------------------------
; Definition of (locical) top 2 memory pages
diff --git a/z180/console.180 b/z180/console.180 index d7b5ef6..9b0d519 100644 --- a/z180/console.180 +++ b/z180/console.180 @@ -8,8 +8,8 @@ extrn ser.init,ser.instat,ser.in,ser.out
-; extrn f.init,f.in,f.out,f.i.st
-; extrn msg.co
+ extrn msginit,msg.in,msg.out,msgi.st
+ extrn msg.co
include config.inc
@@ -20,19 +20,19 @@ ;
$coninit:
-; call f.init
+ call msginit
call ser.init
ret
$cists:
-; call f.i.st
-; ret nz
+ call msgi.st
+ ret nz
call ser.instat
ret
$ci:
-; call f.i.st
-; jp nz,f.in
+ call msgi.st
+ jp nz,msg.in
call ser.instat
jp nz,ser.in
jr $ci
@@ -41,7 +41,7 @@ $ci: ; jp f.o.st
$co:
-; call msg.co
+ call msg.co
jp ser.out
end
diff --git a/z180/msgfifo.180 b/z180/msgfifo.180 new file mode 100644 index 0000000..582c219 --- /dev/null +++ b/z180/msgfifo.180 @@ -0,0 +1,260 @@ + page 255
+ .z80
+
+ global msg_rx_fifo,msg_tx_fifo
+
+ global msginit,msgi.st,msg.in,msgo.st,msg.out
+ global msg.sout,msg.co
+
+ extrn buf.init
+
+ include config.inc
+ include z180reg.inc
+
+;--------------------------------------------------------------
+
+ dseg
+
+ mkbuf msg_rx_fifo,msg_rx_fifo_len
+ mkbuf msg_tx_fifo,msg_tx_fifo_len
+
+
+
+;--------------------------------------------------------------
+
+ cseg
+
+;
+; Init buffer
+;
+
+msginit:
+ ld ix,msg_rx_fifo
+ ld a,msg_rx_fifo.mask
+ call buf.init
+ ld ix,msg_tx_fifo
+ ld a,msg_tx_fifo.mask
+ jp buf.init
+
+;--------------------------------------------------------------
+
+msgi.st:
+ push ix
+ ld ix,msg_rx_fifo ;
+
+buf.empty:
+ ld a,(ix+o.in_idx) ;
+ sub (ix+o.out_idx) ;
+ pop ix
+ ret z
+ or 0ffh
+ ret
+
+;--------------------------------------------------------------
+
+msg.in:
+ push ix
+ ld ix,msg_rx_fifo ;
+
+buf.get:
+ ld a,(ix+o.out_idx) ;
+bg.wait:
+ cp (ix+o.in_idx) ;
+ jr z,bg.wait
+
+ push hl ;
+ push ix
+ pop hl
+ add a,l
+ ld l,a
+ jr nc,bg.nc
+ inc h
+bg.nc:
+ ld l,(hl)
+
+ ld a,(ix+o.out_idx) ;
+ inc a
+ and (ix+o.mask)
+ ld (ix+o.out_idx),a
+
+ ld a,l
+ pop hl
+ pop ix
+ ret
+
+;--------------------------------------------------------------
+
+msgo.st:
+ push ix
+ ld ix,msg_tx_fifo ;
+
+buf.full:
+ ld a,(ix+o.in_idx) ;
+ inc a
+ and (ix+o.mask)
+ sub (ix+o.out_idx) ;
+ pop ix
+ ret z
+ or 0ffh
+ ret
+
+;--------------------------------------------------------------
+
+msg.out:
+ push ix
+ ld ix,msg_tx_fifo ;
+
+buf.put:
+ push hl ;
+ push bc
+ push ix
+ pop hl
+ ld c,(ix+o.in_idx) ;
+ ld b,0
+ add hl,bc
+ ld b,a
+
+ ld a,c ;
+ inc a
+ and (ix+o.mask)
+bp.wait:
+ cp (ix+o.out_idx) ;
+ jr z,bp.wait
+ ld (hl),b
+ ld (ix+o.in_idx),a
+
+ ld a,b
+ out0 (AVRINT5),a
+ pop bc
+ pop hl
+ pop ix
+ ret
+
+
+;--------------------------------------------------------------
+;--------------------------------------------------------------
+;--------------------------------------------------------------
+
+if 0
+msg.out:
+ push ix
+ ld ix,msg_fifo ;
+
+ push bc
+ ld b,a ;save char
+ ld a,(ix+o.in_idx) ;
+ inc a
+ and (ix+o.mask)
+bp.wait:
+ cp (ix+o.out_idx) ;
+ jr z,bp.wait
+ ld c,a
+ ld a,b
+ out (PMSG),a
+ ld (ix+o.in_idx),c
+
+ pop bc
+ pop ix
+ ret
+endif
+
+;--------------------------------------------------------------
+;
+; (hl): data
+
+msg.sout:
+ push ix
+ ld ix,msg_tx_fifo ;
+
+ push bc
+ push de
+ ld b,(hl) ;
+ inc hl
+ ex de,hl
+
+ms.ol:
+ push ix
+ pop hl
+ ld c,(ix+o.in_idx) ;
+ ld a,c
+ add l
+ ld l,a
+ jr nc,ms.on
+ inc h
+ms.on:
+ ld a,c ;
+ inc a
+ and (ix+o.mask)
+ms.wait:
+ cp (ix+o.out_idx) ;
+ jr z,ms.wait
+ ld c,a
+ ld a,(de)
+ inc de
+ ld (hl),a
+ ld (ix+o.in_idx),c
+ djnz ms.ol
+ out0 (AVRINT5),a
+ ex de,hl
+ pop de
+ pop bc
+ pop ix
+ ret
+
+;--------------------------------------------------------------
+
+if 0
+msg.sout:
+ push ix
+ ld ix,msg_fifo ;
+ push bc
+
+ ld b,(hl) ;count
+ inc hl
+obs_1:
+ ld a,(ix+o.out_idx) ;
+ sub (ix+o.in_idx) ;
+ dec a
+ and (ix+o.mask)
+ cp b
+ jr c,obs_1
+
+ ld c,(hl) ;port address
+ inc hl
+ ld a,b
+ otir
+ add (ix+o.in_idx)
+ and (ix+o.mask)
+ ld (ix+o.in_idx),a
+ pop bc
+ pop ix
+ ret
+
+;----------------------------------------------------------------------
+endif
+
+msg.co:
+ push af
+ push hl
+ ld (buf_char),a
+ ld hl,buf
+ call msg.sout
+ pop hl
+ pop af
+ ret
+
+
+buf:
+ db buf_end - $ - 1 ;output string length
+ db 081h ; message start token
+ db buf_end - $ - 1 ; message length
+ db 1 ; command
+ db 1 ; subcommand
+buf_char:
+ db 0 ; pay load
+buf_end:
+
+;----------------------------------------------------------------------
+
+ end
+
diff --git a/z180/r3init.180 b/z180/r3init.180 index 0d3e5be..1936c9b 100644 --- a/z180/r3init.180 +++ b/z180/r3init.180 @@ -94,8 +94,8 @@ start: ld a,M_NCD ;No Clock Divide
out0 (ccr),a
- ld a,M_X2CM ;X2 Clock Multiplier
- out0 (cmr),a
+; ld a,M_X2CM ;X2 Clock Multiplier
+; out0 (cmr),a
; search warm start mark
@@ -280,12 +280,9 @@ wstart: call prt0_init
-
-;;; call bufferinit
-
-
call $coninit
+ call bufferinit
@@ -301,7 +298,6 @@ wstart: ld e,a ;
jp ddtz ;0290
-
;
;----------------------------------------------------------------------
;
@@ -317,56 +313,48 @@ buf.init: ret
;----------------------------------------------------------------------
-if 0
- extrn msginit,msg.sout,msg_fifo
- extrn tx.buf,rx.buf
+ extrn msginit,msg_tx_fifo,msg_rx_fifo
+ extrn msg.sout
bufferinit:
- call msginit
- ld hl,buffers
- ld bc,0300h
-bfi_1:
- ld e,(hl)
- inc hl
- ld d,(hl)
- inc hl
- push hl
+ ld de,msg_tx_fifo
in0 a,cbr
call log2phys
ld (40h+0),hl
ld (40h+2),a
- ld a,c
+
+ ld (bufdat+1),hl
+ ld (bufdat+3),a
+ xor a
ld (bufdat+0),a
ld hl,inimsg
call msg.sout
- pop hl
- inc c
- djnz bfi_1
- ret
- rept 20
- db 0
- endm
+ ld de,msg_rx_fifo
+ in0 a,cbr
+ call log2phys
+ ld (bufdat+1),hl
+ ld (bufdat+3),a
+ ld a,1
+ ld (bufdat+0),a
+ ld hl,inimsg
+ call msg.sout
-buffers:
- dw msg_fifo
- dw tx.buf
- dw rx.buf
+ ret
inimsg:
- db inimsg_e - $ -2
- db PMSG
+ db inimsg_e - $ - 1
db 81h
- db inimsg_e - $ -1
+ db inimsg_e - $ - 1
db 0
bufdat:
db 0
dw 0
db 0
inimsg_e:
-endif
+
;----------------------------------------------------------------------
;
if 0
@@ -379,7 +367,7 @@ bufferinit: call msginit
ld hl,buffers
- ld bc,0300h
+ ld bc,0300h ; b:count, c:buffer nr
bfi_1:
ld e,(hl)
inc hl
|