Skip to content

Instantly share code, notes, and snippets.

@willbritton
Last active August 25, 2023 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willbritton/c8f427edb8d3bd70ceb8592ab524db52 to your computer and use it in GitHub Desktop.
Save willbritton/c8f427edb8d3bd70ceb8592ab524db52 to your computer and use it in GitHub Desktop.
; control characters
; string terminator
ff=</>
; crlf
fe=<br>
; various sized "tabs"
f1=<1>
f2=<2>
f3=<3>
f4=<4>
f5=<5>
f6=<6>
f7=<7>
f8=<8>
f9=<9>
; printable characters
; single space character on line below!
00=
01=A
02=B
03=C
04=D
05=E
06=F
07=G
08=H
09=I
0a=J
0b=K
0c=L
0d=M
0e=N
0f=O
10=P
11=Q
12=R
13=S
14=T
15=U
16=V
17=W
18=X
19=Y
1a=Z
1b=a
1c=b
1d=c
1e=d
1f=e
20=f
21=g
22=h
23=i
24=j
25=k
26=l
27=m
28=n
29=o
2a=p
2b=q
2c=r
2d=s
2e=t
2f=u
30=v
31=w
32=x
33=y
34=z
35=1
36=2
37=3
38=4
39=5
3a=6
3b=7
3c=8
3d=9
3e=/
3f='
40=,
41=.
42=-
43=..
.include "memory_map.inc"
.smstag ; automatically adds the TMR SEGA header so real consoles recognize it
.define RAM_TOP = $dff8
.define VDP_CMD = $bf
.define VDP_DATA = $be
; duplicating control mappings here for convenience
.define STR_TERM = $ff
.define STR_CRLF = $fe
.define STR_TAB_START = $f0
.define STR_SPACE = $00
.orga 0
di
im 1
ld sp, RAM_TOP
jp init
.orga $0010
ld a, e
out (VDP_CMD), a
ld a, d
out (VDP_CMD), a
ret
.orga $0038
in a, (VDP_CMD)
reti
.orga $0066
retn
init:
; load palette
ld de, $c000
rst $10
ld hl, intropalette
ld bc, _sizeof_intropalette
call vdp_memcpy
; copy tiles
ld de, $4000
rst $10
ld hl, assets.fonticons.bin
ld bc, _sizeof_assets.fonticons.bin
call vdp_memcpy
; suppress sprites
ld de, $7f00
rst $10
ld a, $d0
out (VDP_DATA), a
; clear screen
ld de, $7800
rst $10
ld bc, 32*28*2
xor a
call vdp_memfill
; construct screenmap from string(s)
ld de, $3800
ld hl, strings.intro
call text_print
; display on
ld de, $8160
rst $10
ei
jr main
main:
halt
jr main
text_print:
ld a, d
or $40
ld d, a
rst $10 ; de is keeping track of the vram pointer within this routine
ld bc, $0040 ; used for line feeds
-
ld a, (hl) ; load the next byte
inc hl ; make sure the pointer is moved on regardless
cp STR_TERM ; test for string terminator
ret z
cp STR_CRLF ; test for newlines
jr nz, +
ex de, hl
add hl, bc ; moves to next line (lf)
ld a, l
and $c0 ; moves to start of line (cr)
ld l, a
ex de, hl
rst $10
jr -
+
cp STR_TAB_START ; test for tabs
jr c, +
jr z, +
sub STR_TAB_START
sla a
add a, e
ld e, a
rst $10
jr -
+
out (VDP_DATA), a ; write the tile index
xor a
out (VDP_DATA), a ; keeping it simple with first screenmap byte being $00 for now
jr -
vdp_memcpy:
ld e, b
ld b, c
ld c, VDP_DATA
-
otir
dec e
ret m
jr -
ret
vdp_memfill:
ld e, b
ld b, c
-
out (VDP_DATA), a
djnz -
dec e
ret m
jr -
ret
.stringmaptable default "./assets/default.tbl"
strings.intro:
.stringmap default, "<5>The world is veiled in<br><br>"
.stringmap default, "<4>darkness. The wind stops,<br><br>"
.stringmap default, "<9>the sea is wild,<br><br>"
.stringmap default, "<2>and the earth begins to rot.<br><br>"
.stringmap default, "<9>The people wait,<br><br>"
.stringmap default, "<2>their only hope, a prophecy....<br><br>"
.stringmap default, "<1>'When the world is in darkness<br><br>"
.stringmap default, "<3>Four Warriors will come....'<br><br>"
.stringmap default, "<3>After a long journey, four<br><br>"
.stringmap default, "<5>young warriors arrive,<br><br>"
.stringmap default, "<6>each holding an ORB.</>"
assets.fonticons.bin: .incbin "./assets/fonticons.bin"
intropalette: .db $20,$20,$15,$2A,$3F ;dark blue, dark blue, dark gray, gray, white
eof:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment