MGTize

Priskribo de la ĉi-paĝa enhavo

Programo por faciligi la uzon de pyz80 por krei disked-kopian MGT-dosierojn por SAM Coupé.

Etikedoj:

MGTize estas envolvaĵo por pyz80, de Andrew Collier, Z80-asemblilo fokusita en transprogramado por SAM Coupé. La celo de MGTize estas plifaciligi la kreon de disked-kopiaj MGT-dosieroj per pyz80.

Por krei disked-kopian MGT-dosieron per pyz80 endas aparte mencii ĉiun dosieron per la parametrilo -I, kaj krome Z80-dosieron asembli, eĉ malplenan: necesas ion asembli. Do la komanda linio povas tre longiĝi:

touch empty.z80s
pyz80 -I pict1.png -I pict2.pbm -I pict3.pgm -I pict4.ppm -I too.jpg -o result.mgt.gz empty.z80s
rm empty.z80s

MGTize plifaciligas tion: La una parametro esta la nomo de la nova MGT-dosiero (kies sufikso «.mgt.gz» estos poste aldonita aŭ kompletigita senecese; jama samnoma dosiero estos forviŝita). Ceteraj parametroj estas nomoj de inkludendaj dosieroj, kaj eblas uzi ŝablonojn de la sistema komandlinio: Kompreneble, ne necesas dosieron de Z80-fontprogramo: MGTize kreas unu malplenan dosieron, kiu estos «asemblita» kaj forviŝita. Ekzemple, jen la koresponda supra ezkemplo per MGTize:

mgtize result pict?.p* too.jpg

MGTize estas verkita Fortho per Gforth. Ĝi bezona du Forthajn bibliotekojn: Forth Foundation Library kaj Galope (ankore ne publikigita, sed la necesaj difinoj estas inkluditaj en la fontprogramo).

En la fontprogramo estas inkluditaj, kiel komentaro, simplaj angla-lingvaj instal-instrukcioj.

Fontkodo

#! /usr/bin/env gforth

\ mgtize.fs
\ MGTize (version B-00-20150809)
\ This program creates SAMDOS MGT disk images.

\ Copyright (C) 2012 Marcos Cruz (programandala.net)

\ MGTize 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; either version 2 of the License, or
\ (at your option) any later version. See:
\
\ MGTize 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 http://www.gnu.org/licenses/.

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Description

\ MGTize creates a gzip-compressed SAMDOS MGT disk image with the
\ desired files.  The MGT disk image can be used with SimCoupe, the
\ SAM Coupé emulator (<http://simcoupe.org>), or copied to a diskette.
\
\ MGTize is a wrapper for Andrew Collier's pyz80 (version 1.1,
\ 2007-04-13): <http://www.intensity.org.uk/samcoupe/pyz80.html>.
\
\ MGTize was written to make it easier to use pyz80 when you just want
\ to create a MGT disk image with several files, not to compile any
\ Z80 code. 
\
\ MGTize is written in Forth with Gforth:
\ <http://gnu.org/software/gforth>,
\ <http://www.complang.tuwien.ac.at/forth/gforth/>.

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Installation on Linux systems

\ 1. Gforth (http://gnu.org/software/gforth) and the Forth Foundation
\ Library (http://irdvo.github.io/ffl/) must be installed.
\
\ 2. Make sure this source file is executable, with the following
\ command:
\
\   chmod ugo+x mgtize.fs
\
\ 3. Copy, move or link this source file to your path (ussually to
\ </usr/local/bin/>), with the desired name (e.g. without the
\ extension). Example command:
\
\   sudo ln mgtize.fs /usr/local/bin/mgtize

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ History

\ 2012-12-09: Version A-00-20121209.
\ 2012-12-10: Version A-01-20121210. Improved: the file extension
\ is added or completed when needed; better arguments check;
\ clearer usage instructions.
\ 2013-07-07: Typo fixed.
\ 2013-07-28: Change in '+extension'.
\ 2014-05-29: Changed the stack notation of strings. New: 'fpath'.
\ 2015-01-10: Changes in comments and header.
\ 2015-08-07: The Galope definitions are pasted insted of included,
\ until the library is published. Version B-00.
\ 2015-08-09: Installation instructions.

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Requirements

\ fpath path+ ~/forth  \ XXX OLD TMP -- until the next version of Gforth supports <~/.gforthrc>

\ From Galope
\ (<http://programandala.net/en.program.galope.html>)

\ require galope/ends-question.fs  \ 'ends?'
\ require galope/sconstant.fs  \ 'sconstant'
\ require galope/svariable.fs  \ 'svariable'

\ XXX TMP -- pasted:

: fourth  ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 )
  \ Copy fourth element on the stack onto top of stack.
  3 pick
  ;
: ends? ( ca1 len1 ca2 len2 -- ca1 len1 wf )
  \ Check end of string:
  \ Is ca2 len2 the end of ca1 len1?
  \ ca1 len1 = long string
  \ ca2 len2 = end to check
  2over  dup fourth - /string  compare 0=
  ;
: sconstant  (  a len "name" -- )
  create  s,
  does>  ( -- a len ) ( pfa ) count
  ;
s" /COUNTED-STRING" environment? 0= [if]  255  [then]
constant /counted-string
: svariable  ( "name" -- )
  \ Create a string variable.
  create 0 c, /counted-string allot align
  ;

\ From Forth Foundation Library
\ (<http://code.google.com/p/ffl/>)
require ffl/str.fs  \ dynamic strings

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ System

\ The Forth Foundation Library's config.fs file nullifies the
\ words 'argc' and 'arg', and defines its own versions '#args'
\ and 'arg@'.

[defined] ffl.version [if]

  \ Re-create the original Gforth words 'argc' and 'arg', based
  \ on the words defined by the Forth Foundation Library's
  \ config.fs. 

  warnings @ warnings off

  variable argc  #args 1+ argc !
  : arg  ( n -- a u )
    1- arg@
    ;

  warnings !

[then]

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Variables and constants

svariable mgt-file
svariable input-file
s" mgtize.fs" sconstant command  \ name of this file

\ Temporary empty file used as fake assembler file for pyz80:
s" .tmp-" command s+  s" -.z80s" s+ sconstant z80-file

variable z80-file-id

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Strings

: s&  ( ca1 len1 ca2 len2 -- ca3 len3 )
  \ Concatenate two strings adding a space between them.
  2>r s"  " s+ 2r> s+
  ;
: str-space-escape  ( str -- )
  \ Replace all spaces of a dynamic string with escaped spaces.
  \ str = dynamic string address
  >r s" \ " s"  " r> str-replace
  ;
str-create tmp-str
: escaped  ( ca1 len1 -- ca2 len2 )
  \ Escape all the spaces of a string.
  tmp-str str-set
  tmp-str str-space-escape
  tmp-str str-get
  ;

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ pyz80 and its parameters

: -i-parameters  ( -- a u )
  \ Return a string with all '-I' parameters required by pyz80.
  \ ca1 len1 = files to be imported, with their '-I' prefixes
  s" "
  argc @ 2 ?do
    s"  -I " i arg escaped s+ s+
  loop
  ;
: create-z80-file  ( -- )
  \ Create the temporary fake z80 file.
  z80-file r/o create-file abort" Error creating the fake z80 file."
  z80-file-id !
  ;
: delete-z80-file  ( -- )
  \ Delete the temporary fake z80 file.
  z80-file delete-file abort" Error deleting the fake z80 file."
  ;
: +extension  ( ca1 len1 -- ca2 len2 )
  \ Add the file extension to the output file, if needed.
  s" .mgt.gz" ends? 0= if
    \ xxx first version
    \ s" .mgt" ends? if  s" .gz"  else  s" .mgt.gz"  then  s+
    \ xxx 2013-07-28 new version
    s" .mgt" ends? 0= if  s" .mgt" s+  then  s" .gz" s+
  then
  ;
: -o-parameter  ( -- a u )
  \ Return a string with the '-o' parameter required by pyz80.
  s" -o "
  1 arg  \ parameter 1 is the name of the MGT disk image
  +extension
  2dup mgt-file place  \ keep a copy of the file name for later use
  s+
  ;
: pyz80  ( ca1 len1 ca2 len2 -- )
  \ Execute pyz80 with the provided parameters.
  \ ca1 len1 = files to be imported, with their '-I' prefixes
  \ ca2 len2 = name of the MGT disk image
  create-z80-file
  s" pyz80 " 2swap s+ 2swap s& z80-file s& system
  delete-z80-file
  ;
: mgt ( -- )
  \ Convert the parameters and execute pyz80 with them.
  -i-parameters -o-parameter pyz80
  ;

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Usage

: .command  ( -- )
  \ Print the name of this file.
  command type
  ;
: cri  ( -- )
  \ Start a new line with an indentation.
  cr 4 spaces
  ;
: usage  ( -- )
  \ Show the usage instructions.
  cr ." Usage:" cr
  cr ." The first parameter is the MGT disk image file name."
  cr ." Its extension '.mgt.gz' will be automatically added or completed if needed."
  cr ." WARNING: If the file already exists, it will be overwritten." cr
  cr ." The second parameter is a space separated list of files to be added to the disk image."
  cr ." Shell patterns can be used." cr
  cr ." Examples:" cr
  cri .command ."  mynewdiskimage myfile.bin" cr
  cri .command ."  mynewdiskimage myfile1.bin myfile2.txt" cr
  cri .command ."  mynewdiskimage img*.png data??.*" cr
  ;

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Debug

: .args  ( -- )
  \ Show all parameters.
  argc @ 0 ?do
    i dup . arg type cr
  loop
  ;

\ ." echo $0 --" s" echo $0" system ." --" cr cr  \ xxx debug check
\ 0 arg type cr  \ xxx debug check

\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Main

: check  ( -- )
  \ Make sure the number of parameters is 3 or more.
  argc @ 3 < if  usage bye  then
  ;
: main  ( -- )
  check mgt
  ;
main  bye

Deŝutoj

Rilataj paĝoj

mkmgt
Kreilo por MGT-aj dosier-diskedoj de ZX Spectrum por sistemoj GDOS, G+DOS kaj Beta DOS.