software/keymap: added `Makefile`

This commit is contained in:
Ivan Tatarinov 2021-06-11 20:40:58 +03:00
parent 032664e42d
commit 6d19576ef0
5 changed files with 263 additions and 122 deletions

View File

@ -44,6 +44,10 @@
define cold_boot $fe
define core_id $ff
; Aliases
ZXUNOADDR: equ zxuno_port
ZXUNODATA: equ zxuno_data
; MMC/SDC interface:
define SPI_PORT $eb
define OUT_PORT $e7

View File

@ -28,10 +28,11 @@ prefix ?= .
SUBDIRS=\
dmaplayw\
esxdos\
esprst\
esxdos\
iwconfig\
joyconf\
iwconfig
keymap
.PHONY: all
all: build

5
software/keymap/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
#
# SPDX-License-Identifier: CC0-1.0
build

82
software/keymap/Makefile Normal file
View File

@ -0,0 +1,82 @@
# SPDX-FileCopyrightText: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Supported environments:
# * GNU on Linux, FreeBSD etc.
# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL)
#
# Build:
# make [<TARGET> ...]
# Install / Uninstall:
# make [prefix=<PREFIX>] install | uninstall
# Clean:
# make clean | distclean
#
# where:
# <TARGET> is one of values for `BINS' variable prefixed with "build/"
# (see target `all' below).
# <PREFIX> is a prefix directory to install files into.
include ../../sdk/common.mk
srcdir = .
# Use uppercase for FAT filesystem
prefix ?= .
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/BIN
INSTALL ?= install
INSTALL_PROGRAM ?= $(INSTALL)
RM = rm -f
INCLUDEDIR = ../../sdk/include
AS = sjasmplus
ifeq ($(USE_SJASMPLUS_VERSION),sjasmplus)
AFLAGS = --nobanner
else ifeq ($(USE_SJASMPLUS_VERSION),z00m128)
AFLAGS = --nologo
else
AFLAGS =
endif
AFLAGS += -I$(INCLUDEDIR)
BINS=\
KEYMAP
.PHONY: all
all: $(foreach t,$(BINS),build/$(t))
build\
$(DESTDIR)$(bindir):
mkdir -p $@
build/KEYMAP: $(srcdir)/keymap.asm\
$(INCLUDEDIR)/zxuno.def\
$(INCLUDEDIR)/esxdos.def\
| build
$(AS) $(AFLAGS) --raw=$@ $<
# $1 = target
# No need in execution mode for FAT filesystem
define install_bin_rule =
$$(DESTDIR)$$(bindir)/$1: build/$1 | $$(DESTDIR)$$(bindir)
$$(INSTALL_PROGRAM) -m 644 $$< $$@
endef
$(foreach t,$(BINS),$(eval $(call install_bin_rule,$(t))))
.PHONY: install
install: $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t))
.PHONY: uninstall
uninstall:
$(RM) $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t))
.PHONY: clean
clean:
rm -f $(foreach t,$(BINS),build/$(t))
.PHONY: distclean
distclean:
rm -rf build

View File

@ -1,120 +1,169 @@
; API de ESXDOS.
include "esxdos.inc"
include "errors.inc"
; KEYMAP. Una utilidad para cargar un mapa de teclado en el ZX-Uno
; Necesita sólamente un nombre de fichero de mapa, que debe estar
; guardado en /SYS/KEYMAPS dentro de la tarjeta SD donde esté ESXDOS.
;Para ensamblar con PASMO como archivo binario (no TAP)
ZXUNOADDR equ 0fc3bh
ZXUNODATA equ 0fd3bh
org 2000h ;comienzo de la ejecución de los comandos ESXDOS.
Main proc
ld a,h
or l
jr z,PrintUso ;si no se ha especificado nombre de fichero, imprimir uso
call RecogerNFile
call ReadMap
ret
PrintUso ld hl,Uso
BucPrintMsg ld a,(hl)
or a
ret z
rst 10h
inc hl
jr BucPrintMsg
endp
RecogerNFile proc ;HL apunta a los argumentos (nombre del fichero)
ld de,BufferNFich
CheckCaracter ld a,(hl)
or a
jr z,FinRecoger
cp " "
jr z,FinRecoger
cp ":"
jr z,FinRecoger
cp 13
jr z,FinRecoger
ldi
jr CheckCaracter
FinRecoger xor a
ld (de),a
inc de ;DE queda apuntando al buffer este que se necesita en OPEN, no sé pa qué.
ret
endp
ReadMap proc
xor a
rst 08h
db M_GETSETDRV ;A = unidad actual
ld b,FA_READ ;B = modo de apertura
ld hl,MapFile ;HL = Puntero al nombre del fichero (ASCIIZ)
rst 08h
db F_OPEN
ret c ;Volver si hay error
ld (FHandle),a
ld bc,ZXUNOADDR
ld a,7
out (c),a ;select KEYMAP register
ld b,4 ;4 chunks of 4096 bytes each to load
BucReadMapFromFile push bc
ld bc,4096
ld hl,Buffer
ld a,(FHandle)
rst 08h
db F_READ
jr c,PrematureEnd ;si error, fin de lectura
ld hl,Buffer
ld bc,ZXUNODATA
ld de,4096
BucWriteMapToFPGA ld a,(hl)
out (c),a
inc hl
dec de
ld a,d
or e
jr nz,BucWriteMapToFPGA
pop bc
djnz BucReadMapFromFile
jr FinReadMap
PrematureEnd pop bc
push af
ld a,(FHandle)
rst 08h
db F_CLOSE
pop af
ret
FinReadMap ld a,(FHandle)
rst 08h
db F_CLOSE
or a ;Volver sin errores a ESXDOS
ret
endp
; 01234567890123456789012345678901
Uso db " KEYMAP file",13,13
db "Loads the specified keymap from",13
db "/SYS/KEYMAPS and enables it.",13,0
FHandle db 0
Buffer ds 4096 ;4KB para buffer de lectura
MapFile db "/SYS/KEYMAPS/"
BufferNFich equ $ ;resto de la RAM para el nombre del fichero
; keymap - utility for loading a keymap into the ZX-Uno. You only need a map
; filename, which must be saved in `/SYS/KEYMAPS' inside the SD card where
; ESXDOS is.
;
; Copyright (C) 2016-2021 Antonio Villena
; Contributors:
; 2021 Ivan Tatarinov <ivan-tat@ya.ru>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, version 3.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
;
; SPDX-FileCopyrightText: Copyright (C) 2016-2021 Antonio Villena
;
; SPDX-FileContributor: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
;
; SPDX-License-Identifier: GPL-3.0-only
; Compatible compilers:
; SJAsmPlus, <https://github.com/sjasmplus/sjasmplus/>
; output KEYMAP
define PROGRAM "keymap"
define VERSION "0.1"
include "zxuno.def"
include "esxdos.def"
define KEYMAPPATH "/SYS/KEYMAP"
define FNAMESIZE 1024 ; will it be enough?
define FBUFSIZE 4096 ; 4KB file buffer
org $2000 ; entry point of ESXDOS program
;-----------------------------------------------------------------------------
; Subroutine
; In: HL = pointer to the command line arguments string (ASCIIZ)
Main: ld a, h
or l
jr nz, Init
; jr ShowUsage ; No need, it follows
;-----------------------------------------------------------------------------
; Subroutine
ShowUsage: ld hl, aUsage
; jr Print ; No need, it follows
;-----------------------------------------------------------------------------
; Subroutine
; In: HL = pointer to an ASCIIZ string
Print: ld a, (hl)
or a
ret z
rst $10
inc hl
jr Print
;-----------------------------------------------------------------------------
; Subroutine
; In: HL = pointer to the command line arguments string (ASCIIZ)
Init: ld de, FileName
; call GetFileName ; inline
;-----------------------------------------------------------------------------
; Subroutine
; In: HL = pointer to the command line arguments (filename)
; DE = pointer to the output ASCIIZ string (filename)
; Out: DE = pointer to terminating 0 character of output string
.GetFileName: ld a, (hl)
or a
jr z, .End
cp " "
jr z, .End
cp ":"
jr z, .End
cp 13
jr z, .End
ldi
jr .GetFileName
.End: xor a
ld (de),a
; ret ; skipped
; continue Init()
inc de ; DE remains pointing to the buffer that is
; needed in OPEN, I don't know what for
; jr ReadMap ; No need, it follows
;-----------------------------------------------------------------------------
; Subroutine
; In: DE = pointer to the buffer that is needed in OPEN, I don't know what for
ReadMap: xor a
esxdos M_GETSETDRV ; A = current drive
ld b, FA_READ ; B = file open mode
ld hl, FilePath ; HL = pointer to a filename (ASCIIZ)
esxdos F_OPEN
ret c ; Return on error
ld (FileHandle), a
ld bc, ZXUNOADDR
ld a, key_map ; Select KEYMAP register
out (c), a
ld b, 4 ; 4 chunks of FBUFSIZE bytes each to load
.ReadMapFromFileLoop:
push bc ; Save counter
ld bc, FBUFSIZE
ld hl, FileBuffer
ld a, (FileHandle)
esxdos F_READ
jr c, .Error ; End reading on error
ld hl, FileBuffer
ld bc, ZXUNODATA
ld de, FBUFSIZE
.WriteMapToFPGALoop:
ld a, (hl)
out (c), a
inc hl
dec de
ld a, d
or e
jr nz, .WriteMapToFPGALoop
pop bc ; Restore counter
djnz .ReadMapFromFileLoop
jr .ReadMapDone
.Error: pop bc ; Restore stack
push af ; Save error status
ld a, (FileHandle)
esxdos F_CLOSE
pop af ; Restore error status
ret
.ReadMapDone: ld a, (FileHandle)
esxdos F_CLOSE
or a ; Return to ESXDOS without errors (CY=0)
ret
; 01234567890123456789012345678901
aUsage: db " .", PROGRAM, " file", 13
db 13
db "Loads the specified keymap from", 13
db KEYMAPPATH, " and enables it.", 13, 0
FileHandle: db 0
FilePath: db KEYMAPPATH, "/"
FileName: ; File name buffer
org $+FNAMESIZE
FileBuffer: ; File data buffer