FantomoUDG
Description of the page content
Command line tools to convert UDG of ZX Spectrum and other systems.
Tags:
Description
FantomoUDG is a small set of command line tools that convert so called UDG (User Defined Graphics), which are 8x8-pixel characters used by ZX Spectrum and other 8-bit computers. The set will grow following the requirements of other projects that need to manipulate UDG. The goal is to make it easy to include UDG in Forth and assembly sources. FantomoUDG is written in Forth with Gforth.Name
"FantomoUDG" stands for "Forth ANomalistic Tools Of Manipulation Of UDG", where "UDG" stands for "User Defined Graphics"; beside, "fantomo" is the Esperanto word for "ghost".History
Some simple tools to manipulate and convert UDG were written in 2011, 2013 and 2015, for specific needs. In 2016 the tools were put together to prepare a coherent toolkit, and a Git repository was created from development backups in order to resume the development.Source code
udg_defb_to_forth
#! /usr/bin/env gforth
\ udg_defb_to_forth.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612211827
\ ==============================================================
\ Description
\ This Forth program converts Z80 assembler 'defb' directives,
\ with binary numbers representing User Defined Graphics, to hex
\ data ready to be used in a Forth program.
\
\ The `udg!` word is used in the output code, which is suitable
\ for Solo Forth.
\ Input format example:
\ ;; á
\ defb %00001000
\ defb %00010000
\ defb %00111000
\ defb %00000100
\ defb %00111100
\ defb %01000100
\ defb %00111100
\ defb %00000000
\ Output:
\ $08 $10 $38 $04 $3C $44 $3C $00 #128 udg! \ á
\ ==============================================================
\ Usage
\ See <udg_defb_to_forth.demo.fs> for a usage example.
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2015, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2015-03-20: First version.
\
\ 2015-03-23: Add '90 UDG!' as default (graphic char and
\ defininig word).
\
\ 2016-12-21: Update file header and source layout. Factor,
\ improve and comment the code. Add an increasing UDG code and
\ make the first one configurable. Extract the data to their
\ own file, as a demo.
\ ==============================================================
\ Main
variable udg 128 udg ! \ char code of the first UDG
8 constant scans/udg
variable scans scans off \ counter
2variable udg-name
: ;; ( "name" -- ) parse-name save-mem udg-name 2! ;
: .scan ( n -- )
s>d hex <# # # '$' hold #> type space decimal ;
: get-scan ( "name" -- n ) parse-name evaluate ;
: last-scan? ( -- f ) scans @ scans/udg = ;
: next-scan ( -- ) 1 scans +! ;
: next-udg ( -- ) 1 udg +! scans off ;
: .udg ( n -- ) s>d space <# # # # '#' hold #> type space ;
: .udg-name ( -- ) ." \ " udg-name 2@ type cr ;
: .store-udg ( -- ) udg @ .udg ." udg!" ;
: finish-udg ( -- ) .store-udg .udg-name next-udg ;
: defb ( "number" -- )
get-scan .scan next-scan last-scan? if finish-udg then ;
#! /usr/bin/env gforth
\ udg_defb_to_forth.demo.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612211827
\ ==============================================================
\ Description
\ Demo of the <udg_defb_to_forth.fs> converter.
\ This source converts UDG defined in Z80 assembly `defb`
\ directives to to Forth notation, suitable for Solo Forth.
\
\ Note the Z80 assembly comment character, ";", has been
\ duplicated.
\ ==============================================================
\ Usage
\ ./udg_defb_to_forth.demo.fs > output_file.fs
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2015, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2016-12-21: Extract from <udg_defb_to_forth.fs>.
\ ==============================================================
include udg_defb_to_forth.fs
160 udg !
;; á
defb %00001000
defb %00010000
defb %00111000
defb %00000100
defb %00111100
defb %01000100
defb %00111100
defb %00000000
;; Á
defb %00000100
defb %00001000
defb %00111100
defb %01000010
defb %01111110
defb %01000010
defb %01000010
defb %00000000
;; é
defb %00001000
defb %00010000
defb %00111000
defb %01000100
defb %01111000
defb %01000000
defb %00111100
defb %00000000
;; É
defb %00000100
defb %00001000
defb %01111110
defb %01000000
defb %01111100
defb %01000000
defb %01111110
defb %00000000
;; í
defb %00001000
defb %00010000
defb %00000000
defb %00110000
defb %00010000
defb %00010000
defb %00111000
defb %00000000
;; Í
defb %00000100
defb %00001000
defb %00111110
defb %00001000
defb %00001000
defb %00001000
defb %00111110
defb %00000000
;; ó
defb %00001000
defb %00010000
defb %00111000
defb %01000100
defb %01000100
defb %01000100
defb %00111000
defb %00000000
;; Ó
defb %00001000
defb %00010000
defb %00111100
defb %01000010
defb %01000010
defb %01000010
defb %00111100
defb %00000000
;; ú
defb %00001000
defb %00010000
defb %01000100
defb %01000100
defb %01000100
defb %01000100
defb %00111000
defb %00000000
;; Ú
defb %00000100
defb %01001010
defb %01000010
defb %01000010
defb %01000010
defb %01000010
defb %00111100
defb %00000000
;; ñ
defb %00000000
defb %01111000
defb %00000000
defb %01111000
defb %01000100
defb %01000100
defb %01000100
defb %00000000
;; Ñ
defb %00111100
defb %00000000
defb %01100010
defb %01010010
defb %01001010
defb %01000110
defb %01000010
defb %00000000
;; ü
defb %01000100
defb %00000000
defb %01000100
defb %01000100
defb %01000100
defb %01000100
defb %00111000
defb %00000000
;; Ü
defb %01000010
defb %00000000
defb %01000010
defb %01000010
defb %01000010
defb %01000010
defb %00111100
defb %00000000
;; ¿
defb %00000000
defb %00010000
defb %00000000
defb %00010000
defb %00100000
defb %01000010
defb %00111100
defb %00000000
;; ¡
defb %00000000
defb %00001000
defb %00000000
defb %00001000
defb %00001000
defb %00001000
defb %00001000
defb %00000000
;; º
defb %00011000
defb %00100100
defb %00011000
defb %00000000
defb %00111100
defb %00000000
defb %00000000
defb %00000000
;; «
defb %00000000
defb %00000000
defb %00010010
defb %00100100
defb %01001000
defb %00100100
defb %00010010
defb %00000000
;; »
defb %00000000
defb %00000000
defb %01001000
defb %00100100
defb %00010010
defb %00100100
defb %01001000
defb %00000000
bye
udg_tap_to_forth_c-comma
#! /usr/bin/env gforth
\ udg_tap_to_forth_c-comma.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612212324
\ ==============================================================
\ Description
\ This program converts a ZX Spectrum TAP file, containing User
\ Defined Graphics, to a Forth source that stores the graphics
\ into Forth data space using the `c,` word, one graphic per
\ line.
\ ==============================================================
\ Usage
\ ./udg_tap_to_forth_c-comma.fs input_file.tap > output_file.fs
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2015, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2016-12-21: Start.
\ ==============================================================
\ Main
variable scans \ counter
8 constant scans/udg
: .scan ( n -- )
base @ >r s>d hex <# # # '$' hold #> type space r> base ! ;
: last-scan? ( -- f ) scans @ scans/udg = ;
: next-scan ( -- ) 1 scans +! ;
: new-udg ( -- ) scans off cr ;
: udgs>forth ( ca len -- )
new-udg bounds ?do
i c@ .scan ." c, " next-scan last-scan? if new-udg then
loop ;
\ Convert the UDG definitions contained in the memory zone
\ _ca len_ (8 bytes per UDG) to Forth source printed to
\ standard output.
: behead ( ca1 len1 -- ca2 len2 ) 24 /string 1- ;
\ Remove the TAP file header from the TAP file contents _ca1
\ len1_, and the checksum byte of the data block, resulting a string
\ _ca2 len2_ that contains only the actual data of the file.
: udgtap>forth ( ca len -- ) slurp-file behead udgs>forth ;
\ Convert the UDGs contained in TAP file _ca len_ to Forth
\ source printed to standard output.
1 arg udgtap>forth bye
#! /usr/bin/env gforth
\ udg_tap_to_forth.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612212324
\ ==============================================================
\ Description
\ This program converts a ZX Spectrum TAP file, containing User
\ Defined Graphics, to hex data ready to be used in a Forth
\ program.
\ ==============================================================
\ Usage
\ ./udg_tap_to_forth.fs input_file.tap > output_file.fs
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2015, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2015-03-23: Start.
\
\ 2016-03-01: Fix, improve.
\
\ 2016-12-21: Update file header and source layout. Fix `hex8.`,
\ `next-udg`, `behead`. Factor.
\ ==============================================================
\ Main
variable scans \ counter
variable udg \ counter
144 constant first-udg
8 constant scans/udg
: .scan ( n -- )
base @ >r s>d hex <# # # '$' hold #> type space r> base ! ;
: last-scan? ( -- f ) scans @ scans/udg = ;
: next-scan ( -- ) 1 scans +! ;
: next-udg ( -- ) 1 udg +! scans off ;
: .udg ( n -- ) s>d space <# # # # '#' hold #> type space ;
: .store-udg ( -- ) udg @ .udg ." udg!" cr ;
: finish-udg ( -- ) .store-udg next-udg ;
: init ( -- ) scans off first-udg udg ! ;
: udgs>forth ( ca len -- )
init bounds ?do
i c@ .scan next-scan last-scan? if finish-udg then
loop ;
\ Convert the UDG definitions contained in the memory zone
\ _ca len_ (8 bytes per UDG) to Forth source printed to
\ standard output.
: behead ( ca1 len1 -- ca2 len2 ) 24 /string 1- ;
\ Remove the TAP file header from the TAP file contents _ca1
\ len1_, and the checksum byte of the data block, resulting a string
\ _ca2 len2_ that contains only the actual data of the file.
: udgtap>forth ( ca len -- ) slurp-file behead udgs>forth ;
\ Convert the UDGs contained in TAP file _ca len_ to Forth
\ source printed to standard output.
1 arg udgtap>forth bye
udg_ti99_to_bin
#! /usr/bin/env gforth
\ udg_ti99_to_bin.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612211827
\ ==============================================================
\ Description
\ This program converts TI BASIC UDGs (for TI-99 computers) to
\ 8x8 binary grids.
\ Input format example:
\ s" 183C3CFF3C3C3C3C" chardef
\ Output:
\ 00011000
\ 00111100
\ 00111100
\ 11111111
\ 00111100
\ 00111100
\ 00111100
\ 00111100
\ ==============================================================
\ Usage
\ See <udg_ti99_to_bin.demo.fs> for a usage example.
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2013, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2013-01-17: First version.
\
\ 2016-12-21: Update file header and source layout. Improve
\ documentation and code. Extract the data to their own file, as
\ a demo.
\ ==============================================================
: binary ( -- ) 2 base ! ;
: row ( ud -- )
base @ >r binary <# # # # # # # # # #> type cr r> base ! ;
\ Print the UDG row _ud_.
: chardef ( ca len -- )
base @ >r hex
bounds do
0. i 2 >number 2drop row
2 +loop cr
r> base ! ;
\ Print the binary pattern of a TI-99 character definition,
\ defined as 16 hex digits in the string _ca len_.
#! /usr/bin/env gforth
\ udg_ti99_to_bin.demo.fs
\ This file is part of FantomoUDG
\ http://programandala.net/en.program.fantomoudg.html
\ Last modified 201612211827
\ ==============================================================
\ Description
\ Demo of the <udg_ti99_to_bin.fs> converter.
\ This program converts some example TI BASIC UDGs (for TI-99
\ computers) to 8x8 binary grids.
\ ==============================================================
\ Usage
\ ./udg_ti99_to_bin.demo.fs > output_file.fs
\ ==============================================================
\ Author
\ Marcos Cruz (programandala.net), 2013, 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain every copyright, credit and authorship notice, and this
\ license. There is no warranty.
\ ==============================================================
\ History
\ 2016-12-21: Extract from <udg_ti99_to_bin.fs>.
\ ==============================================================
include udg_ti99_to_bin.fs
s" 183C3CFF3C3C3C3C" chardef
s" 472F1F3E7CFA7120" chardef
s" 0808FEFFFFFE0808" chardef
s" 2071FA7C3E1F2F47" chardef
s" 3C3C3C3CFF3C3C18" chardef
s" 048E5F3E7CF8F4E2" chardef
s" 10107FFFFF7F1010" chardef
s" E2F4F87C3E5F8E04" chardef
s" 0000001818000000" chardef
s" 187C7CFFFFFF5E1C" chardef
s" 003C203820202000" chardef
s" 001824202C241800" chardef
bye
Download
You can download FantomoUDG in GitHub.