aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-10-31 15:04:01 +0900
committerAstatin <[email protected]>2024-10-31 15:04:01 +0900
commita69ff95615b9ef4ed1ef2e0dbe42bf64b36e25b0 (patch)
tree805f8f0ab1274df6d89fcf8ea1f46643b47e941a
parente4507824c03030e7f1f11483f400335ae668424a (diff)
Add font and Print_str routine
-rw-r--r--entity/actions.gbasm8
-rw-r--r--main.gbasm10
-rw-r--r--scripts/generate-tiledata.py8
-rw-r--r--scripts/parse_sprite_png.py27
-rw-r--r--tiles.gbasm30
-rw-r--r--tileset.gbasm45
-rw-r--r--utils.gbasm22
7 files changed, 106 insertions, 44 deletions
diff --git a/entity/actions.gbasm b/entity/actions.gbasm
index 28f1cca..bcf89c1 100644
--- a/entity/actions.gbasm
+++ b/entity/actions.gbasm
@@ -245,14 +245,6 @@ Fox_AI:
LD A, $tmp_var_2
ADD $80
CP E
- PUSH AF
- PUSH HL
- LD HL, $9800
- LD A, $00
- RL A
- CALL =Print_8bit
- POP HL
- POP AF
JR Z =Fox_AI.No_movement
JR C =Fox_AI.Go_Up
diff --git a/main.gbasm b/main.gbasm
index 3462f72..d8c3c92 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -21,6 +21,9 @@ New_Dungeon:
HALT
JP =Wait_for_VRAM.loop
+Text_Astatin:
+ .DB 0x8a, 0x9c, 0x9d, 0x8a, 0x9d, 0x92, 0x97, 0xff
+
VBLANK_Entrypoint:
; Window enable
LD A, $reg_lcd_controller
@@ -37,7 +40,12 @@ VBLANK_Entrypoint:
CALL =Print_8bit
LD A, $68
- LD (HL), A
+ LD (HL+), A
+
+ INC HL
+
+ LD BC, =Text_Astatin
+ CALL =Print_str
CALL =Display_Prepared_Block
CALL =Display_Object
diff --git a/scripts/generate-tiledata.py b/scripts/generate-tiledata.py
index d0a963b..720191f 100644
--- a/scripts/generate-tiledata.py
+++ b/scripts/generate-tiledata.py
@@ -2,9 +2,9 @@ import subprocess
sprite_idx = 0x0
-def get_sprite_png_parse_output(png, tallmode=False):
+def get_sprite_png_parse_output(png, tallmode=False, sprite_1bpp_mode=False):
global sprite_idx
- result = str(subprocess.check_output(["python", "./scripts/parse_sprite_png.py", png] + (["--8x16"] if tallmode else []))).split("\\n")
+ result = str(subprocess.check_output(["python", "./scripts/parse_sprite_png.py", png] + (["--8x16"] if tallmode else []) + (["--1bpp"] if sprite_1bpp_mode else []))).split("\\n")
for r in result:
if r.startswith(".DB"):
print("\t{} ; 0x{:02x}".format(r, sprite_idx))
@@ -23,6 +23,10 @@ print("Small_sprites:")
print("\n\t; Heart")
get_sprite_png_parse_output("./sprites/bg/heart.png")
+sprite_idx = 0x80
+print("\nFont_Data:")
+get_sprite_png_parse_output("./sprites/font.png", sprite_1bpp_mode=True)
+
sprite_idx = 0x02
print("\nOBJ_Tile_Image_Data:")
print("\n\t; Bunny side")
diff --git a/scripts/parse_sprite_png.py b/scripts/parse_sprite_png.py
index f8d130a..5f9df9c 100644
--- a/scripts/parse_sprite_png.py
+++ b/scripts/parse_sprite_png.py
@@ -2,10 +2,9 @@ from PIL import Image
import numpy as np
import sys
-sprite_8x16 = False
+sprite_8x16 = "--8x16" in sys.argv
-if len(sys.argv) >= 3 and sys.argv[2] == "--8x16":
- sprite_8x16 = True
+sprite_1bpp = "--1bpp" in sys.argv
file = Image.open(sys.argv[1]).convert("RGB")
@@ -18,7 +17,7 @@ def getpx(sprite_nb, x, y):
sprite_tile_y = 1 if sprite_nb & 0b10 else 0
sprite_tile_x = 1 if sprite_nb & 0b01 else 0
- if sprite_8x16:
+ if sprite_8x16 or file.width < 16:
sprite_tile_x ^= sprite_tile_y
sprite_tile_y ^= sprite_tile_x
sprite_tile_x ^= sprite_tile_y
@@ -26,6 +25,10 @@ def getpx(sprite_nb, x, y):
sprite_line = sprite_double_line * 2 + sprite_tile_y
sprite_column = sprite_double_column * 2 + sprite_tile_x
+ if file.width < 16:
+ sprite_line = sprite_column * 2 + sprite_line
+ sprite_column = 0
+
return [int(x) for x in px_array[int(sprite_line * 8 + y)][int(sprite_column * 8 + x)]]
@@ -52,17 +55,23 @@ for nb in range(0, sprite_nb):
if abs(db) < min(abs(dw), abs(dlg), abs(ddg)):
print("#", end = '')
- if abs(ddg) < min(abs(dw), abs(dlg), abs(db)):
+ elif abs(ddg) < min(abs(dw), abs(dlg), abs(db)):
print(";", end = '')
- if abs(dlg) < min(abs(dw), abs(ddg), abs(db)):
+ elif abs(dlg) < min(abs(dw), abs(ddg), abs(db)):
print(".", end = '')
else:
print(" ", end = '')
print("\n", end = '')
print("\n")
for i in range(0, 8):
- if i == 0:
- print(".DB $%02x, $%02x" % (result1[i], result2[i]), end='')
+ if sprite_1bpp:
+ if i == 0:
+ print(".DB $%02x" % (result1[i]), end='')
+ else:
+ print(", $%02x" % (result1[i]), end='')
else:
- print(", $%02x, $%02x" % (result1[i], result2[i]), end='')
+ if i == 0:
+ print(".DB $%02x, $%02x" % (result1[i], result2[i]), end='')
+ else:
+ print(", $%02x, $%02x" % (result1[i], result2[i]), end='')
print("\n")
diff --git a/tiles.gbasm b/tiles.gbasm
index 48c5f91..1d8c03a 100644
--- a/tiles.gbasm
+++ b/tiles.gbasm
@@ -1,21 +1,3 @@
-Number_Font_Data:
- .DB $00, $38, $4c, $c6, $c6, $64, $38, $00 ; 0
- .DB $00, $18, $38, $18, $18, $18, $7e, $00 ; 1
- .DB $00, $7c, $c6, $0e, $7c, $e0, $fe, $00 ; 2
- .DB $00, $7e, $0c, $38, $06, $c6, $7c, $00 ; 3
- .DB $00, $1c, $3c, $6c, $cc, $fe, $0c, $00 ; 4
- .DB $00, $fc, $80, $fc, $06, $c6, $7c, $00 ; 5
- .DB $00, $7c, $c0, $fc, $c6, $c6, $7c, $00 ; 6
- .DB $00, $fe, $c6, $0c, $18, $30, $30, $00 ; 7
- .DB $00, $7c, $c6, $7c, $c6, $c6, $7c, $00 ; 8
- .DB $00, $7c, $c6, $c6, $7e, $06, $7c, $00 ; 9
- .DB $00, $3c, $46, $46, $7e, $46, $46, $00 ; A
- .DB $00, $7c, $46, $7c, $46, $46, $7c, $00 ; B
- .DB $00, $3c, $62, $60, $60, $62, $3c, $00 ; C
- .DB $00, $7c, $62, $62, $62, $62, $7c, $00 ; D
- .DB $00, $7e, $60, $7c, $60, $60, $7e, $00 ; E
- .DB $00, $7e, $60, $7c, $60, $60, $60, $00 ; F
-
Load_Tile:
LD HL, $8020
LD DE, =OBJ_Tile_Image_Data
@@ -30,15 +12,19 @@ Load_Tile:
Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x1f
- LD HL, $9100
- LD DE, =Number_Font_Data
- LD B, $80
+ LD HL, $8800
+ LD DE, =Font_Data
+ LD BC, $0158
Load_Number_Font.loop:
LD A, (DE)
LD (HL+), A
LD (HL+), A
INC DE
- DEC B
+ DEC BC
+ XOR A
+ CP B
+ JR NZ, =Load_Number_Font.loop
+ CP C
JR NZ, =Load_Number_Font.loop
RET
diff --git a/tileset.gbasm b/tileset.gbasm
index 235521b..7e4b09e 100644
--- a/tileset.gbasm
+++ b/tileset.gbasm
@@ -82,6 +82,51 @@ Small_sprites:
; Heart
.DB $00, $00, $6c, $6c, $fe, $fe, $fe, $fe, $7c, $7c, $38, $38, $10, $10, $00, $00 ; 0x68
+Font_Data:
+ .DB $00, $3c, $46, $46, $46, $46, $3c, $00 ; 0x80
+ .DB $00, $18, $38, $18, $18, $18, $7e, $00 ; 0x81
+ .DB $00, $3c, $46, $06, $1c, $30, $7e, $00 ; 0x82
+ .DB $00, $7c, $06, $3c, $06, $06, $7c, $00 ; 0x83
+ .DB $00, $0c, $1c, $2c, $4c, $7e, $0c, $00 ; 0x84
+ .DB $00, $7c, $40, $7c, $06, $06, $7c, $00 ; 0x85
+ .DB $00, $3c, $40, $7c, $46, $46, $3c, $00 ; 0x86
+ .DB $00, $7e, $06, $0c, $18, $18, $18, $00 ; 0x87
+ .DB $00, $3c, $46, $3c, $46, $46, $3c, $00 ; 0x88
+ .DB $00, $3c, $46, $46, $3e, $06, $3c, $00 ; 0x89
+ .DB $00, $3c, $46, $46, $7e, $46, $46, $00 ; 0x8a
+ .DB $00, $7c, $46, $7c, $46, $46, $7c, $00 ; 0x8b
+ .DB $00, $3e, $60, $60, $60, $60, $3e, $00 ; 0x8c
+ .DB $00, $7c, $46, $46, $46, $46, $7c, $00 ; 0x8d
+ .DB $00, $7e, $60, $78, $60, $60, $7e, $00 ; 0x8e
+ .DB $00, $7e, $60, $78, $60, $60, $60, $00 ; 0x8f
+ .DB $00, $3e, $60, $60, $66, $62, $3e, $00 ; 0x90
+ .DB $00, $46, $46, $7e, $46, $46, $46, $00 ; 0x91
+ .DB $00, $3c, $18, $18, $18, $18, $3c, $00 ; 0x92
+ .DB $00, $1e, $0c, $0c, $0c, $4c, $38, $00 ; 0x93
+ .DB $00, $66, $6c, $78, $78, $6c, $66, $00 ; 0x94
+ .DB $00, $60, $60, $60, $60, $60, $7e, $00 ; 0x95
+ .DB $00, $46, $6e, $56, $46, $46, $46, $00 ; 0x96
+ .DB $00, $46, $66, $56, $4e, $46, $46, $00 ; 0x97
+ .DB $00, $3c, $46, $46, $46, $46, $3c, $00 ; 0x98
+ .DB $00, $7c, $46, $46, $7c, $40, $40, $00 ; 0x99
+ .DB $00, $3c, $46, $46, $56, $4e, $3c, $02 ; 0x9a
+ .DB $00, $7c, $46, $46, $7c, $46, $46, $00 ; 0x9b
+ .DB $00, $3e, $60, $3c, $06, $06, $7c, $00 ; 0x9c
+ .DB $00, $7e, $18, $18, $18, $18, $18, $00 ; 0x9d
+ .DB $00, $46, $46, $46, $46, $46, $3c, $00 ; 0x9e
+ .DB $00, $46, $46, $46, $2c, $2c, $18, $00 ; 0x9f
+ .DB $00, $46, $46, $56, $56, $56, $3c, $00 ; 0xa0
+ .DB $00, $46, $2c, $18, $18, $2c, $46, $00 ; 0xa1
+ .DB $00, $46, $46, $3c, $18, $18, $18, $00 ; 0xa2
+ .DB $00, $7e, $06, $0c, $18, $30, $7e, $00 ; 0xa3
+ .DB $00, $00, $00, $00, $00, $18, $18, $00 ; 0xa4
+ .DB $00, $18, $18, $18, $18, $00, $18, $00 ; 0xa5
+ .DB $00, $3c, $66, $06, $1c, $00, $18, $00 ; 0xa6
+ .DB $00, $00, $00, $00, $00, $18, $08, $00 ; 0xa7
+ .DB $00, $18, $18, $30, $00, $00, $00, $00 ; 0xa8
+ .DB $00, $2c, $2c, $2c, $00, $00, $00, $00 ; 0xa9
+ .DB $00, $18, $18, $00, $00, $18, $18, $00 ; 0xaa
+
OBJ_Tile_Image_Data:
; Bunny side
diff --git a/utils.gbasm b/utils.gbasm
index 857acbc..5dad3a9 100644
--- a/utils.gbasm
+++ b/utils.gbasm
@@ -38,18 +38,36 @@ Print_8bit: ; Number in A, Memory Tilemap position in HL
LD C, A
SWAP A ; We start by the highest nibble
AND $0f
- OR $10
+ OR $80
LD (HL+), A
LD A, C
AND $0f ; Then the lowest
- OR $10
+ OR $80
LD (HL+), A
POP BC
POP AF
RET
+Print_str: ; Memory Tilemap position in HL, Text address in BC, FF ended
+ PUSH AF
+ PUSH BC
+
+ Print_str.loop:
+ LD A, (BC)
+ CP $ff
+ JR Z, =Print_str.end
+
+ LD (HL+), A
+ INC BC
+ JR =Print_str.loop
+
+ Print_str.end:
+ POP BC
+ POP AF
+ RET
+
MUL: ; B x C => EA
XOR A
LD E, $00