aboutsummaryrefslogtreecommitdiff
path: root/player
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-04-17 22:05:24 +0100
committerJuan J. Martinez <jjm@usebox.net>2021-04-17 22:05:24 +0100
commita5745813e442b66ae6eed30bba81d1b3dd5cf634 (patch)
treeb302db1780350dc44543b81d49bfc1b2d4dff6a8 /player
downloadbeeper-int-zx-a5745813e442b66ae6eed30bba81d1b3dd5cf634.tar.gz
beeper-int-zx-a5745813e442b66ae6eed30bba81d1b3dd5cf634.zip
Initial public release
Diffstat (limited to 'player')
-rw-r--r--player/Makefile20
-rw-r--r--player/README.md13
-rwxr-xr-xplayer/bin2h.py40
-rw-r--r--player/player.z8093
4 files changed, 166 insertions, 0 deletions
diff --git a/player/Makefile b/player/Makefile
new file mode 100644
index 0000000..c837be5
--- /dev/null
+++ b/player/Makefile
@@ -0,0 +1,20 @@
+all: player.bin
+
+CC = sdcc
+AS = sdasz80
+AR = sdar
+CFLAGS = -mz80 --Werror --fsigned-char --std-sdcc99 --opt-code-speed
+LDFLAGS = --no-std-crt0 --fomit-frame-pointer
+
+%.rel: %.z80
+ $(AS) -g -o $@ $<
+
+player.bin: player.rel
+ $(CC) $(CFLAGS) $(LDFLAGS) --code-loc 20480 --data-loc 0 -o player.ihx $<
+ hex2bin -p 00 player.ihx
+ ./bin2h.py player.bin player > ../player.h
+
+.PHONY: clean
+clean:
+ rm -f *.rel *.ihx *.bin *.map *.noi *.lk
+
diff --git a/player/README.md b/player/README.md
new file mode 100644
index 0000000..d9f0c96
--- /dev/null
+++ b/player/README.md
@@ -0,0 +1,13 @@
+This builds a player to be run from sfxed emulator.
+
+Changing this is not completely supported, but if you really want to do it, it
+is possible!
+
+## Build instructions
+
+This requires in your PATH:
+
+* SDCC
+* Python 3
+* hex2bin; for example [you can use this version](https://github.com/reidrac/ubox-msx-lib/tree/master/tools/hex2bin-2.0)
+
diff --git a/player/bin2h.py b/player/bin2h.py
new file mode 100755
index 0000000..d0395fd
--- /dev/null
+++ b/player/bin2h.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+from argparse import ArgumentParser
+
+__version__ = "1.0"
+
+
+def main():
+
+ parser = ArgumentParser(description="Bin to H converter",
+ epilog="Copyright (C) 2014-2021 Juan J Martinez <jjm@usebox.net>",
+ )
+
+ parser.add_argument("--version", action="version",
+ version="%(prog)s " + __version__)
+ parser.add_argument("file", help="file to convert")
+ parser.add_argument("id", help="variable to use")
+
+ args = parser.parse_args()
+
+ with open(args.file, "rb") as fd:
+ data = bytearray(fd.read())
+
+ data_out = ""
+ for part in range(0, len(data), 8):
+ if data_out:
+ data_out += ",\n"
+ data_out += ', '.join(["0x%02x" % b for b in data[part: part + 8]])
+
+ print("/* file: %s */" % args.file)
+ print("#define %s_LEN %d\n" % (args.id.upper(), len(data)))
+ print("#ifdef LOCAL")
+ print("const unsigned char %s[] = {\n%s\n};\n" % (args.id, data_out))
+ print("#else")
+ print("extern const unsigned char %s[];\n" % args.id)
+ print("#endif")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/player/player.z80 b/player/player.z80
new file mode 100644
index 0000000..d6fed1a
--- /dev/null
+++ b/player/player.z80
@@ -0,0 +1,93 @@
+ISR_TABLE_START = 0xfe00
+ISR_TABLE_START_LO = 0xfe
+ISR_TABLE_VALUE = 0xfd
+ISR_TABLE_START_JP = 0xfdfd
+
+EFX_TABLE_ADDR = 32000
+EFX_IN_ADDR = EFX_TABLE_ADDR - 1
+
+.area _HOME
+.area _CODE
+.area _INITIALIZER
+.area _GSINIT
+.area _GSFINAL
+
+.area _DATA
+.area _INITIALIZED
+.area _BSEG
+.area _BSS
+.area _HEAP
+
+.area _CODE
+
+_main::
+ di
+ ld sp, #0
+ ei
+
+ ld hl, #EFX_TABLE_ADDR
+ ld (sfx_data), hl
+
+ ld hl, #ISR_TABLE_START
+ ld (hl), #ISR_TABLE_VALUE
+ ld e, l
+ ld d, h
+ inc de
+ ld bc, #257
+ ldir
+
+ ld a, #ISR_TABLE_START_LO
+ ld i, a
+ im 2
+
+ ld hl, #ISR_TABLE_START_JP
+ ld de, #isr
+ ld a, #0xc3
+ ld (hl), a
+ inc hl
+ ld (hl), e
+ inc hl
+ ld (hl), d
+ ei
+
+ ld a, (EFX_IN_ADDR)
+ ld l, a
+ call _beeper_queue
+
+wait::
+ ld a, (sfx_type)
+ or a
+ jr nz, wait
+
+ halt
+ halt
+ halt
+ halt
+
+ out (0xff), a
+
+ di
+ halt
+
+isr:
+ ex af,af
+ push hl
+ push ix
+ push iy
+ push bc
+ push de
+
+ call _beeper_play
+
+ pop de
+ pop bc
+ pop iy
+ pop ix
+ pop hl
+ ex af,af
+ ei
+
+ ret
+
+.include "../sdcc/beeper.z80"
+