From 57fd14b0b3b97ef623e4503ba3f9580aac6812ab Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 16 Nov 2020 13:10:04 -0500 Subject: [PATCH] sms: fix cursor mis-display in text mode In CURSOR!, I was using a write commande to read from VRAM and the emulator didn't properly behave and did as if everything was fine. The result on a real SMS was that the cursor would contain the inverted glyph of the contents of the *old* cursor position. --- blk.fs | 11 ++++++----- emul/z80/tms9918.c | 11 ++++++----- emul/z80/tms9918.h | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/blk.fs b/blk.fs index da50eba..8debdaa 100644 --- a/blk.fs +++ b/blk.fs @@ -2769,7 +2769,8 @@ CODE TICKS 1 chkPS, ( n=100us ) ( ----- 470 ) ( Z80 driver for TMS9918. Implements grid protocol. Requires TMS_CTLPORT, TMS_DATAPORT and ~FNT from the Font compiler at -B520. Load range B470-472 ) +B520. Patterns are at addr 0x0000, Names are at 0x3800. +Load range B470-472 ) CODE _ctl ( a -- sends LSB then MSB ) HL POP, chkPS, A L LDrr, TMS_CTLPORT OUTiA, @@ -2795,10 +2796,10 @@ them. We insert a blank one at the end of those 7. ) 0x20 - ( glyph ) 0x5e MOD _data ; ( ----- 472 ) : CURSOR! ( new old -- ) - 0x7800 OR DUP _ctl [ TMS_DATAPORT LITN ] PC@ - 0x7f AND ( new cmd glyph ) SWAP _ctl _data - 0x7800 OR DUP _ctl [ TMS_DATAPORT LITN ] PC@ - 0x80 OR ( cmd glyph ) SWAP _ctl _data ; + DUP 0x3800 OR _ctl [ TMS_DATAPORT LITN ] PC@ + 0x7f AND ( new old glyph ) SWAP 0x7800 OR _ctl _data + DUP 0x3800 OR _ctl [ TMS_DATAPORT LITN ] PC@ + 0x80 OR ( new glyph ) SWAP 0x7800 OR _ctl _data ; : COLS 40 ; : LINES 24 ; : TMS$ 0x8100 _ctl ( blank screen ) diff --git a/emul/z80/tms9918.c b/emul/z80/tms9918.c index a2a9d57..462fca7 100644 --- a/emul/z80/tms9918.c +++ b/emul/z80/tms9918.c @@ -27,6 +27,7 @@ void tms_init(TMS9918 *tms) memset(tms->regs, 0, 0x10); tms->has_cmdlsb = false; tms->curaddr = 0; + tms->databuf = 0; tms->width = 40*6; tms->height = 24*8; } @@ -50,20 +51,20 @@ void tms_cmd_wr(TMS9918 *tms, uint8_t val) } else { // VRAM tms->curaddr = ((val&0x3f) << 8) + tms->cmdlsb; + if ((val & 0x40) == 0) { // reading VRAM + tms->databuf = tms->vram[tms->curaddr]; + } } } uint8_t tms_data_rd(TMS9918 *tms) { - if (tms->curaddr < TMS_VRAM_SIZE) { - return tms->vram[tms->curaddr++]; - } else { - return 0; - } + return tms->databuf; } void tms_data_wr(TMS9918 *tms, uint8_t val) { + tms->databuf = val; if (tms->curaddr < TMS_VRAM_SIZE) { tms->vram[tms->curaddr++] = val; } diff --git a/emul/z80/tms9918.h b/emul/z80/tms9918.h index db4b8d2..0ab2d33 100644 --- a/emul/z80/tms9918.h +++ b/emul/z80/tms9918.h @@ -13,6 +13,7 @@ typedef struct { uint8_t cmdlsb; bool has_cmdlsb; uint16_t curaddr; + uint8_t databuf; uint16_t width; // in pixels uint16_t height; // in pixels } TMS9918;