1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 15:58:05 +11:00

sms: WIP !

This commit is contained in:
Virgil Dupras 2020-05-14 22:15:31 -04:00
parent faa2576f83
commit 43eabf566b
13 changed files with 130 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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,

3
blk/620 Normal file
View File

@ -0,0 +1,3 @@
Sega Master System Recipe
622 VDP

16
blk/622 Normal file
View File

@ -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

9
blk/623 Normal file
View File

@ -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

10
blk/624 Normal file
View File

@ -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

10
blk/625 Normal file
View File

@ -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?) )

12
blk/626 Normal file
View File

@ -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 ;

14
blk/627 Normal file
View File

@ -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
;

View File

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <xcb/xcb.h>
@ -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.

View File

@ -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)

32
recipes/sms/xcomp.fs Normal file
View File

@ -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!