From 43eabf566b8d18510897aaa6beee8a50fe8277ff Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 14 May 2020 22:15:31 -0400 Subject: [PATCH] sms: WIP ! --- blk/001 | 2 +- blk/209 | 2 +- blk/224 | 3 ++- blk/620 | 3 +++ blk/622 | 16 ++++++++++++++++ blk/623 | 9 +++++++++ blk/624 | 10 ++++++++++ blk/625 | 10 ++++++++++ blk/626 | 12 ++++++++++++ blk/627 | 14 ++++++++++++++ emul/hw/sms/sms.c | 7 ++++++- recipes/sms/Makefile | 22 ++++++++++++++-------- recipes/sms/xcomp.fs | 32 ++++++++++++++++++++++++++++++++ 13 files changed, 130 insertions(+), 12 deletions(-) create mode 100644 blk/620 create mode 100644 blk/622 create mode 100644 blk/623 create mode 100644 blk/624 create mode 100644 blk/625 create mode 100644 blk/626 create mode 100644 blk/627 create mode 100644 recipes/sms/xcomp.fs diff --git a/blk/001 b/blk/001 index 427c812..82c2ef6 100644 --- a/blk/001 +++ b/blk/001 @@ -8,7 +8,7 @@ MASTER INDEX 280 Z80 boot code 390 Cross-compiled core 490 TRS-80 Recipe 520 Fonts 550 TI-84+ Recipe 580 RC2014 Recipe - +620 Sega Master System Recipe diff --git a/blk/209 b/blk/209 index 527dcd7..a25a953 100644 --- a/blk/209 +++ b/blk/209 @@ -8,4 +8,4 @@ JP [nn, (HL), (IX), (IY)] JR [, Z, NZ, C, NC] DI EI EXDEHL EXX HALT -NOP RET SCF +NOP RET RETI RETN SCF diff --git a/blk/224 b/blk/224 index 9f8d305..b67e602 100644 --- a/blk/224 +++ b/blk/224 @@ -5,4 +5,5 @@ 0xed5e OP2 IM2, 0xeda0 OP2 LDI, 0xedb0 OP2 LDIR, 0xeda8 OP2 LDD, 0xedb8 OP2 LDDR, -0xed44 OP2 NEG, 0xed4d OP2 RETI, +0xed44 OP2 NEG, +0xed4d OP2 RETI, 0xed45 OP2 RETN, diff --git a/blk/620 b/blk/620 new file mode 100644 index 0000000..bce2e02 --- /dev/null +++ b/blk/620 @@ -0,0 +1,3 @@ +Sega Master System Recipe + +622 VDP diff --git a/blk/622 b/blk/622 new file mode 100644 index 0000000..e640ba1 --- /dev/null +++ b/blk/622 @@ -0,0 +1,16 @@ +VDP Driver + +Implement (emit) on the console. Characters start at the top +left. Every (emit) call converts the ASCII char received to its +internal font, then put that char on screen, advancing the +cursor by one. When reaching the end of the line (33rd char), +wrap to the next. + +In the future, there's going to be a scrolling mechanism when +we reach the bottom of the screen, but for now, when the end of +the screen is reached, we wrap up to the top. + +When reaching a new line, we clear that line and the next to +help readability. + +Load range: 623-623 diff --git a/blk/623 b/blk/623 new file mode 100644 index 0000000..bea85cc --- /dev/null +++ b/blk/623 @@ -0,0 +1,9 @@ +CODE _ctl ( a -- sends LSB then MSB ) + HL POPqq, chkPS, + A L LDrr, VDP_CTLPORT OUTnA, + A H LDrr, VDP_CTLPORT OUTnA, +;CODE +CODE _data + HL POPqq, chkPS, + A L LDrr, VDP_DATAPORT OUTnA, +;CODE diff --git a/blk/624 b/blk/624 new file mode 100644 index 0000000..2212e80 --- /dev/null +++ b/blk/624 @@ -0,0 +1,10 @@ +CODE _blank ( this is way too slow in Forth ) + A XORr, VDP_CTLPORT OUTnA, + A 0x40 LDrn, VDP_CTLPORT OUTnA, + HL 0x4000 LDddnn, + BEGIN, + A XORr, VDP_DATAPORT OUTnA, + HL DECss, HLZ, + JRNZ, AGAIN, +;CODE + diff --git a/blk/625 b/blk/625 new file mode 100644 index 0000000..70e9aee --- /dev/null +++ b/blk/625 @@ -0,0 +1,10 @@ +CREATE _idat +0b00000100 C, 0x80 C, ( Bit 2: Select mode 4 ) +0b00000000 C, 0x81 C, +0b11111111 C, 0x82 C, ( Name table: 0x3800 ) +0b11111111 C, 0x85 C, ( Sprite table: 0x3f00 ) +0b11111111 C, 0x86 C, ( sprite use tiles from 0x2000 ) +0b11111111 C, 0x87 C, ( Border uses palette 0xf ) +0b00000000 C, 0x88 C, ( BG X scroll ) +0b00000000 C, 0x89 C, ( BG Y scroll ) +0b11111111 C, 0x8a C, ( Line counter (why have this?) ) diff --git a/blk/626 b/blk/626 new file mode 100644 index 0000000..e81e993 --- /dev/null +++ b/blk/626 @@ -0,0 +1,12 @@ +: _zero ( x -- send 0 _data x times ) + ( x ) 0 DO 0 _data LOOP ; + +( Each row in ~FNT is a row of the glyph and there is 7 of +them. We insert a blank one at the end of those 7. For each +row we set, we need to send 3 zero-bytes because each pixel in +the tile is actually 4 bits because it can select among 16 +palettes. We use only 2 of them, which is why those bytes +always stay zero. ) +: _sfont ( a -- Send font to VDP ) + 7 0 DO C@+ _data 3 _zero LOOP DROP + ( blank row ) 4 _zero ; diff --git a/blk/627 b/blk/627 new file mode 100644 index 0000000..4aa6757 --- /dev/null +++ b/blk/627 @@ -0,0 +1,14 @@ +: _set ( row col tilenum -- ) + ROT 5 LSHIFT ROT OR 0x7800 OR _ctl + _data 1 _zero +; +: VDP$ + 9 0 DO _idat I 2 * + @ _ctl LOOP _blank + ( palettes ) + 0xc000 _ctl + ( BG ) 1 _zero 0x3f _data 14 _zero + ( sprite, inverted colors ) 0x3f _data 15 _zero + 0x4000 _ctl 0x5e 0 DO ~FNT I 7 * + _sfont LOOP + 0 0 1 _set +; + diff --git a/emul/hw/sms/sms.c b/emul/hw/sms/sms.c index bde800d..7bce0f5 100644 --- a/emul/hw/sms/sms.c +++ b/emul/hw/sms/sms.c @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -155,7 +156,11 @@ void draw_pixels() void event_loop() { while (1) { - emul_step(); + if (!emul_step()) { + fprintf(stderr, "CPU halted, quitting\n"); + usleep(1000 * 1000); + break; + } if (vdp_changed) { // To avoid overdrawing, we'll let the CPU run a bit to finish its // drawing operation. diff --git a/recipes/sms/Makefile b/recipes/sms/Makefile index b1145e5..c0ace7e 100644 --- a/recipes/sms/Makefile +++ b/recipes/sms/Makefile @@ -1,10 +1,16 @@ -TARGET = os.sms -BASEDIR = ../.. -ZASM = $(BASEDIR)/emul/zasm/zasm -KERNEL = $(BASEDIR)/kernel -APPS = $(BASEDIR)/apps +TARGET = os.bin +STAGE = ../../emul/stage +EMUL = ../../emul/hw/sms/sms .PHONY: all -all: $(TARGET) -$(TARGET): glue.asm - $(ZASM) $(KERNEL) $(APPS) < glue.asm > $@ +all: $(TARGET) +$(TARGET): xcomp.fs $(STAGE) + cat xcomp.fs | $(STAGE) > $@ + +$(EMUL): + $(MAKE) -C ${@:%/sms=%} + +.PHONY: emul +emul: $(EMUL) $(TARGET) + $(EMUL) $(TARGET) + diff --git a/recipes/sms/xcomp.fs b/recipes/sms/xcomp.fs new file mode 100644 index 0000000..8fe4c50 --- /dev/null +++ b/recipes/sms/xcomp.fs @@ -0,0 +1,32 @@ +( 8K of onboard RAM ) +0xc000 CONSTANT RAMSTART +0xdd00 CONSTANT RS_ADDR +( Memory register at the end of RAM. Must not overwrite ) +0xddca CONSTANT PS_ADDR +0xbf CONSTANT VDP_CTLPORT +0xbe CONSTANT VDP_DATAPORT +32 CONSTANT VDP_COLS +24 CONSTANT VDP_ROWS +212 LOAD ( z80 assembler ) +: ZFILL, ( u ) 0 DO 0 A, LOOP ; +262 LOAD ( xcomp ) +524 LOAD ( font compiler ) +270 LOAD ( xcomp overrides ) + +0x100 JPnn, 0x63 ZFILL, ( 0x66 ) +RETN, 0x98 ZFILL, ( 0x100 ) +( All set, carry on! ) +CURRENT @ XCURRENT ! +0x100 BIN( ! +282 LOAD ( boot.z80 ) +393 LOAD ( xcomp core low ) +CREATE ~FNT CPFNT7x7 +623 627 LOADR ( VDP ) +: (key) 0 ; : (emit) DROP ; +420 LOAD ( xcomp core high ) +(entry) _ +( Update LATEST ) +PC ORG @ 8 + ! +," VDP$ BYE " +ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! +H@ 256 /MOD 2 PC! 2 PC!