diff --git a/.gitignore b/.gitignore index c21a4f0..20fd895 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,7 @@ __pycache__ *.o *.chr +# Don't get your hopes up /hopesup/*.sms /hopesup/*.sym +/hopesup/obj/something/ diff --git a/hopesup/makefile b/hopesup/makefile index a72aa02..91f3143 100644 --- a/hopesup/makefile +++ b/hopesup/makefile @@ -4,7 +4,7 @@ title:=hopesup version:=wip objlist:= \ - init main ppuclear pads vwfdraw + init main ppuclear pads vwfdraw vwf7_cp144p objdir:=obj/something srcdir:=src @@ -59,6 +59,8 @@ $(objdir)/%.pb16: tools/pb16.py $(objdir)/% $(PY) $^ $@ $(objdir)/%.iu: tools/incruniq.py $(objdir)/%.2b $(PY) $^ $@ +$(objdir)/vwf7_cp144p.asm: tools/vwfbuild.py ../tilesets/vwf7_cp144p.png + $(PY) $^ $@ # LUT generation diff --git a/hopesup/obj/something/objlist b/hopesup/obj/something/objlist deleted file mode 100644 index bb7626e..0000000 --- a/hopesup/obj/something/objlist +++ /dev/null @@ -1,6 +0,0 @@ -[objects] -obj/something/init.o -obj/something/main.o -obj/something/ppuclear.o -obj/something/pads.o -obj/something/vwfdraw.o diff --git a/hopesup/src/floormodel.asm b/hopesup/src/floormodel.asm new file mode 100644 index 0000000..6405ca4 --- /dev/null +++ b/hopesup/src/floormodel.asm @@ -0,0 +1 @@ +.include "src/sms.inc" diff --git a/hopesup/src/floorvram.asm b/hopesup/src/floorvram.asm new file mode 100644 index 0000000..6405ca4 --- /dev/null +++ b/hopesup/src/floorvram.asm @@ -0,0 +1 @@ +.include "src/sms.inc" diff --git a/hopesup/src/main.asm b/hopesup/src/main.asm index 175579c..162e854 100644 --- a/hopesup/src/main.asm +++ b/hopesup/src/main.asm @@ -124,39 +124,39 @@ draw_bg: ; Clear the pattern table vdp_seek_tile 0 ld a, $55 - ld d, 32/32 + ld d, 40/8 call vmemset_256d ; Clear nametable and SAT call vdp_clear_nt - - vdp_seek_xy 15, 11 - ld a, 16 - out [VDPDATA], a - ld a, 0 - out [VDPDATA], a - ld a, 17 - out [VDPDATA], a - ld a, 0 - out [VDPDATA], a + + ; load vwfcanvas + vdp_seek_xy 8, 11 + ld c, 16 + ld b, c + @loop: + ld a, c + inc c + out [VDPDATA], a + xor a + out [VDPDATA], a + djnz @loop + + call vwfClearBuf + ld hl, hello_msg + ld b, 4 + call vwfPuts + vdp_seek_tile 16 - ld a, $20 - out [VDPDATA], a - xor a - out [VDPDATA], a - out [VDPDATA], a - out [VDPDATA], a - ld a, $10 - out [VDPDATA], a - xor a - out [VDPDATA], a - out [VDPDATA], a - out [VDPDATA], a - + ld hl, lineImgBuf + ld d, 1 + call load_1bpp_font + ret PaletteData: - drgb $FF0000, $555555, $AAAAAA, $FFFFFF + drgb $AAAAAA, $000000 PaletteDataEnd: - +hello_msg: + .db "Nothing to see; move along", 0 .ends \ No newline at end of file diff --git a/hopesup/src/vwfdraw.asm b/hopesup/src/vwfdraw.asm index 8240038..5ddef22 100644 --- a/hopesup/src/vwfdraw.asm +++ b/hopesup/src/vwfdraw.asm @@ -79,7 +79,7 @@ vwfPutTile_rowloop: ;; ; Draws the tile for glyph A at horizontal position B -vwfPutTile:: +vwfPutTile: ; Calculate address of glyph ld h,0 @@ -123,11 +123,11 @@ vwfPutTile:: ; Write glyphs for the 8-bit-encoded characters string at (hl) to ; X position B in the VWF buffer ; @return HL pointer to the first character not drawn -vwfPuts:: +vwfPuts: @chloop: ; Load character, stopping at control character ld a,[hl] - inc a + inc hl cp 32 jr c,@decret @@ -162,5 +162,17 @@ vwfPuts:: dec hl ret +;; +; Clears the line image. +; @return B = 0; HL = lineImgBuf + lineImgBufLen +vwfClearBuf: + ld hl,lineImgBuf + ld b,lineImgBufLen + xor a +.loop: + ld [hl],a + inc l + djnz .loop + ret .ends \ No newline at end of file diff --git a/hopesup/tools/vwfbuild.py b/hopesup/tools/vwfbuild.py new file mode 100755 index 0000000..dd11b1c --- /dev/null +++ b/hopesup/tools/vwfbuild.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +from __future__ import with_statement +from PIL import Image +import sys + +def rgbasm_bytearray(s): + s = [' .db ' + ','.join("%3d" % ch for ch in s[i:i + 16]) + for i in range(0, len(s), 16)] + return '\n'.join(s) + +def vwfcvt(filename, tileHt=8): + im = Image.open(filename) + pixels = im.load() + (w, h) = im.size + (xparentColor, sepColor) = im.getextrema() + widths = bytearray() + tiledata = bytearray() + for yt in range(0, h, tileHt): + for xt in range(0, w, 8): + # step 1: find the glyph width + tilew = 8 + for x in range(8): + if pixels[x + xt, yt] == sepColor: + tilew = x + break + # step 2: encode the pixels + widths.append(tilew) + for y in range(tileHt): + rowdata = 0 + for x in range(8): + pxhere = pixels[x + xt, y + yt] + pxhere = 0 if pxhere in (xparentColor, sepColor) else 1 + rowdata = (rowdata << 1) | pxhere + tiledata.append(rowdata) + return (widths, tiledata) + +def main(argv=None): + import sys + if argv is None: + argv = sys.argv + if len(argv) > 1 and argv[1] == '--help': + print("usage: %s font.png font.asm" % argv[0]) + return + if len(argv) != 3: + print("wrong number of options; try %s --help" % argv[0], file=sys.stderr) + sys.exit(1) + + (widths, tiledata) = vwfcvt(argv[1]) + out = ["; Generated by vwfbuild", + '.include "src/sms.inc"', + '.section "vwfChrData" align 8 ; glyph height = 8', + 'vwfChrData:', + rgbasm_bytearray(tiledata), + "vwfChrWidths:", + rgbasm_bytearray(widths), + '.ends', + ''] + with open(argv[2], 'w') as outfp: + outfp.write('\n'.join(out)) + +if __name__ == '__main__': + if 'idlelib' in sys.modules: + main(['vwfbuild', '../../tilesets/vwf7_cp144p.png', '../obj/something/vwf7.asm']) + else: + main()