From 64cc220767e870fad388fb9021cf96ff2958275b Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 1 May 2015 23:19:32 +0200 Subject: Simplify Console I/O. Switch back to IOBYTE. --- z180/conbuf-a.180 | 85 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 25 deletions(-) (limited to 'z180/conbuf-a.180') diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index 8534f73..096bbf9 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -9,7 +9,9 @@ extrn buf.init include config.inc + if CPU_Z180 include z180reg.inc + endif ;-------------------------------------------------------------- @@ -96,36 +98,69 @@ buf.full: ret + if 1 ff.out: - push ix - ld ix,co.fifo ; + push ix ;15 + ld ix,co.fifo ;14 buf.put: - push hl ; - push bc - push ix - pop hl - ld a,c - ld c,(ix+o.in_idx) ; - ld b,0 - add hl,bc - ld b,a - - ld a,c ; - inc a - and (ix+o.mask) + push hl ;11 + push bc ;11 + push ix ;15 + pop hl ;10 + ld a,c ;4 + ld c,(ix+o.in_idx) ;19 + ld b,0 ;7 + add hl,bc ;11 + ld (hl),a ;7 + ld b,a ;4 + + ld a,c ;4 + inc a ;4 + and (ix+o.mask) ;19 bp.wait: - cp (ix+o.out_idx) ; - jr z,bp.wait - ld (hl),b - ld (ix+o.in_idx),a + cp (ix+o.out_idx) ;19 + jr z,bp.wait ;12/7 + ld (ix+o.in_idx),a ;19 - out (AVRINT6),a - ld a,b - pop bc - pop hl - pop ix - ret + out (AVRINT6),a ;11 + ld a,b ;4 + pop bc ;10 + pop hl ;10 + pop ix ;14 + ret ;10 + + else + +ff.out: + push ix ;15 + ld ix,co.fifo ;14 + +buf.put: + push hl ;11 + push ix ;15 + pop hl ;10 + ld a,(ix+o.in_idx) ;19 + add a,l ;4 + ld l,a ;4 + jr nc,bp.1 ;12/7 + inc l ;4 + ld (hl),c ;7 + ld a,(ix+o.in_idx) ;19 + inc a ;4 + and (ix+o.mask) ;19 +bp.wait: + cp (ix+o.out_idx) ;19 + jr z,bp.wait ;12/7 + ld (ix+o.in_idx),a ;19 + + out (AVRINT6),a ;11 + ld a,c ;4 + pop hl ;10 + pop ix ;14 + ret ;10 | + + endif end -- cgit v1.2.3 From e4c4b148ced1347935dff6200380e90cb3bfcde3 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sun, 10 May 2015 12:54:12 +0200 Subject: Add unique id to fifos --- z180/asci1-i.180 | 42 ++++++++++++++++++++---------------------- z180/chario.180 | 7 +++---- z180/conbuf-a.180 | 17 ++++++++--------- z180/config.inc | 31 ++++++++++++++++++++----------- z180/fifoio.180 | 17 ++++++++--------- z180/msgbuf-a.180 | 4 ++-- z180/msgfifo.180 | 27 +++++++++++++-------------- 7 files changed, 74 insertions(+), 71 deletions(-) (limited to 'z180/conbuf-a.180') diff --git a/z180/asci1-i.180 b/z180/asci1-i.180 index 2410e38..15e121a 100644 --- a/z180/asci1-i.180 +++ b/z180/asci1-i.180 @@ -4,12 +4,12 @@ extrn buf.init extrn isv_sw - + global ser.init global ser.ist,ser.in global ser.ost,ser.out -;TODO: define a trampoline area somewhere in top ram. +;TODO: define a trampoline area somewhere in top ram. rtxisvjmp equ 0FF60h ;momentan frei... include config.inc @@ -19,10 +19,10 @@ rtxisvjmp equ 0FF60h ;momentan frei... ;----------------------------------------------------- dseg - + buf_start: - mkbuf ser1.inbuf,s1.rx_len - mkbuf ser1.outbuf,s1.tx_len + mkbuf s1.rx_id, ser1.inbuf, s1.rx_len + mkbuf s1.tx_id, ser1.outbuf, s1.tx_len buf_end: @@ -33,7 +33,7 @@ buf_end: ; ; Init Serial I/O for console input and output (ASCI1) ; - + ser.init: ; ld a,i @@ -42,10 +42,10 @@ ser.init: xor a ; out0 (stat1),a ;Disable rx/tx interrupts - + ld hl,rxtx_src ;move rx and tx isv to common ram ld de,rxtx_dst ; - ld bc,rxtx_src_e-rxtx_src ; + ld bc,rxtx_src_e-rxtx_src ; ldir ; ld hl,rtxisvjmp ;rx/tx int vector @@ -59,7 +59,7 @@ ser.init: ; ASCI1: 8N1, highest baudrate (56700), CTS disabled - ld a,M_MPBT + ld a,M_MPBT out0 (cntlb1),a ld a,M_RE + M_TE + M_MOD2 out0 (cntla1),a @@ -89,21 +89,21 @@ buf.empty: ret z or 0ffh ret - + ser.in: - push hl ;11 + push hl ;11 push de ;11 - ld hl,ser1.inbuf-1 ; 9 hl = &rx.out_idx + ld hl,ser1.inbuf-1 ; 9 hl = &rx.out_idx ld a,(hl) ; 6 a = rx.out_idx dec hl ; 4 hl = &rx.in_idx jr bg.w1 bg.wait: halt bg.w1: - cp (hl) ; 6 while (out_idx==in_idx) + cp (hl) ; 6 while (out_idx==in_idx) jr z,bg.wait ; 6 (/8) ; - ld e,a ; 4 + ld e,a ; 4 ld d,0 ; 6 inc de inc de @@ -111,20 +111,20 @@ bg.w1: ex de,hl ; 3 add hl,de ;10 ld l,(hl) ; 6 - ex de,hl ; 3 + ex de,hl ; 3 inc a ; 4 dec hl ; 4 - and (hl) ; 6 + and (hl) ; 6 inc hl ; 4 inc hl ; 4 ld (hl),a ; 7 - + ld a,e ; 4 pop de ; 9 pop hl ; 9 ret ; 9 - ; 153 + ; 153 ser.ost: push ix @@ -191,7 +191,7 @@ rxtxisv: in0 d,(rdr1) ;todo: break detection bit FE,a ;framing error? jr nz,??ri_1 - + push ix ld ix,ser1.inbuf ; ld hl,ser1.inbuf ; @@ -233,7 +233,7 @@ txisv: ??ti_1: ld l,(hl) out0 (tdr1),l ;071b - + ld a,(ix+o.out_idx) ; inc a and (ix+o.mask) @@ -254,5 +254,3 @@ rxtx_src_e: end - - diff --git a/z180/chario.180 b/z180/chario.180 index 8313658..4d37b89 100644 --- a/z180/chario.180 +++ b/z180/chario.180 @@ -2,7 +2,7 @@ .z80 -; CP/M 3 compatible character i/o +; CP/M 3 compatible character i/o public ?cinit,?ci,?co,?cist,?cost public @ctbl @@ -10,7 +10,7 @@ extrn ff.init,ff.i.st,ff.in,ff.o.st,ff.out extrn as0init,as0ista,as0inp,as0osta,as0out extrn as1init,as1ista,as1inp,as1osta,as1out - + include config.inc include z180reg.inc include modebaud.inc ; define mode bits and baud eqautes @@ -98,7 +98,7 @@ null$status: db mb$in$out db baud$none - db 'ASCI1 ' ; device 1 + db 'ASCI0 ' ; device 1 db mb$in$out+mb$serial+mb$soft$baud ser0$baud: db baud$19200 @@ -111,4 +111,3 @@ ser1$baud: db 0 ; table terminator end - diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index 096bbf9..e86b8b2 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -1,6 +1,6 @@ page 255 .z80 - + ; ; FIFO channels for communication with avr ; @@ -17,10 +17,10 @@ ;-------------------------------------------------------------- dseg - - mkbuf co.fifo,co.fifo_len - mkbuf ci.fifo,ci.fifo_len + + mkbuf co.fifo_id, co.fifo, co.fifo_len + mkbuf ci.fifo_id, ci.fifo, ci.fifo_len ;-------------------------------------------------------------- @@ -50,7 +50,7 @@ buf.empty: ret z or 0ffh ret - + ff.in: push ix @@ -71,12 +71,12 @@ bg.wait: 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 @@ -122,7 +122,7 @@ bp.wait: cp (ix+o.out_idx) ;19 jr z,bp.wait ;12/7 ld (ix+o.in_idx),a ;19 - + out (AVRINT6),a ;11 ld a,b ;4 pop bc ;10 @@ -163,4 +163,3 @@ bp.wait: endif end - diff --git a/z180/config.inc b/z180/config.inc index 33152de..0c945ae 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -47,8 +47,8 @@ CA equ 10h - CSK ;common area start BA equ 0 ;banked area start SYS$CBR equ 0 -SYS$CBAR equ CA<<4 + CA ;CBAR in system mode -USR$CBAR equ CA<<4 + BA ;CBAR in user mode (CP/M) +SYS$CBAR equ CA*16 + CA ;CBAR in system mode +USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M) BANKS equ 18 ;max nr. of banks @@ -57,6 +57,7 @@ BANKS equ 18 ;max nr. of banks CREFSH equ 0 ;Refresh rate register (disable refresh) CWAITIO equ 3 shl IWI0 ;Max I/O Wait States, 0 Memory Wait States +PHI_X2 equ 0 ;set to M_X2CM to enable the clock doubler endif ;CPU_Z180 if CPU_Z80 @@ -108,14 +109,20 @@ CWAITROM equ 2 shl MWI0 DRSTNUM equ 30h ;DDTZ Restart vector (breakpoints) -mrx.fifo_len equ 256 -mtx.fifo_len equ 256 +mtx.fifo_len equ 32 ;Message transfer fifos +mtx.fifo_id equ 0 ; This *must* have #0 +mrx.fifo_len equ 32 +mrx.fifo_id equ 1 -ci.fifo_len equ 128 -co.fifo_len equ 256 +ci.fifo_len equ 32 ;AVRCON Character I/O via AVR +ci.fifo_id equ 2 +co.fifo_len equ 32 +co.fifo_id equ 3 -s1.rx_len equ 256 ;Serial 1 (ASCI1) buffers -s1.tx_len equ 256 ; +s1.rx_len equ 128 ;Serial 1 (ASCI1) buffers +s1.rx_id equ 4 ; +s1.tx_len equ 128 ; +s1.tx_id equ 5 ; AVRINT5 equ 4Fh AVRINT6 equ 5Fh @@ -136,24 +143,26 @@ iv2tab equ ivtab + 2*9 ;----------------------------------------------------- - +o.id equ -4 o.mask equ -3 o.in_idx equ -2 o.out_idx equ -1 .lall -mkbuf macro name,size - if ((size & (size-1)) ne 0) or (size gt 256) +mkbuf macro id,name,size + if ((size AND (size-1)) NE 0) OR (size GT 256) .printx Error: buffer ^size must be power of 2 and in range 0..256! name&.mask equ ;wrong size error else + db id ds 3 name:: ds size name&.mask equ low (size-1) if size ne 0 name&.end equ $-1 name&.len equ size + name&.id equ id endif endif endm diff --git a/z180/fifoio.180 b/z180/fifoio.180 index dd99c53..cbcece9 100644 --- a/z180/fifoio.180 +++ b/z180/fifoio.180 @@ -1,6 +1,6 @@ page 255 .z80 - + ; ; FIFO channels for communication with stm32 ; @@ -15,10 +15,10 @@ ;-------------------------------------------------------------- dseg - - mkbuf rx.buf,rx.buf_len - mkbuf tx.buf,tx.buf_len + + mkbuf ci.fifo_id, rx.buf,rx.buf_len + mkbuf co.fifo_id, tx.buf,tx.buf_len ;-------------------------------------------------------------- @@ -48,7 +48,7 @@ buf.empty: ret z or 0ffh ret - + f.in: push ix @@ -69,12 +69,12 @@ bg.wait: 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 @@ -118,7 +118,7 @@ bp.wait: jr z,bp.wait ld (hl),b ld (ix+o.in_idx),a - + ld a,b pop bc pop hl @@ -126,4 +126,3 @@ bp.wait: ret end - diff --git a/z180/msgbuf-a.180 b/z180/msgbuf-a.180 index ddb2d93..ff2a657 100644 --- a/z180/msgbuf-a.180 +++ b/z180/msgbuf-a.180 @@ -17,8 +17,8 @@ dseg - mkbuf mrx.fifo,mrx.fifo_len - mkbuf mtx.fifo,mtx.fifo_len + mkbuf mtx.fifo_id, mtx.fifo, mtx.fifo_len + mkbuf mrx.fifo_id, mrx.fifo, mrx.fifo_len ;-------------------------------------------------------------- diff --git a/z180/msgfifo.180 b/z180/msgfifo.180 index 582c219..cf1ae2a 100644 --- a/z180/msgfifo.180 +++ b/z180/msgfifo.180 @@ -1,11 +1,11 @@ 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 @@ -15,8 +15,8 @@ dseg - mkbuf msg_rx_fifo,msg_rx_fifo_len - mkbuf msg_tx_fifo,msg_tx_fifo_len + mkbuf mtx.fifo_id, msg_tx_fifo, msg_tx_fifo_len + mkbuf mrx.fifo_id, msg_rx_fifo, msg_rx_fifo_len @@ -27,7 +27,7 @@ ; ; Init buffer ; - + msginit: ld ix,msg_rx_fifo ld a,msg_rx_fifo.mask @@ -49,7 +49,7 @@ buf.empty: ret z or 0ffh ret - + ;-------------------------------------------------------------- msg.in: @@ -71,12 +71,12 @@ bg.wait: 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 @@ -122,7 +122,7 @@ bp.wait: jr z,bp.wait ld (hl),b ld (ix+o.in_idx),a - + ld a,b out0 (AVRINT5),a pop bc @@ -152,7 +152,7 @@ bp.wait: ld a,b out (PMSG),a ld (ix+o.in_idx),c - + pop bc pop ix ret @@ -171,7 +171,7 @@ msg.sout: ld b,(hl) ; inc hl ex de,hl - + ms.ol: push ix pop hl @@ -242,8 +242,8 @@ msg.co: pop hl pop af ret - - + + buf: db buf_end - $ - 1 ;output string length db 081h ; message start token @@ -257,4 +257,3 @@ buf_end: ;---------------------------------------------------------------------- end - -- cgit v1.2.3 From ad9bc17c8ecab1f0bbd26f2270d4d396f4bc5e52 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Jun 2015 23:29:55 +0200 Subject: switch fifos conin,conout --- avr/cmd_loadcpm3.c | 1 + avr/cmd_mem.c | 4 +-- avr/command_tbl.c | 12 ++++++++ avr/debug.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++---- avr/z180-serv.c | 3 ++ include/z80-if.h | 2 +- z180/conbuf-a.180 | 2 +- z180/config.inc | 9 +++++- z180/ddtz.180 | 19 +++++++----- z180/init.180 | 4 +-- 10 files changed, 125 insertions(+), 19 deletions(-) (limited to 'z180/conbuf-a.180') diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c index fd685b2..3f1bbe1 100644 --- a/avr/cmd_loadcpm3.c +++ b/avr/cmd_loadcpm3.c @@ -55,6 +55,7 @@ int load(FIL *File, uint16_t addr, uint8_t len) return 0; } +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index 53b1842..101b912 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -152,8 +152,8 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) if (incrflag) addr += nbytes ? -1 : 1; nbytes = 1; - } - else { + + } else { char *endp; data = strtoul(console_buffer, &endp, 16); nbytes = endp - console_buffer; diff --git a/avr/command_tbl.c b/avr/command_tbl.c index eb0d84f..a9cc2bd 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -25,6 +25,8 @@ extern command_ret_t do_go(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_restart(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_console(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_dump_mem(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_mm_avr(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_nm_avr(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_eep_cp(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_busreq_pulse(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_date(cmd_tbl_t *, int, int, char * const []); @@ -75,6 +77,16 @@ CMD_TBL_ITEM( "EEPROM copy", "source target count" ), +CMD_TBL_ITEM( + !mm, 2, 1, do_mem_mm_avr, + "avr memory modify (auto-incrementing address)", + "address" +), +CMD_TBL_ITEM( + !nm, 2, 1, do_mem_nm_avr, + "avr memory modify (constant address)", + "address" +), #endif CMD_TBL_ITEM( mstep, 2, 1, do_busreq_pulse, diff --git a/avr/debug.c b/avr/debug.c index d4ae1f4..f3632c2 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -11,6 +11,7 @@ #include #include "command.h" +#include "cli_readline.h" #include "print-utils.h" #include "debug.h" @@ -39,7 +40,7 @@ void dump_heap(void) */ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count); + void (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count); (void) cmdtp; (void) flag; @@ -51,13 +52,13 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg switch (argv[0][3]) { case 'r': - readhow = ram_read_buf; + readwhat = ram_read_buf; break; case 'e': - readhow = eeprom_read_buf; + readwhat = eeprom_read_buf; break; case 'f': - readhow = flash_read_buf; + readwhat = flash_read_buf; break; default: return CMD_RET_USAGE; @@ -71,7 +72,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg length = (uint16_t) strtoul(argv[2], NULL, 16); /* Print the lines. */ - dump_mem(addr, addr, length, readhow, NULL); + dump_mem(addr, addr, length, readwhat, NULL); return CMD_RET_SUCCESS; } @@ -127,6 +128,83 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } +/* Modify memory. + * + * Syntax: + * !mm {addr} + * !nm {addr} + */ + + static uint8_t *mm_last_addr; + +static command_ret_t +mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) +{ + uint8_t *addr; + uint8_t data; + int nbytes; + + (void) cmdtp; + + if (argc != 2) + return CMD_RET_USAGE; + + /* We use the last specified parameters, unless new ones are + * entered. + */ + addr = mm_last_addr; + + if ((flag & CMD_FLAG_REPEAT) == 0) { + /* New command specified. + */ + + /* Address is specified since argc > 1 + */ + addr = (uint8_t *) (size_t) strtoul(argv[1], NULL, 16); + } + + /* Print the address, followed by value. Then accept input for + * the next value. A non-converted value exits. + */ + do { + data = *addr; + printf_P(PSTR("%04x: %02x"), addr, data); + + nbytes = cli_readline(PSTR(" ? ")); + if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { + /* pressed as only input, don't modify current + * location and move to next. "-" pressed will go back. + */ + if (incrflag) + addr += nbytes ? -1 : 1; + nbytes = 1; + + } else { + char *endp; + data = strtoul(console_buffer, &endp, 16); + nbytes = endp - console_buffer; + if (nbytes) { + *addr = data; + if (incrflag) + addr++; + } + } + } while (nbytes); + + mm_last_addr = addr; + return CMD_RET_SUCCESS; +} + + +command_ret_t do_mem_mm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 1, flag, argc, argv); +} +command_ret_t do_mem_nm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 0, flag, argc, argv); +} + /*------------------------------------------------------------------------------*/ #if 1 diff --git a/avr/z180-serv.c b/avr/z180-serv.c index af1d8e0..7193495 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -491,6 +491,9 @@ int msg_handling(int state) pending = (Stat & S_MSG_PENDING) != 0; Stat &= ~S_MSG_PENDING; } +/* + * TODO: if pending but no message chr --> special condition. ie init,... + */ if (pending) { switch (state) { diff --git a/include/z80-if.h b/include/z80-if.h index 58790bd..676d37d 100644 --- a/include/z80-if.h +++ b/include/z80-if.h @@ -43,7 +43,7 @@ void z80_read_block (uint8_t *dest, uint32_t src, size_t length); typedef enum fifo_t { fifo_msgin, fifo_msgout, - fifo_conout, fifo_conin, + fifo_conin, fifo_conout, NUM_FIFOS } fifo_t; diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index e86b8b2..0a35195 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -19,8 +19,8 @@ dseg - mkbuf co.fifo_id, co.fifo, co.fifo_len mkbuf ci.fifo_id, ci.fifo, ci.fifo_len + mkbuf co.fifo_id, co.fifo, co.fifo_len ;-------------------------------------------------------------- diff --git a/z180/config.inc b/z180/config.inc index 7b6d7ac..2a8a842 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -151,7 +151,7 @@ AVRINT6 equ 5Fh ; Definition of (logical) top 2 memory pages sysram_start equ 0FE00h -stacksize equ 80 +bs$stack$size equ 80 isvsw_loc equ 0FEE0h @@ -198,3 +198,10 @@ inidate macro dseg ds ??ps.len endm + +;----------------------------------------------------- + +b0call macro address + call _b0call + dw address + endm diff --git a/z180/ddtz.180 b/z180/ddtz.180 index aa4e977..4411549 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -958,11 +958,11 @@ do_op_mod: jr l0b58h ; divide x/y -; x: hl -; y: de +; hl: x +; de: y ; return: -; x/y: hl -; rem: de +; hl: q (x/y) +; de: r (x%y) DIV_HL_DE: push bc @@ -971,6 +971,11 @@ DIV_HL_DE: ld c,l ld hl,0 ;r = 0 ld a,16 ;count + +; de: x (x shifted out, q shifted in) +; bc: y +; hl: r (initially 0) + l0b89h: ex de,hl ;x add hl,hl ;x <<= 1 @@ -986,7 +991,7 @@ l0b89h: div_no_restore: dec a jr nz,l0b89h - ex de,hl + ex de,hl ;hl: q de: r pop bc ret @@ -6240,9 +6245,9 @@ vartabe: ;------------------------------------------ - .phase sysram_start+stacksize + .phase sysram_start+bs$stack$size $stack: -$stcka equ $ - stacksize +$stcka equ $ - bs$stack$size curphse defl $ .dephase diff --git a/z180/init.180 b/z180/init.180 index 11f45ec..b0b4b21 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -361,9 +361,9 @@ buffers: db 1 dw mrx.fifo db 2 - dw co.fifo - db 3 dw ci.fifo + db 3 + dw co.fifo buftablen equ ($ - buffers)/3 inimsg: -- cgit v1.2.3 From 8bbf185ed81c12534c0ad9b26f0049035fde8df4 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 9 Jun 2015 09:31:33 +0200 Subject: message buffer init changes. cp/m r/w for new memory map --- avr/z180-serv.c | 58 ++----- z180/conbuf-a.180 | 8 +- z180/config.inc | 22 ++- z180/ddtz.180 | 480 +++++++++++++++++++++++++++--------------------------- z180/init.180 | 113 +++++-------- z180/msgbuf-a.180 | 84 +++++++++- 6 files changed, 386 insertions(+), 379 deletions(-) (limited to 'z180/conbuf-a.180') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index b5d8140..69bcd9c 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -211,8 +211,8 @@ void do_msg_get_set_time(uint8_t subf, int len, uint8_t * msg) #define MAX_DRIVE 4 #define BLOCK_SIZE 512 -#define TPA_BASE 0x10000 -#define COMMON_BASE 0xC000 +//#define TPA_BASE 0x10000 +//#define COMMON_BASE 0xC000 struct cpm_drive_s { uint8_t drv; @@ -390,52 +390,31 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) res = f_lseek(&drv_table[drv].fd, pos); while (!res && secs--) { - unsigned int cnt, br; - - /* check bank boundary crossing */ - cnt = 0; - if (addr < (TPA_BASE + COMMON_BASE) && - (addr + BLOCK_SIZE) > (TPA_BASE + COMMON_BASE)) { - cnt = (TPA_BASE + COMMON_BASE) - addr; - } - - if (cnt) { - debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr, cnt); - debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr+cnt-TPA_BASE, BLOCK_SIZE-cnt); - } - + unsigned int brw; if (dowrite) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; break; } else { - if (cnt) { - z80_read_block(disk_buffer, addr, cnt); - addr = addr + cnt - TPA_BASE; - } - z80_read_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); + z80_read_block(disk_buffer, addr, BLOCK_SIZE); z80_bus_cmd(Release); } - res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw); } else { - res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); - if (res == FR_OK && br == BLOCK_SIZE) { + res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw); + if (res == FR_OK && brw == BLOCK_SIZE) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; break; } else { - if (cnt) { - z80_write_block(disk_buffer, addr, cnt); - addr = addr + cnt - TPA_BASE; - } - z80_write_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); + z80_write_block(disk_buffer, addr, BLOCK_SIZE); z80_bus_cmd(Release); } } } - if (br != BLOCK_SIZE) { - debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, br); + if (brw != BLOCK_SIZE) { + debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, brw); dump_ram(disk_buffer, 0, 64, "Read Data"); res = -1; } @@ -588,20 +567,11 @@ int msg_handling(int state) init_request = z80_read(0x43); z80_bus_cmd(Release); if ( init_request != 0) { - /* Get address of fifo_list */ - uint32_t fifo_addr = 0; + /* Get address of fifo 0 */ z80_bus_cmd(Request); - uint32_t fifo_list = z80_read(0x40) + - ((uint16_t) z80_read(0x41) << 8) + - ((uint32_t) z80_read(0x42) << 16); - if (fifo_list != 0) { - /* Get address of fifo 0 */ - fifo_addr = z80_read(fifo_list) + - ((uint16_t) z80_read(fifo_list+1) << 8); - /* TODO: log to phys addr translation - ((uint32_t) z80_read(fifo_list+2) << 16); - */ - } + uint32_t fifo_addr = z80_read(0x40) + + ((uint16_t) z80_read(0x40+1) << 8) + + ((uint32_t) z80_read(0x40+2) << 16); z80_write(0x43, 0); z80_bus_cmd(Release); diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index 0a35195..f69b86d 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -6,7 +6,7 @@ ; global ff.init,ff.in,ff.out,ff.i.st,ff.o.st - extrn buf.init + extrn bufinit include config.inc if CPU_Z180 @@ -32,11 +32,9 @@ ff.init: ld ix,ci.fifo - ld a,ci.fifo.mask - call buf.init + call bufinit ld ix,co.fifo - ld a,co.fifo.mask - jp buf.init + jp bufinit ff.i.st: diff --git a/z180/config.inc b/z180/config.inc index ffab6e6..1d0709d 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -48,22 +48,34 @@ PRT_PRE equ 20 ;PRT prescaler COMMON_SIZE equ 16*1024 ;Common Area size in bytes ;must be multiple of 4K - if (COMMON_SIZE mod 1000h) .printx COMMON_SIZE not multiple of 4K! end ;stop assembly endif +CMN_SIZE equ COMMON_SIZE/1000h ;4K units +BNK_SIZE equ 64/4 - CMN_SIZE ;bank size (4K units) +BANKS equ (512/4 - CMN_SIZE)/BNK_SIZE ;max nr. of banks + +; Logical address space, CBAR values -CSK equ COMMON_SIZE/1000h ; -CA equ 10h - CSK ;common area start -BA equ 0 ;banked area start +CA equ 10h - CMN_SIZE ;common area start (64K - common size) +BA equ 0 ;banked area start + + if 0 SYS$CBR equ 0 SYS$CBAR equ CA*16 + CA ;CBAR in system mode USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M) + endif + if 1 + +SYS$CBR equ BNK_SIZE +SYS$CBAR equ CA*16 + CA ;CBAR in system mode +USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M) + + endif -BANKS equ 18 ;max nr. of banks ;----------------------------------------------------- diff --git a/z180/ddtz.180 b/z180/ddtz.180 index 4411549..d5b921b 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -2197,294 +2197,294 @@ b_0x132A_start: DC 'F' DB 0 b_0x136C_start: - if ROMSYS - defb 000h - defw uromen + if ROMSYS + defb 000h + defw uromen endif if CPU_Z180 - defb 000h - defw ucbar - defb 000h - defw ubbr + defb 000h + defw ucbar + defb 000h + defw ubbr else - defb 000h - defw ubnk + defb 000h + defw ubnk endif - defb 003h - defw reg.c2 - defb 003h - defw reg.e2 - defb 003h - defw reg.l2 - defb 003h - defw reg.c - defb 003h - defw reg.e - defb 003h - defw reg.l - defb 000h - defw reg.a2 - defb 000h - defw reg.b2 - defb 000h - defw reg.c2 - defb 000h - defw reg.d2 - defb 000h - defw reg.e2 - defb 000h - defw reg.h2 - defb 000h - defw reg.l2 - defb 000h - defw reg.a - defb 000h - defw reg.b - defb 000h - defw reg.c - defb 000h - defw reg.d - defb 000h - defw reg.e - defb 000h - defw reg.h - defb 000h - defw reg.l - defb 003h - defw reg.ix - defb 003h - defw reg.iy - defb 003h - defw reg.sp - defb 003h - defw reg.pc - defb 003h - defw reg.ix - defb 003h - defw reg.iy - defb 003h - defw reg.sp - defb 003h - defw reg.pc - defb 000h - defw reg.i - defb 000h - defw reg.f2 - defb 000h - defw reg.f + defb 003h + defw reg.c2 + defb 003h + defw reg.e2 + defb 003h + defw reg.l2 + defb 003h + defw reg.c + defb 003h + defw reg.e + defb 003h + defw reg.l + defb 000h + defw reg.a2 + defb 000h + defw reg.b2 + defb 000h + defw reg.c2 + defb 000h + defw reg.d2 + defb 000h + defw reg.e2 + defb 000h + defw reg.h2 + defb 000h + defw reg.l2 + defb 000h + defw reg.a + defb 000h + defw reg.b + defb 000h + defw reg.c + defb 000h + defw reg.d + defb 000h + defw reg.e + defb 000h + defw reg.h + defb 000h + defw reg.l + defb 003h + defw reg.ix + defb 003h + defw reg.iy + defb 003h + defw reg.sp + defb 003h + defw reg.pc + defb 003h + defw reg.ix + defb 003h + defw reg.iy + defb 003h + defw reg.sp + defb 003h + defw reg.pc + defb 000h + defw reg.i + defb 000h + defw reg.f2 + defb 000h + defw reg.f CMD.S: - ld hl,(lst.S) - call get_lastarg_def + ld hl,(lst.S) + call get_lastarg_def l13d8h: - ld (lst.S),hl - call out.hl.@ - call OUTBL + ld (lst.S),hl + call out.hl.@ + call OUTBL comst - ld a,(hl) + ld a,(hl) comend - call out.hex - call outbl2 - call INLINE - call SKIPBL - inc hl - jr z,l13d8h - dec hl - inc de - cp '.' - jp z,assert_eol - cp '-' - jr nz,l1406h - ld a,(de) - or a - dec hl - jr z,l13d8h - inc hl + call out.hex + call outbl2 + call INLINE + call SKIPBL + inc hl + jr z,l13d8h + dec hl + inc de + cp '.' + jp z,assert_eol + cp '-' + jr nz,l1406h + ld a,(de) + or a + dec hl + jr z,l13d8h + inc hl l1406h: - dec de - call get_bytes_m - jr l13d8h + dec de + call get_bytes_m + jr l13d8h CMD.@: - call assert_eol - ld hl,MSG_at - ld de,offs.@ - ld c,001h - jp l1279h + call assert_eol + ld hl,MSG_at + ld de,offs.@ + ld c,001h + jp l1279h MSG_at: dc '@' CMD.I: - ld hl,CMD.I - ld (CMD_RPT),hl - ld hl,(lst.IP) - call get_lastarg_def - ld (lst.IP),hl - ld b,h - ld c,l + ld hl,CMD.I + ld (CMD_RPT),hl + ld hl,(lst.IP) + call get_lastarg_def + ld (lst.IP),hl + ld b,h + ld c,l if CPU_Z180 - ld a,b - or a - jr nz,l1442h - ld a,c - ld hl,ucbar - cp cbar - jr z,l143fh - ld hl,ubbr - cp bbr - jr nz,l1442h + ld a,b + or a + jr nz,l1442h + ld a,c + ld hl,ucbar + cp cbar + jr z,l143fh + ld hl,ubbr + cp bbr + jr nz,l1442h l143fh: - ld a,(hl) - jr l1444h + ld a,(hl) + jr l1444h l1442h: endif - in a,(c) + in a,(c) l1444h: - push af - call out.hex - call outbl4 - pop af - call out.bin.b - jp CRLF + push af + call out.hex + call outbl4 + pop af + call out.bin.b + jp CRLF CMD.O: - ld hl,CMD.O - ld (CMD_RPT),hl - ld hl,(lst.OD) - call get_arg_def - ld a,l - ld (lst.OD),a - push af - call skip_to_nextarg - ld hl,(lst.OP) - call get_lastarg_def - ld (lst.OP),hl - ld b,h - ld c,l + ld hl,CMD.O + ld (CMD_RPT),hl + ld hl,(lst.OD) + call get_arg_def + ld a,l + ld (lst.OD),a + push af + call skip_to_nextarg + ld hl,(lst.OP) + call get_lastarg_def + ld (lst.OP),hl + ld b,h + ld c,l if CPU_Z180 - ld a,b - or a - jr nz,l1489h - ld a,c - ld hl,ucbar - cp cbar - jr z,l148dh - ld hl,ubbr - cp bbr - jr z,l148dh - cp cbr - jp z,ERROR + ld a,b + or a + jr nz,l1489h + ld a,c + ld hl,ucbar + cp cbar + jr z,l148dh + ld hl,ubbr + cp bbr + jr z,l148dh + cp cbr + jp z,ERROR l1489h: endif - pop af - out (c),a + pop af + out (c),a ret if CPU_Z180 l148dh: - pop af - ld (hl),a - ret + pop af + ld (hl),a + ret endif CMD.V: - call get_arg3 ;1490 get from, size, to + call get_arg3 ;1490 get from, size, to cmp_mem: - push bc + push bc comst - ld a,(de) - ld b,(hl) + ld a,(de) + ld b,(hl) comend - cp b - jr z,l14bah - ld c,a - call out.hl.@ - call OUTBL - ld a,b - call out.hex - call outbl2 - ld a,c - call out.hex - call OUTBL - ex de,hl - call out.hl.@ - ex de,hl - call CRLF + cp b + jr z,l14bah + ld c,a + call out.hl.@ + call OUTBL + ld a,b + call out.hex + call outbl2 + ld a,c + call out.hex + call OUTBL + ex de,hl + call out.hl.@ + ex de,hl + call CRLF l14bah: - pop bc - inc hl - inc de - dec bc - ld a,b - or c - jr nz,cmp_mem + pop bc + inc hl + inc de + dec bc + ld a,b + or c + jr nz,cmp_mem ret CMD.M: - ld a,(de) - cp 'V' - jr nz,bm_nv - inc de + ld a,(de) + cp 'V' + jr nz,bm_nv + inc de bm_nv: - push af ;14c9 save 'V' flag - call get_arg3 - push hl - push de - push bc - call CP.HL.DE - jr nc,bm_mvdown - add hl,bc - ex de,hl - add hl,bc - ex de,hl - dec hl - dec de + push af ;14c9 save 'V' flag + call get_arg3 + push hl + push de + push bc + call CP.HL.DE + jr nc,bm_mvdown + add hl,bc + ex de,hl + add hl,bc + ex de,hl + dec hl + dec de comst - lddr + lddr comend - jr bm_done + jr bm_done bm_mvdown: comst ldir comend bm_done: - pop bc - pop de - pop hl - pop af - jr z,cmp_mem ;14ed validate? + pop bc + pop de + pop hl + pop af + jr z,cmp_mem ;14ed validate? ret CMD.H: - call EXPR - jp c,l173ch - call skip_to_nextarg - push hl - call EXPR - push af - call assert_eol - pop af - ex de,hl - pop hl - jr c,l1511h - push hl - push de - add hl,de - call l1511h - pop de - pop hl - and a - sbc hl,de + call EXPR + jp c,l173ch + call skip_to_nextarg + push hl + call EXPR + push af + call assert_eol + pop af + ex de,hl + pop hl + jr c,l1511h + push hl + push de + add hl,de + call l1511h + pop de + pop hl + and a + sbc hl,de l1511h: - call out.hl ;1511 val - call outbl2 - call sub_0928h ;1517 -val - call outbl4 - call out.hl.dec ;151d dec - call outbl2 - call out.hl.decm ;1523 -dec - call outbl4 - call out.bin.w ;1529 bin - call outbl2 - ld a,l - call out.ascii - jp CRLF + call out.hl ;1511 val + call outbl2 + call sub_0928h ;1517 -val + call outbl4 + call out.hl.dec ;151d dec + call outbl2 + call out.hl.decm ;1523 -dec + call outbl4 + call out.bin.w ;1529 bin + call outbl2 + ld a,l + call out.ascii + jp CRLF CMD.Q: ld a,(de) diff --git a/z180/init.180 b/z180/init.180 index 4c7bd77..05c24ff 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -76,7 +76,7 @@ start: hwini0: if CPU_Z180 - db 3 ;count + db ;count db rcr,CREFSH ;configure DRAM refresh db dcntl,INIWAITS ;wait states db cbr,SYS$CBR @@ -152,7 +152,7 @@ hw_reset: kstart: if CPU_Z180 - ld a,SYS$CBR + ld a,SYS$CBR ;TODO: out0 (cbr),a ld a,SYS$CBAR out0 (cbar),a @@ -192,8 +192,8 @@ wstart: ; call prt0_init endif + call msginit call charini - call bufferinit if CPU_Z80 ld a,0 @@ -228,86 +228,66 @@ syscbr: db 0 ;---------------------------------------------------------------------- ; - global buf.init + global bufinit -buf.init: - ld (ix+o.in_idx),0 +bufinit: + ld (ix+o.in_idx),0 ;reset pointers (empty fifo) ld (ix+o.out_idx),0 - ld a,(ix+o.id) - cp 4 - ret nc - - push de - push hl - ld hl,fifo_list - push hl ;save fifo_list + ld hl,fifolst ld e,a ld d,0 add hl,de add hl,de push ix pop de + cp 4 + jr nc,bfi_skip + ld (hl),e inc hl ld (hl),d - pop hl ;get fifo_list back - or a - jr nz,bufi_ex - ld (040h),hl - ld (040h+2),a -bufi_ex: - pop hl - pop de +bfi_skip: + ex de,hl + call hwl2phy ;get phys. address of fifo + ld c,a + ld a,(ix+o.id) ;fifo id + or a ;test if fifo 0 + ret z + ld b,a + push bc ;c: bank-addr, b: ignored + push hl ;address + ld c,0 + push bc ;c: function, b:subf + ld b,5 + ld h,c + ld l,c + add hl,sp + call msg.sm + pop hl + pop hl + pop hl ret - -fifo_list: + public fifolst +fifolst : rept 4 dw 0 endm ;---------------------------------------------------------------------- + extrn msg.sm extrn msginit,msg.sout extrn mtx.fifo,mrx.fifo - extrn co.fifo,ci.fifo + extrn ff.init,co.fifo,ci.fifo -bufferinit: +fifoinit: if CPU_Z180 - call msginit - - ld hl,buffers - ld b,buftablen -bfi_1: - ld a,(hl) - inc hl - ld (bufdat+0),a - ld e,(hl) - inc hl - ld d,(hl) - inc hl - ex de,hl - or a - jr nz,bfi_2 -; call hwl2phy -; ld (40h+0),hl -; ld (40h+2),a - out (AVRINT5),a - jr bfi_3 -bfi_2: - call hwl2phy - ld (bufdat+1),hl - ld (bufdat+3),a - ld hl,inimsg - call msg.sout -bfi_3: - ex de,hl - djnz bfi_1 ret else ;CPU_Z180 @@ -351,27 +331,7 @@ bfi_3: ret endif -buffers: - db 0 - dw mtx.fifo - db 1 - dw mrx.fifo - db 2 - dw ci.fifo - db 3 - dw co.fifo -buftablen equ ($ - buffers)/3 - -inimsg: - db inimsg_e - $ -1 - db 0AEh - db inimsg_e - $ -1 - db 0 -bufdat: - db 0 - dw 0 - db 0 -inimsg_e: + ; @@ -612,6 +572,7 @@ l2p_i: ; ;out ahl: Phys. (linear) Address + public hwl2phy hwl2phy: push bc ; diff --git a/z180/msgbuf-a.180 b/z180/msgbuf-a.180 index 7e8c9cc..3575569 100644 --- a/z180/msgbuf-a.180 +++ b/z180/msgbuf-a.180 @@ -1,12 +1,13 @@ page 255 .z80 - global mrx.fifo,mtx.fifo + public mrx.fifo,mtx.fifo - global msginit,msgi.st,msg.in,msgo.st,msg.out - global msg.sout + public msginit,msgi.st,msg.in,msgo.st + public msg.sm,msg.sout - extrn buf.init + extrn bufinit,hwl2phy + extrn fifolst include config.inc if CPU_Z180 @@ -29,12 +30,25 @@ ; msginit: + ld a,(043h) +;TODO: value should be 0 ld ix,mtx.fifo - ld a,mtx.fifo.mask - call buf.init + call bufinit + push ix + pop hl + call hwl2phy + ld (040h),hl + ld (040h+2),a + ld a,0ffh + ld (043h),a + out (AVRINT5),a +wait: + ld a,(043h) + or a + jr nz,wait + ld ix,mrx.fifo - ld a,mrx.fifo.mask - jp buf.init + jp bufinit ;-------------------------------------------------------------- @@ -136,7 +150,7 @@ bp.wait: ;-------------------------------------------------------------- - + if 0 msg.out: push ix @@ -165,6 +179,36 @@ bp.wait: pop ix ret + endif + +;---------------------------------------------------------------------- +; +; Put char in message buffer: +; ix: buffer to put into +; c: char + +buf.put: + push ix ;15 + push bc ;11 + ld a,(ix+o.in_idx) ;19 + ld c,a ;4 + ld b,0 ;7 + add ix,bc ;11 + pop bc ;10 + ld (ix),c ;7 + pop ix ;14 + + inc a ;4 + and (ix+o.mask) ;19 =121 +bufp.wait: + cp (ix+o.out_idx) ;19 + jr z,bufp.wait ;12/7 + ld (ix+o.in_idx),a ;19 + + out (AVRINT5),a ;11 + ld a,c ;4 + ret ;10 =191 + ;-------------------------------------------------------------- @@ -305,4 +349,26 @@ buf_end: ;---------------------------------------------------------------------- +;---------------------------------------------------------------------- +; Send message MEMORY +; +; hl: pointer to message (netto) +; b: msg length + +msg.sm: + push ix + ld ix,mtx.fifo + ld c,0AEh + call buf.put + ld c,b + call buf.put +msm_l: + ld c,(hl) + inc hl + call buf.put + djnz msm_l + pop ix + ret + + end -- cgit v1.2.3