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=⮐
; 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⮐⮐"
.stringmap default, "4️⃣darkness. The wind stops,⮐⮐"
.stringmap default, "9️⃣the sea is wild,⮐⮐"
.stringmap default, "2️⃣and the earth begins to rot.⮐⮐"
.stringmap default, "9️⃣The people wait,⮐⮐"
.stringmap default, "2️⃣their only hope, a prophecy....⮐⮐"
.stringmap default, "1️⃣'When the world is in darkness⮐⮐"
.stringmap default, "3️⃣Four Warriors will come....'⮐⮐"
.stringmap default, "3️⃣After a long journey, four⮐⮐"
.stringmap default, "5️⃣young warriors arrive,⮐⮐"
.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