summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING339
-rw-r--r--TODO.md10
-rw-r--r--avr/Tupfile32
-rw-r--r--avr/background.c16
-rw-r--r--avr/bcd.c21
-rw-r--r--avr/cli.c133
-rw-r--r--avr/cli_readline.c13
-rw-r--r--avr/cmd_boot.c69
-rw-r--r--avr/cmd_date.c136
-rw-r--r--avr/cmd_fat.c419
-rw-r--r--avr/cmd_gpio.c8
-rw-r--r--avr/cmd_help.c8
-rw-r--r--avr/cmd_loadcpm3.c172
-rw-r--r--avr/cmd_loadihex.c261
-rw-r--r--avr/cmd_mem.c377
-rw-r--r--avr/cmd_misc.c48
-rw-r--r--avr/cmd_sd.c81
-rw-r--r--avr/command.c15
-rw-r--r--avr/command_tbl.c105
-rw-r--r--avr/con-utils.c34
-rw-r--r--avr/date.c139
-rw-r--r--avr/debug.c108
-rw-r--r--avr/env.c46
-rw-r--r--avr/getopt-min.c9
-rw-r--r--avr/gpio.c62
-rw-r--r--avr/i2c.c8
-rw-r--r--avr/main.c80
-rw-r--r--avr/mmc.c218
-rw-r--r--avr/pcf8583.c27
-rw-r--r--avr/print-utils.c13
-rw-r--r--avr/serial.c9
-rw-r--r--avr/timer.c23
-rw-r--r--avr/xmalloc.c11
-rw-r--r--avr/z180-serv.c455
-rw-r--r--avr/z180-stamp-avr.c591
-rw-r--r--avr/z80-if.c12
-rw-r--r--fatfs/src/ffconf.h269
-rw-r--r--fatfs/src/option/ccsbcs.c51
-rw-r--r--include/avr/ffconf.h248
-rw-r--r--include/background.h7
-rw-r--r--include/bcd.h13
-rw-r--r--include/cli.h21
-rw-r--r--include/cli_readline.h3
-rw-r--r--include/cmd_mem.h10
-rw-r--r--include/command.h16
-rw-r--r--include/common.h14
-rw-r--r--include/con-utils.h14
-rw-r--r--include/config.h30
-rw-r--r--include/crc.h9
-rw-r--r--include/debug.h14
-rw-r--r--include/diskio.h2
-rw-r--r--include/env.h9
l---------[-rw-r--r--]include/ff.h3
-rw-r--r--include/ffconf.h5
-rw-r--r--include/getopt-min.h7
-rw-r--r--include/gpio.h7
-rw-r--r--include/i2c.h2
-rw-r--r--include/print-utils.h7
-rw-r--r--include/ring.h7
-rw-r--r--include/rtc.h41
-rw-r--r--include/serial.h6
-rw-r--r--include/spi.h12
l---------include/time.h1
-rw-r--r--include/timer.h9
-rw-r--r--include/z180-serv.h6
-rw-r--r--include/z80-if.h7
-rw-r--r--stm32/debug.h5
-rw-r--r--stm32/serial.c5
-rw-r--r--stm32/serial.h6
-rw-r--r--stm32/z180-stamp-stm32.c71
-rw-r--r--stm32/z80-if.c66
-rw-r--r--stm32/z80-if.h5
-rw-r--r--time/Files.am77
-rw-r--r--time/Makefile529
-rw-r--r--time/Makefile.am35
-rw-r--r--time/Makefile.in529
-rw-r--r--time/Rules.am30
-rw-r--r--time/asc_store.c39
-rw-r--r--time/asctime.c44
-rw-r--r--time/asctime_r.c82
-rw-r--r--time/ctime.c47
-rw-r--r--time/ctime_r.c43
-rw-r--r--time/daylight_seconds.c72
-rw-r--r--time/difftime.c41
-rw-r--r--time/dst_pointer.c34
-rw-r--r--time/ephemera_common.h44
-rw-r--r--time/equation_of_time.c86
-rw-r--r--time/fatfs_time.c66
-rw-r--r--time/geo_location.c32
-rw-r--r--time/gm_sidereal.c60
-rw-r--r--time/gmtime.c45
-rw-r--r--time/gmtime_r.c144
-rw-r--r--time/isLeap.c56
-rw-r--r--time/iso_week_date.c51
-rw-r--r--time/iso_week_date_r.c114
-rw-r--r--time/isotime.c44
-rw-r--r--time/isotime_r.c70
-rw-r--r--time/lm_sidereal.c47
-rw-r--r--time/localtime.c44
-rw-r--r--time/localtime_r.c60
-rw-r--r--time/mk_gmtime.c113
-rw-r--r--time/mktime.c61
-rw-r--r--time/month_length.c48
-rw-r--r--time/moon_phase.c65
-rw-r--r--time/print_lz.c45
-rw-r--r--time/set_dst.c44
-rw-r--r--time/set_position.c44
-rw-r--r--time/set_system_time.c55
-rw-r--r--time/set_zone.c41
-rw-r--r--time/solar_declination.c77
-rw-r--r--time/solar_noon.c57
-rw-r--r--time/strftime.c322
-rw-r--r--time/sun_rise.c49
-rw-r--r--time/sun_set.c50
-rw-r--r--time/system_tick.S60
-rw-r--r--time/system_time.c36
-rw-r--r--time/time.c58
-rw-r--r--time/time.h523
-rw-r--r--time/tm_store.c37
-rw-r--r--time/utc_offset.c35
-rw-r--r--time/week_of_month.c62
-rw-r--r--time/week_of_year.c58
-rw-r--r--z180/Makefile17
-rw-r--r--z180/Tupfile18
-rw-r--r--z180/asci-p.180133
-rw-r--r--z180/asci1-i.180 (renamed from z180/ser1-i.180)42
-rw-r--r--z180/bioscio.1803
-rw-r--r--z180/chario.18034
-rw-r--r--z180/conbuf-a.180108
-rw-r--r--z180/config.inc171
-rw-r--r--z180/console.180143
-rw-r--r--z180/ddtz.1808492
-rw-r--r--z180/fifoio.18017
-rw-r--r--z180/init-80.180591
-rw-r--r--z180/init.180913
-rw-r--r--z180/msgbuf-a.180277
-rw-r--r--z180/msgfifo.18027
-rw-r--r--z180/r3init.180957
-rw-r--r--z180/z180reg.inc14
139 files changed, 14131 insertions, 7447 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d159169
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..75c9679
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,10 @@
+TODO List
+=========
+
+- TODO: eliminate xmalloc
+- TODO: build time directory as lib
+- TODO: file search path. 'cd' command?
+- TODO: increase __malloc_margin to ? (now 0x20)
+----------------------------------------------------
+- Done:
+ - command 'help <topic>' should return success
diff --git a/avr/Tupfile b/avr/Tupfile
index 11b5802..d73db12 100644
--- a/avr/Tupfile
+++ b/avr/Tupfile
@@ -1,14 +1,25 @@
include_rules
PROG = stamp-monitor
+
+FATFS = $(TOP)/fatfs/src/ff.c
+
SRC = main.c
SRC += cli.c cli_readline.c command.c command_tbl.c
SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c
-SRC += cmd_sd.c cmd_fat.c
-SRC += env.c xmalloc.c date.c con-utils.c print-utils.c getopt-min.c
-SRC += timer.c serial.c i2c.c pcf8583.c mmc.c
+SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c
+SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c
+SRC += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c
SRC += background.c z180-serv.c z80-if.c gpio.c
-SRC += $(TOP)/fatfs/src/ff.c
+SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c
+
+#TODO: time lib
+SRC += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c
+SRC += ../time/print_lz.c ../time/isLeap.c
+SRC += ../time/time.c ../time/fatfs_time.c
+SRC += ../time/system_time.c ../time/set_system_time.c
+
+ASRC += ../time/system_tick.S
SRC_Z = ../z180/hdrom.c
@@ -59,25 +70,34 @@ CFLAGS += -fno-split-wide-types
CFLAGS += -fshort-enums
#CFLAGS += -fdiagnostics-color=always
-
#CFLAGS += -save-temps
+CFLAGS_$(FATFS) = -fno-strict-aliasing
CFLAGS += $(INCLUDES)
CPPFLAGS += $(DEFS)
+#ASFLAGS += -Wa,-adhlns=$(<:.S=.lst),-gstabs
+ASFLAGS += -mmcu=$(MCU_TARGET) -x assembler-with-cpp $(ASFLAGS)
+
# Linker flags
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--cref
+# Assemble: create object files from assembler source files.
+#.S.o:
+# $(CC) -c $(ALL_ASFLAGS) $< -o $@
+
-!cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) -c %f -o %o |> %B.o
+!as = |> ^ AS %f^ $(CC) $(ASFLAGS) -c %f -o %o |> %B.o
+!cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS_%f) -c %f -o %o |> %B.o
!LINK = |> ^ LINK %o^ $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=%O.map %f $(LDLIBS) -o %o |> | %O.map
!OBJCOPY= |> ^ OBJCOPY %o^ $(OBJCOPY) -Oihex %f %o |>
!OBJDUMP= |> ^ OBJDUMP %o^ $(OBJDUMP) -h -S %f > %o |> %O.lss
!SIZE = |> ^ SIZE^ $(SIZE) %f |>
+: foreach $(ASRC) |> !as |> {objs}
: foreach $(SRC) | ../z180/hdrom.h |> !cc |> {objs}
: $(SRC_Z) |> !cc -D'const=const __flash' |> {objs}
diff --git a/avr/background.c b/avr/background.c
index 0e1ca40..9c8b5a6 100644
--- a/avr/background.c
+++ b/avr/background.c
@@ -1,10 +1,16 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include "background.h"
#define BG_FUNC_MAX 5
-static struct {
+static struct {
bg_func fct;
int param;
} func_tab[BG_FUNC_MAX];
@@ -13,7 +19,7 @@ static int_fast8_t fcount;
int bg_register(bg_func f, int initval)
{
- if (fcount < BG_FUNC_MAX) {
+ if (fcount < BG_FUNC_MAX) {
func_tab[fcount].fct = f;
func_tab[fcount].param = initval;
return ++fcount - 1;
@@ -27,7 +33,7 @@ int bg_setstat(int handle, int val)
func_tab[handle].param = val;
return 1;
}
-
+
return 0;
}
@@ -44,7 +50,7 @@ int bg_getstat(int handle)
void bg_shed(void)
{
static int_fast8_t current;
-
+
if (func_tab[current].fct) {
int v = func_tab[current].fct(func_tab[current].param);
func_tab[current].param = v;
@@ -52,5 +58,3 @@ void bg_shed(void)
if (++current >= fcount)
current = 0;
}
-
-
diff --git a/avr/bcd.c b/avr/bcd.c
new file mode 100644
index 0000000..5154852
--- /dev/null
+++ b/avr/bcd.c
@@ -0,0 +1,21 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "stdlib.h"
+#include "stdint.h"
+#include "bcd.h"
+
+uint_fast8_t bcd2bin(uint8_t val)
+{
+ return (val >> 4) * 10 + (val & 0x0f);
+}
+
+uint8_t bin2bcd (uint_fast8_t val)
+{
+ div_t d = div(val, 10);
+
+ return (d.quot << 4) | d.rem;
+}
diff --git a/avr/cli.c b/avr/cli.c
index b310f79..43b5be0 100644
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -1,3 +1,16 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * Add to readline cmdline-editing by
+ * (C) Copyright 2005
+ * JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <string.h>
@@ -14,6 +27,9 @@
#include "con-utils.h"
#include "cli.h"
+
+/* FIXME: Quoting problems */
+
#define DEBUG_PARSER 0 /* set to 1 to debug */
#define debug_parser(fmt, args...) \
@@ -21,26 +37,75 @@
static int cli_parse_line(char *line, char *argv[])
{
- static const FLASH char delim[] = {" \t"};
-
- char *ptr;
+ uint_fast8_t state = 0;
uint_fast8_t nargs = 0;
+ char *inp, *outp;
+ char c, quote;
- debug_parser("parse_line: \"%s\"\n", line);
+ debug_parser("%s: \"%s\"\n", __func__, line);
+
+ for (outp = inp = line, quote = '\0' ;
+ nargs < CONFIG_SYS_MAXARGS && (c = *inp) != '\0';
+ inp++) {
+
+ switch (state) {
+ case 0: /* before arg string, waiting for arg start */
+ if (isblank(c))
+ continue;
+
+ argv[nargs++] = inp; /* begin of argument string */
+ outp = inp;
+ state = 1;
+ /* fall thru */
+
+ case 1: /* in arg string, waiting for end of arg string */
+ if (c == '\\') {
+ ++state;
+ continue;
+ }
+ if (c == '\"' || c == '\'') {
+ quote = c;
+ state = 3;
+ continue;
+ }
+ if (isblank(c)) {
+ c = '\0';
+ state = 0;
+ }
+ break;
- ptr = strtok_P(line, delim);
- while(nargs < CONFIG_SYS_MAXARGS && ptr != NULL) {
- argv[nargs++] = ptr;
- ptr = strtok_P(NULL, delim);
+ case 3: /* in quote */
+ if (c == '\\' && quote == '\"') {
+ ++state;
+ continue;
+ }
+ if (c == quote) {
+ state = 1;
+ continue;
+ }
+ break;
+
+ case 2: /* waiting for next char */
+ case 4:
+ --state;
+ break;
+
+ }
+ *outp++ = c;
}
- if (ptr != NULL)
+ if (*inp != '\0')
printf_P(PSTR("** Too many args (max. %d) **\n"), CONFIG_SYS_MAXARGS);
+ *outp = '\0';
argv[nargs] = NULL;
- debug_parser("parse_line: nargs=%d\n", nargs);
-
+ debug_parser("%s: nargs=%d\n", __func__, nargs);
+#if 0
+ for (int i = 0; i < nargs; i++)
+ debug_parser("%s: arg %d: >%s<\n", __func__, i, argv[i]);
+#endif
return nargs;
+
}
static
@@ -61,7 +126,8 @@ char *process_macros(char *input, char *output)
for(uint_fast8_t pass = 0; pass < 2; pass++)
{
- uint_fast8_t state = 0; /* 0 = waiting for '$' */
+ uint_fast8_t state = 0;
+ /* 0 = waiting for '$' */
/* 1 = waiting for '{' */
/* 2 = waiting for '}' */
/* 3 = waiting for ''' */
@@ -75,22 +141,13 @@ char *process_macros(char *input, char *output)
}
inp = input;
- prev = '\0'; /* previous character */
- debug_parser("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen(inp),
- inp);
+ debug_parser("[PROCESS_MACROS] INPUT len %d: \"%s\"\n",
+ strlen(inp), inp);
+
+ for (prev = '\0'; (c = *inp++) != '\0'; prev = c) {
- while ((c = *inp++) != '\0') {
- if (state != 3) {
- /* remove one level of escape characters */
- if ((c == '\\') && (prev != '\\')) {
- if (*inp == '\0')
- break;
- prev = c;
- c = *inp++;
- }
- }
switch (state) {
case 0: /* Waiting for (unescaped) $ */
@@ -98,19 +155,19 @@ char *process_macros(char *input, char *output)
state = 3;
break;
}
- if ((c == '$') && (prev != '\\'))
+ if ((c == '$') && (prev != '\\')) {
state++;
- else
- append_char(pass, &outp, c);
+ continue;
+ }
break;
case 1: /* Waiting for { */
if (c == '{') {
state++;
varname = inp;
+ continue;
} else {
state = 0;
append_char(pass, &outp, '$');
- append_char(pass, &outp, c);
}
break;
case 2: /* Waiting for } */
@@ -126,15 +183,13 @@ char *process_macros(char *input, char *output)
/* Look for another '$' */
state = 0;
}
- break;
+ continue;
case 3: /* Waiting for ' */
- if ((c == '\'') && (prev != '\\'))
+ if (c == '\'')
state = 0;
- else
- append_char(pass, &outp, c);
break;
}
- prev = c;
+ append_char(pass, &outp, c);
}
append_char(pass, &outp, 0);
@@ -200,12 +255,13 @@ static int cli_run_command(const char *cmd, int flag)
*/
for (inquotes = 0, sep = str; *sep; sep++) {
if ((*sep == '\'') &&
- (*(sep - 1) != '\\'))
+ (sep != str) && /* past string start */
+ (*(sep - 1) != '\\')) /* and NOT escaped */
inquotes = !inquotes;
if (!inquotes &&
- (*sep == ';' || *sep == '\n') && /* separator */
- (sep != str) && /* past string start */
+ (*sep == ';' || *sep == '\n') && /* separator */
+ (sep != str) && /* past string start */
(*(sep - 1) != '\\')) /* and NOT escaped */
break;
}
@@ -257,7 +313,7 @@ static int cli_run_command_list(const char *cmd)
/*
- * Run a command using the selected parser.
+ * Run a command.
*
* @param cmd Command to run
* @param flag Execution flags (CMD_FLAG_...)
@@ -350,4 +406,3 @@ command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
return CMD_RET_SUCCESS;
}
-
diff --git a/avr/cli_readline.c b/avr/cli_readline.c
index 8795a97..ff83a3a 100644
--- a/avr/cli_readline.c
+++ b/avr/cli_readline.c
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -10,7 +12,6 @@
*/
#include "common.h"
-
#include <string.h>
#include <stdio.h>
#include <ctype.h>
@@ -666,16 +667,8 @@ static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer
my_puts_P(tab_seq + (col & 07));
col += 8 - (col & 07);
} else {
- char buf[2];
-
- /*
- * Echo input using puts() to force an
- * LCD flush if we are using an LCD
- */
++col;
- buf[0] = c;
- buf[1] = '\0';
- my_puts(buf);
+ putchar(c);
}
*p++ = c;
++n;
diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c
index 4775b6e..b8799aa 100644
--- a/avr/cmd_boot.c
+++ b/avr/cmd_boot.c
@@ -1,3 +1,11 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000-2003
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
/*
* Misc boot support
@@ -8,6 +16,9 @@
#include <util/atomic.h>
#include "command.h"
+#include "cli_readline.h"
+#include "cli.h"
+#include "env.h"
#include "con-utils.h"
#include "z80-if.h"
#include "z180-serv.h"
@@ -33,11 +44,9 @@ static void z80_load_mem(void)
hdrom_address[sec]+hdrom_length_of_sections[sec] - 1,
hdrom_length_of_sections[sec]);
- z80_bus_cmd(Request);
z80_write_block_P((const FLASH unsigned char *) &hdrom[sec_base], /* src */
hdrom_address[sec], /* dest */
hdrom_length_of_sections[sec]); /* len */
- z80_bus_cmd(Release);
sec_base+=hdrom_length_of_sections[sec];
sec++;
}
@@ -48,11 +57,15 @@ command_ret_t do_loadf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
(void) cmdtp; (void) flag; (void) argc; (void) argv;
if (z80_bus_state() & ZST_RUNNING) {
- printf_P(PSTR("## Can't load while CPU is running!\n"));
+ my_puts_P(PSTR("Can't load while CPU is running!\n"));
return CMD_RET_FAILURE;
}
-
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return CMD_RET_FAILURE;
+ }
z80_load_mem();
+ z80_bus_cmd(Release);
return CMD_RET_SUCCESS;
}
@@ -139,7 +152,7 @@ command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
{
(void) cmdtp; (void) flag; (void) argc; (void) argv;
- printf_P(PSTR("## CPU now in reset state.\n"));
+ printf_P(PSTR("CPU now in reset state.\n"));
reset_cpu(Reset);
return CMD_RET_SUCCESS;
@@ -159,12 +172,13 @@ void print_con_usage(char esc)
{ printf_P(PSTR("\n"
"------------------------------------------------\n"
" ?,H - This Help\n"
- " R - Reset (Restart) CPU\n"
" Q,X - Return to command line\n"
- " \\ - code input:\n"
- " \\nnn 3 decimal digits character code\n"
- " \\Xhh 2 hexadecimal digits character code\n"
- " ^%c - (Escape char) Type again to send itself\n"
+ " R - Reset (Restart) CPU\n"
+ " : - Execute monitor command\n"
+ " \\ - code input:\n"
+ " \\nnn 3 decimal digits character code\n"
+ " \\Xhh 2 hexadecimal digits character code\n"
+ " ^%c - (Escape char) Type again to send itself\n"
"key>"
), esc + 0x40);
}
@@ -176,9 +190,12 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
// uint8_t help_prompt = 0;
uint8_t code = 0;
uint8_t state = 0;
+ char esc_char = (char) getenv_ulong(PSTR(ENV_ESC_CHAR), 16, CONFIG_ESC_CHAR);
(void) cmdtp; (void) flag; (void) argc; (void) argv;
+ printf_P(PSTR("Connecting to CPU. Escape character is '^%c'.\n"),
+ esc_char + 0x40);
while (1) {
@@ -186,14 +203,16 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
pending = (Stat & S_CON_PENDING) != 0;
Stat &= ~S_CON_PENDING;
}
- if (pending)
- while ((ch = z80_memfifo_getc(fifo_conout)) >= 0)
+ if (pending) {
+ uint8_t count = 100;
+ while ((ch = z80_memfifo_getc(fifo_conout)) >= 0 && --count)
putchar(ch);
+ }
if ((ch = my_getchar(0)) >= 0) {
switch (state) {
case 0:
- if (ch == CONFIG_ESC_CHAR) {
+ if (ch == esc_char) {
state = 1;
/* TODO: Timer starten */
} else {
@@ -209,7 +228,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
case '?':
case 'H':
- print_con_usage(CONFIG_ESC_CHAR);
+ print_con_usage(esc_char);
state = 2;
break;
@@ -223,15 +242,21 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
goto quit;
break;
+ case ':':
+ putchar('\n');
+ int cmdlen = cli_readline(PSTR(": "));
+ if (cmdlen > 0)
+ run_command(console_buffer, 0);
+ break;
+
case '\\':
code = 0;
state = 3;
break;
- case CONFIG_ESC_CHAR:
- z80_memfifo_putc(fifo_conin, ch);
- break;
default:
+ if (ch == esc_char)
+ z80_memfifo_putc(fifo_conin, ch);
break;
}
break;
@@ -246,6 +271,11 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
if (isdigit(ch)) {
code = code * 10 + ch - '0';
state++;
+ } else {
+ if (state > 3)
+ z80_memfifo_putc(fifo_conin, code);
+ z80_memfifo_putc(fifo_conin, ch);
+ state = 0;
}
if (state > 5) {
z80_memfifo_putc(fifo_conin, code);
@@ -260,6 +290,11 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
ch -= 'A' - 10;
code = code * 16 + ch - '0';
state++;
+ }else {
+ if (state > 6)
+ z80_memfifo_putc(fifo_conin, code);
+ z80_memfifo_putc(fifo_conin, ch);
+ state = 0;
}
if (state > 7) {
z80_memfifo_putc(fifo_conin, code);
diff --git a/avr/cmd_date.c b/avr/cmd_date.c
index ad0d3ac..efba858 100644
--- a/avr/cmd_date.c
+++ b/avr/cmd_date.c
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* (C) Copyright 2001
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -8,66 +10,12 @@
/*
* RTC, Date & Time support: get and set date & time
*/
-#include <common.h>
+#include "common.h"
#include <string.h>
-#include <command.h>
-#include <rtc.h>
-#include <i2c.h>
-
-
-static const char * const weekdays[] = {
- "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
-};
-
-int mk_date (const char *, struct rtc_time *);
-
-command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- struct rtc_time tm;
- int rcode = CMD_RET_SUCCESS;
-
- (void) cmdtp; (void) flag;
-
- switch (argc) {
- case 2: /* set date & time */
- /* initialize tm with current time */
- rcode = rtc_get (&tm);
-
- if(!rcode) {
- /* insert new date & time */
- if (mk_date (argv[1], &tm) != 0) {
- my_puts_P(PSTR("## Bad date format\n"));
- break;
- }
- /* and write to RTC */
- rcode = rtc_set (&tm);
- if(rcode)
- my_puts_P(PSTR("## Set date failed\n"));
- } else {
- my_puts_P(PSTR("## Get date failed\n"));
- }
- /* FALL TROUGH */
- case 1: /* get date & time */
- rcode = rtc_get (&tm);
+#include "time.h"
+#include "rtc.h"
+#include "command.h"
- if (rcode) {
- my_puts_P(PSTR("## Get date failed\n"));
- break;
- }
- /* TODO: put weekdays[] in flash */
- printf_P(PSTR("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n"),
- tm.tm_year, tm.tm_mon, tm.tm_mday,
- (tm.tm_wday<0 || tm.tm_wday>6) ?
- "unknown " : weekdays[tm.tm_wday],
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-
- break;
- default:
- rcode = CMD_RET_USAGE;
- }
-
- return rcode;
-}
/*
* simple conversion of two-digit string with error checking
@@ -97,7 +45,7 @@ static int cnvrt2 (const char *str, int *valp)
* Some basic checking for valid values is done, but this will not catch
* all possible error conditions.
*/
-int mk_date (const char *datestr, struct rtc_time *tmp)
+int mk_date (const char *datestr, struct tm *tmp)
{
int len, val;
char *ptr;
@@ -123,36 +71,36 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
tmp->tm_sec = 0;
}
- if (len == 12) { /* MMDDhhmmCCYY */
+ if (len == 12) { /* MMDDhhmmCCYY */
int year, century;
if (cnvrt2 (datestr+ 8, &century) ||
cnvrt2 (datestr+10, &year) ) {
return (-1);
}
- tmp->tm_year = 100 * century + year;
+ tmp->tm_year = 100 * century + year - 1900;
} else if (len == 10) { /* MMDDhhmmYY */
int year, century;
- century = tmp->tm_year / 100;
+ century = (tmp->tm_year + 1900) / 100;
if (cnvrt2 (datestr+ 8, &year))
return (-1);
- tmp->tm_year = 100 * century + year;
+ tmp->tm_year = 100 * century + year -1900;
}
switch (len) {
- case 8: /* MMDDhhmm */
+ case 8: /* MMDDhhmm */
/* fall thru */
- case 10: /* MMDDhhmmYY */
+ case 10: /* MMDDhhmmYY */
/* fall thru */
- case 12: /* MMDDhhmmCCYY */
+ case 12: /* MMDDhhmmCCYY */
if (cnvrt2 (datestr+0, &val) ||
val > 12) {
break;
}
- tmp->tm_mon = val;
+ tmp->tm_mon = val - 1;
if (cnvrt2 (datestr+2, &val) ||
- val > ((tmp->tm_mon==2) ? 29 : 31)) {
+ val > ((tmp->tm_mon==2-1) ? 29 : 31)) {
break;
}
tmp->tm_mday = val;
@@ -169,9 +117,6 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
}
tmp->tm_min = val;
- /* calculate day of week */
- GregorianDay (tmp);
-
return (0);
default:
break;
@@ -180,3 +125,52 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
return (-1);
}
+command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ struct tm t;
+ char buf[30];
+ int rcode = CMD_RET_SUCCESS;
+
+ (void) cmdtp; (void) flag;
+
+ switch (argc) {
+ case 2: /* set date & time */
+ /* initialize t with current time */
+ rcode = rtc_get (&t);
+
+ if(!rcode) {
+ /* insert new date & time */
+ if (mk_date (argv[1], &t) != 0) {
+ my_puts_P(PSTR("## Bad date format\n"));
+ break;
+ }
+
+ time_t time;
+ time = mk_gmtime(&t);
+ gmtime_r(&time, &t);
+
+ /* and write to RTC */
+ rcode = rtc_set (&t);
+ if(rcode)
+ my_puts_P(PSTR("## Set date failed\n"));
+ } else {
+ my_puts_P(PSTR("## Get date failed\n"));
+ }
+ /* FALL TROUGH */
+ case 1: /* get date & time */
+ rcode = rtc_get (&t);
+
+ if (rcode) {
+ my_puts_P(PSTR("## Get date failed\n"));
+ break;
+ }
+ asctime_r(&t, buf);
+ printf_P(PSTR("%s\n"), buf);
+ break;
+
+ default:
+ rcode = CMD_RET_USAGE;
+ }
+
+ return rcode;
+}
diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c
index 9222c1b..af2f772 100644
--- a/avr/cmd_fat.c
+++ b/avr/cmd_fat.c
@@ -1,3 +1,13 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * FAT filesystem commands
+ */
+
#include "common.h"
#include <stdlib.h>
#include <string.h>
@@ -6,13 +16,37 @@
#include "command.h"
#include "ff.h"
#include "z80-if.h"
+#include "con-utils.h"
#include "print-utils.h"
+#include "time.h"
#include "timer.h"
+#include "debug.h"
+
+/* TODO: use memory size test function (cmd_mem.c) */
+#define MAX_MEMORY (1ul << 19)
+#define BUFFER_SIZE 512
DWORD get_fattime (void)
{
- return 0;
+ time_t timer;
+ struct tm tm_timer;
+
+ time(&timer);
+ gmtime_r(&timer, &tm_timer);
+
+ return fatfs_time(&tm_timer);
+}
+
+
+static bool check_abort(void)
+{
+ bool ret = ctrlc();
+
+ if (ret)
+ printf_P(PSTR("Abort\n"));
+
+ return ret;
}
@@ -41,23 +75,42 @@ static const FLASH char * const FLASH rc_names[] = {
static
void put_rc (FRESULT rc)
{
+ if (rc < ARRAY_SIZE(rc_names)) {
#if GCC_BUG_61443
- printf_P(PSTR("rc=%u FR_"), rc);
- my_puts_P(rc_names[rc]);
- my_puts_P(PSTR("\n"));
+ printf_P(PSTR("rc=%u FR_"), rc);
+ my_puts_P(rc_names[rc]);
+ my_puts_P(PSTR("\n"));
#else
- printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]);
+ printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]);
#endif
+ }
+}
+
+
+static void swirl(void)
+{
+ static const FLASH char swirlchar[] = { '-','\\','|','/' };
+ static uint_fast8_t cnt;
+ static uint32_t tstamp;
+
+ if (get_timer(0) > tstamp) {
+ printf_P(PSTR("\b%c"), swirlchar[cnt]);
+ cnt = (cnt+1) % ARRAY_SIZE(swirlchar);
+ tstamp = get_timer(0) + 250;
+ }
}
/* Work register for fs command */
-static DWORD AccSize;
-static WORD AccFiles, AccDirs;
-FILINFO Finfo;
+struct stat_dat_s {
+ DWORD AccSize;
+ WORD AccFiles, AccDirs;
+ FILINFO Finfo;
+};
static
FRESULT scan_files (
- char* path /* Pointer to the working buffer with start path */
+ char *path, /* Pointer to the working buffer with start path */
+ struct stat_dat_s *statp
)
{
DIR dirs;
@@ -66,25 +119,30 @@ FRESULT scan_files (
char *fn;
res = f_opendir(&dirs, path);
+ swirl();
if (res == FR_OK) {
i = strlen(path);
- while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) {
- if (_FS_RPATH && Finfo.fname[0] == '.') continue;
-#if _USE_LFN
- fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname;
-#else
- fn = Finfo.fname;
-#endif
- if (Finfo.fattrib & AM_DIR) {
- AccDirs++;
- path[i] = '/'; strcpy(path+i+1, fn);
- res = scan_files(path);
+ while (((res = f_readdir(&dirs, &statp->Finfo)) == FR_OK) &&
+ statp->Finfo.fname[0]) {
+ if (_FS_RPATH && statp->Finfo.fname[0] == '.')
+ continue;
+ fn = statp->Finfo.fname;
+ if (statp->Finfo.fattrib & AM_DIR) {
+ statp->AccDirs++;
+ path[i] = '/';
+ strcpy(path+i+1, fn);
+ res = scan_files(path, statp);
path[i] = '\0';
- if (res != FR_OK) break;
+ if (res != FR_OK)
+ break;
} else {
-// printf_P(PSTR("%s/%s\n"), path, fn);
- AccFiles++;
- AccSize += Finfo.fsize;
+ //printf_P(PSTR("%s/%s\n"), path, fn);
+ statp->AccFiles++;
+ statp->AccSize += statp->Finfo.fsize;
+ }
+ if (check_abort()) {
+ res = 255;
+ break;
}
}
}
@@ -99,64 +157,65 @@ FRESULT scan_files (
*/
command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- FATFS FatFs, *fs;
- DWORD p1, p2;
+ FATFS *fs;
+ DWORD nfreeclst;
FRESULT res;
- char buffer[512];
+ char *path;
+ struct stat_dat_s statp;
(void) cmdtp; (void) flag; (void) argc;
- res = f_mount(&FatFs, argv[1], 0);
- if (!res)
- res = f_getfree(argv[1], &p2, &fs);
- if (res) {
- put_rc(res);
+ path = (char *) malloc(BUFFER_SIZE);
+ if (path == NULL) {
+ printf_P(PSTR("fatstat: Out of Memory!\n"));
+ free(path);
return CMD_RET_FAILURE;
}
- printf_P(PSTR(
- "FAT type: %u\n"
- "Bytes/Cluster: %lu\n"
- "Number of FATs: %u\n"
- "Root DIR entries: %u\n"
- "Sectors/FAT: %lu\n"
- "Number of clusters: %lu\n"
- "FAT start (lba): %lu\n"
- "DIR start (lba,cluster): %lu\n"
- "Data start (lba): %lu\n"),
- fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats,
- fs->n_rootdir, fs->fsize, fs->n_fatent - 2,
- fs->fatbase, fs->dirbase, fs->database);
+ res = f_getfree(argv[1], &nfreeclst, &fs);
+ if (!res) {
+ printf_P(PSTR(
+ "FAT type: %u\n"
+ "Bytes/Cluster: %lu\n"
+ "Number of FATs: %u\n"
+ "Root DIR entries: %u\n"
+ "Sectors/FAT: %lu\n"
+ "Number of clusters: %lu\n"
+ "FAT start (lba): %lu\n"
+ "DIR start (lba,cluster): %lu\n"
+ "Data start (lba): %lu\n"),
+ fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats,
+ fs->n_rootdir, fs->fsize, fs->n_fatent - 2,
+ fs->fatbase, fs->dirbase, fs->database);
#if _USE_LABEL
- TCHAR label[12];
- res = f_getlabel(argv[1], label, &p1);
- if (res) {
- put_rc(res);
- return CMD_RET_FAILURE;
- }
- printf_P(PSTR(
- "Volume name: %s\n"
- "Volume S/N: %04X-%04X\n"),
- label, (WORD)((DWORD)p1 >> 16), (WORD)(p1 & 0xFFFF));
+ TCHAR label[12];
+ DWORD serial;
+ res = f_getlabel(argv[1], label, &serial);
+ if (!res) {
+ printf_P(PSTR(
+ "Volume name: %s\n"
+ "Volume S/N: %04X-%04X\n"),
+ label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF));
+ }
#endif
- my_puts_P(PSTR("\n..."));
- AccSize = AccFiles = AccDirs = 0;
-
- strcpy(buffer, argv[1]);
+ if (!res) {
+ my_puts_P(PSTR("\nCounting... "));
+ statp.AccSize = statp.AccFiles = statp.AccDirs = 0;
+ strcpy(path, argv[1]);
- res = scan_files(buffer);
- if (res) {
- put_rc(res);
- return CMD_RET_FAILURE;
+ res = scan_files(path, &statp);
+ }
+ if (!res) {
+ printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n"
+ "%lu KB total disk space.\n%lu KB available.\n"),
+ statp.AccFiles, statp.AccSize, statp.AccDirs,
+ (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2)
+ );
+ }
}
- printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n"
- "%lu KB total disk space.\n%lu KB available.\n"),
- AccFiles, AccSize, AccDirs,
- (fs->n_fatent - 2) * (fs->csize / 2), p2 * (fs->csize / 2)
- );
- res = f_mount(NULL, argv[1], 0);
+ free(path);
if (res) {
put_rc(res);
return CMD_RET_FAILURE;
@@ -171,7 +230,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
*/
command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- FATFS FatFs, *fs;
+ FATFS *fs;
DIR Dir; /* Directory object */
FILINFO Finfo;
unsigned long p1;
@@ -185,9 +244,7 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
(void) cmdtp; (void) flag; (void) argc;
- res = f_mount(&FatFs, argv[1], 0);
- if (!res)
- res = f_opendir(&Dir, argv[1]);
+ res = f_opendir(&Dir, argv[1]);
if (res) {
put_rc(res);
return CMD_RET_FAILURE;
@@ -203,22 +260,21 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
} else {
s1++; p1 += Finfo.fsize;
}
- printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s"),
+ printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu "),
(Finfo.fattrib & AM_DIR) ? 'D' : '-',
(Finfo.fattrib & AM_RDO) ? 'R' : '-',
(Finfo.fattrib & AM_HID) ? 'H' : '-',
(Finfo.fattrib & AM_SYS) ? 'S' : '-',
(Finfo.fattrib & AM_ARC) ? 'A' : '-',
(Finfo.fdate >> 9) + 1980, (Finfo.fdate >> 5) & 15, Finfo.fdate & 31,
- (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63,
- Finfo.fsize, &(Finfo.fname[0]));
+ (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, Finfo.fsize);
#if _USE_LFN
- for (int i = strlen(Finfo.fname); i < 14; i++)
- putchar(' ');
- printf_P(PSTR("%s\n"), Lfname);
+ printf_P(PSTR("%s\n"), *Lfname ? Lfname : Finfo.fname);
#else
- putchar('\n');
+ printf_P(PSTR("%s\n"), Finfo.fname);
#endif
+ if (check_abort())
+ break;
}
if (res == FR_OK) {
@@ -235,146 +291,153 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
return CMD_RET_SUCCESS;
}
+static
+FRESULT mkpath(TCHAR *path)
+{
+ /* TODO: */
+ (void) path;
+#if 0
+ FILINFO fd
+ TCHAR *p, *q;
+ FRESULT ret;
+
+#if _USE_LFN
+ fd.lfname = 0;
+#endif
+
+
+ res = f_stat (path, &fd)
+
+ p = strchr(path, ':');
+ if (p == NULL || *++p == '\0' || *p++ != '/')
+ return FR_OK;
+
+ while ((q = strchr(p, '/')) != NULL) {
+ *q = '\0';
+ ret = f_mkdir(path);
+ *q = '/';
+ if (ret != FR_OK && ret != FR_EXIST)
+ return ret;
+ p = q + 1;
+ }
+#endif
+
+ return FR_OK;
+}
/*
- * fatread - load binary file from a dos filesystem
- * <d:/path/filename> <addr> [bytes [pos]]
+ * fatread/write - load binary file to/from a dos filesystem
+ * read <d:/path/filename> <addr> [bytes [pos]]
+ * write <d:/path/filename> <addr> <bytes>
*/
-command_ret_t do_fat_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- FATFS FatFs;
FIL File;
- unsigned long bytes = 0x80000;
- unsigned long pos= 0;
- unsigned long bytes_read;
uint32_t addr;
+ unsigned long bytes;
+ unsigned long pos;
+ unsigned long bytes_rw;
+
+ bool dowrite = (argv[0][3] == 'w');
FRESULT res;
bool buserr = 0;
uint32_t timer;
- uint8_t buffer[512];
+ uint8_t *buffer;
(void) cmdtp; (void) flag;
- if (argc < 3)
+ if (argc < (dowrite ? 4 : 3))
return CMD_RET_USAGE;
addr = strtoul(argv[2], 0, 16);
+ if (addr >= MAX_MEMORY) {
+ printf_P(PSTR("address too high: 0x%0lx\n"), addr);
+ return CMD_RET_FAILURE;
+ }
if (argc > 3)
bytes = strtoul(argv[3], 0, 16);
+ else
+ bytes = MAX_MEMORY;
if (argc > 4)
pos = strtoul(argv[4], 0, 16);
+ else
+ pos = 0;
+
+ if (addr + bytes > MAX_MEMORY)
+ bytes = MAX_MEMORY - addr;
- res = f_mount(&FatFs, argv[1], 0);
+ buffer = (uint8_t *) malloc(BUFFER_SIZE);
+ if (buffer == NULL) {
+ printf_P(PSTR("fatstat: Out of Memory!\n"));
+ free(buffer);
+ return CMD_RET_FAILURE;
+ }
+
+ if (dowrite) {
+ res = mkpath(argv[1]);
+ }
if (!res) {
- res = f_open(&File, argv[1], FA_READ);
+ res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS
+ : FA_READ );
if (!res) {
res = f_lseek(&File, pos);
if (!res) {
- bytes_read = 0;
+ bytes_rw = 0;
timer = get_timer(0);
while (bytes) {
unsigned int cnt, br;
- if (bytes >= sizeof buffer) {
- cnt = sizeof buffer;
- bytes -= sizeof buffer;
+ if (bytes >= BUFFER_SIZE) {
+ cnt = BUFFER_SIZE;
+ bytes -= BUFFER_SIZE;
} else {
cnt = bytes; bytes = 0;
}
- res = f_read(&File, buffer, cnt, &br);
- if (res != FR_OK)
- break;
- if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
- buserr = 1;
- break;
+ if (dowrite) {
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ buserr = 1;
+ break;
+ }
+ z80_read_block(buffer, addr, cnt);
+ z80_bus_cmd(Release);
+ res = f_write(&File, buffer, cnt, &br);
+ if (res != FR_OK)
+ break;
+ } else {
+ res = f_read(&File, buffer, cnt, &br);
+ if (res != FR_OK)
+ break;
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ buserr = 1;
+ break;
+ }
+ z80_write_block(buffer, addr, br);
+ z80_bus_cmd(Release);
}
- z80_write_block(buffer, addr, br);
- z80_bus_cmd(Release);
addr += br;
- bytes_read += br;
- if (cnt != br)
+ bytes_rw += br;
+ if (cnt != br) {
+ if (dowrite)
+ printf_P(PSTR("Disk full?\n"));
+ break;
+ }
+ if (check_abort())
break;
}
+
+ FRESULT fr = f_close(&File);
+ if (!res)
+ res = fr;
timer = get_timer(timer);
- printf_P(PSTR("%lu bytes read with %lu bytes/sec.\n"),
- bytes_read, timer ? (bytes_read * 1000 / timer) : 0);
+ printf_P(PSTR("%lu (0x%lx) bytes read/written with %lu bytes/sec.\n"),
+ bytes_rw, bytes_rw, timer ? (bytes_rw * 1000 / timer) : 0);
}
}
- f_mount(NULL, argv[1], 0);
}
- if (buserr)
- my_puts_P(PSTR("Bus timeout\n"));
- if (res)
- put_rc(res);
- if (buserr || res)
- return CMD_RET_FAILURE;
-
- return CMD_RET_SUCCESS;
-}
-
-/*
- * fatwrite - write file into a dos filesystem
- * <d:/path/filename> <addr> <bytes>
- */
-command_ret_t do_fat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- FATFS FatFs;
- FIL File;
- unsigned long bytes;
- unsigned long bytes_written;
- uint32_t addr;
- FRESULT res;
- bool buserr = 0;
- uint32_t timer;
- uint8_t buffer[512];
-
- (void) cmdtp; (void) flag;
-
- if (argc < 4)
- return CMD_RET_USAGE;
-
- addr = strtoul(argv[2], 0, 16);
- bytes = strtoul(argv[3], 0, 16);
-
- res = f_mount(&FatFs, argv[1], 0);
- if (!res) {
- res = f_open(&File, argv[1], FA_CREATE_ALWAYS | FA_WRITE);
- if (!res) {
- bytes_written = 0;
- timer = get_timer(0);
- while (bytes) {
- unsigned int cnt, br;
-
- if (bytes >= sizeof buffer) {
- cnt = sizeof buffer;
- bytes -= sizeof buffer;
- } else {
- cnt = bytes; bytes = 0;
- }
- if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
- buserr = 1;
- break;
- }
- z80_read_block(buffer, addr, cnt);
- z80_bus_cmd(Release);
- res = f_write(&File, buffer, cnt, &br);
- if (res != FR_OK)
- break;
- addr += br;
- bytes_written += br;
- if (cnt != br)
- break;
- }
- res = f_close(&File);
- timer = get_timer(timer);
- printf_P(PSTR("%lu bytes written with %lu bytes/sec.\n"),
- bytes_written, timer ? (bytes_written * 1000 / timer) : 0);
- }
- f_mount(NULL, argv[1], 0);
- }
+ free(buffer);
if (buserr)
my_puts_P(PSTR("Bus timeout\n"));
diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c
index 84723d2..5589381 100644
--- a/avr/cmd_gpio.c
+++ b/avr/cmd_gpio.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <stdlib.h>
#include <string.h>
@@ -29,6 +35,8 @@ static void pinnames_get(void)
memset(pin_names, 0, sizeof(pin_names));
pin_names_width = 0;
+/* TODO: enters endless loop on wrong parameters */
+
if ((lp = getenv(PSTR(ENV_PINALIAS))) != NULL) {
pin_names[namestr] = strdup(lp);
ptr = strtok_P(pin_names[namestr], delim1);
diff --git a/avr/cmd_help.c b/avr/cmd_help.c
index 8f81b2d..010339d 100644
--- a/avr/cmd_help.c
+++ b/avr/cmd_help.c
@@ -1,3 +1,11 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
#include "common.h"
#include "command.h"
diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c
new file mode 100644
index 0000000..da1be37
--- /dev/null
+++ b/avr/cmd_loadcpm3.c
@@ -0,0 +1,172 @@
+/*
+ * (C) Copyright 2015 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "common.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "command.h"
+#include "env.h"
+#include "ff.h"
+#include "con-utils.h"
+#include "z80-if.h"
+#include "debug.h"
+
+
+#define RS 128 /* CP/M record size */
+
+/*
+ * Load Routine
+ *
+ * Input: addr = Page Address of load top
+ * len = Length in pages of module to read
+ *
+ */
+int load(FIL *File, uint32_t addr, uint8_t len)
+{
+ uint8_t buffer[RS];
+ unsigned int br; /* bytes read */
+ int res;
+
+ len *= 2; /* length in records of module */
+ //debug("## load: addr: 0x%.4X, records: 0x%.4X, (%u)\n", addr, len, len);
+
+ for (; len; len--) {
+ addr -= RS;
+ res = f_read(File, buffer, RS, &br);
+ if (res || br != RS) {
+ return 1;
+ }
+
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return 2;
+ }
+ z80_write_block(buffer, addr, RS);
+ z80_bus_cmd(Release);
+ //debug("## written: 0x%.4X\n", addr);
+ }
+
+ return 0;
+}
+
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
+command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ uint16_t mem_top;
+ uint8_t res_len;
+ uint16_t bank_top;
+ uint8_t bank_len;
+ uint16_t osentry_addr = 0;
+ uint32_t common_base, banked_base;
+ char *fname;
+ FIL File;
+ /* TODO: put CONFIG_CPM3_SYSFILE in flash */
+ char default_fname[] = CONFIG_CPM3_SYSFILE;
+ unsigned int br; /* bytes read */
+ uint8_t buffer[RS];
+ int res;
+
+ (void) cmdtp; (void) flag;
+
+
+ common_base = getenv_ulong(PSTR(ENV_CPM3_COMMON_BASE), 16,
+ CONFIG_CPM3_COMMON_BASE);
+ banked_base = getenv_ulong(PSTR(ENV_CPM3_BANKED_BASE), 16,
+ CONFIG_CPM3_BANKED_BASE);
+
+ if (argc > 3)
+ banked_base = strtoul(argv[3], NULL, 16);
+ if (argc > 2)
+ banked_base = strtoul(argv[2], NULL, 16);
+
+ fname = getenv(PSTR(ENV_CPM3_SYSFILE));
+ if (argc > 2) {
+ fname = argv[2];
+ }
+ if (fname == NULL || *fname == '\0')
+ fname = default_fname;
+
+ res = f_open(&File, fname, FA_READ );
+ if (res) {
+ printf_P(PSTR("Error: failed to open '%s'\n"), fname);
+ return CMD_RET_FAILURE;
+ }
+
+ printf_P(PSTR("Loading: '%s'...\n"), fname);
+
+ /* read the load record */
+ res = f_read(&File, buffer, RS, &br);
+ if (res || br != RS)
+ goto out;
+
+ mem_top = buffer[0] << 8;
+ res_len = buffer[1];
+ bank_top = buffer[2] << 8;
+ bank_len = buffer[3];
+ osentry_addr = buffer[4] + (buffer[5] << 8);
+
+ /* read display info */
+ res = f_read(&File, buffer, RS, &br);
+ if (res || br != RS)
+ goto out;
+
+ /* print the info */
+ buffer[RS-1] = '$';
+ uint8_t *p = memchr(buffer, '$', RS);
+ *p = '\0';
+ my_puts((char *)buffer);
+
+ /* Main System Load */
+
+ /* Load Common Portion of System */
+ if ((res = load(&File, common_base + mem_top, res_len)) != 0)
+ goto out;
+
+ /* Load Banked Portion of System */
+ res = load(&File, banked_base + bank_top, bank_len);
+
+out:
+ f_close(&File);
+
+ if (res) {
+ printf_P(PSTR("Error: failed to read '%s'\n"), fname);
+ return CMD_RET_FAILURE;
+ } else {
+ if (res_len != 0) {
+ if (osentry_addr + common_base > 0xffff) {
+ z80_bus_cmd(Request);
+ if (z80_read(osentry_addr + common_base) == 0xc3) {
+ osentry_addr = z80_read(osentry_addr+common_base+1) +
+ (z80_read(osentry_addr + common_base+2) << 8);
+ }
+ z80_bus_cmd(Release);
+ if (banked_base + osentry_addr > 0xffff)
+ osentry_addr = 0;
+ }
+ setenv_hex(PSTR(ENV_STARTADDRESS), osentry_addr);
+ }
+ printf_P(PSTR("Loaded: Resident: "));
+ if (res_len != 0)
+ printf_P(PSTR("0x%.5lX-0x%.5lX, "),
+ (common_base + mem_top) - res_len*256,
+ (common_base + mem_top) - 1);
+ else
+ printf_P(PSTR(" - "));
+ printf_P(PSTR("Banked: "));
+ if (bank_len != 0)
+ printf_P(PSTR("0x%.5lX-0x%.5lX\n"),
+ (banked_base + bank_top) - bank_len*256,
+ (banked_base + bank_top) - 1);
+ else
+ printf_P(PSTR(" - \n"));
+
+ return CMD_RET_SUCCESS;
+ }
+}
diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c
new file mode 100644
index 0000000..18d5331
--- /dev/null
+++ b/avr/cmd_loadihex.c
@@ -0,0 +1,261 @@
+/*
+ * (C) Copyright 2015 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "common.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdbool.h>
+
+#include "command.h"
+#include "con-utils.h"
+#include "z80-if.h"
+#include "debug.h"
+
+
+uint32_t detect_ramsize(void)
+{
+ uint32_t addr;
+ uint8_t save_addr, save_0;
+ const uint8_t PATTERN_1 = 0x55;
+ const uint8_t PATTERN_2 = ~PATTERN_1;
+
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return 0;
+ }
+
+ save_0 = z80_read(0);
+ z80_write(0, PATTERN_1);
+
+ for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) {
+ save_addr = z80_read(addr);
+ z80_write(addr, PATTERN_2);
+ if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2)
+ break;
+ z80_write(addr, save_addr);
+ }
+ z80_write(0, save_0);
+ z80_bus_cmd(Release);
+
+ return addr;
+}
+
+typedef enum {
+ IHX_OK,
+ IHX_BROKEN,
+ IHX_CHKSUMERR
+} ihx_rstat_t;
+
+typedef struct {
+ ihx_rstat_t status;
+ int8_t type;
+ uint8_t len;
+ uint16_t address;
+ uint8_t data[256];
+} ihex_t;
+
+
+static
+int get_hexdigit(void) {
+
+ int c;
+ c = toupper(my_getchar(1));
+ if (isxdigit(c)) {
+ c -= '0';
+ if (c > 9)
+ c -= ('A' - '0' - 10);
+ return c;
+ } else
+ return -1;
+}
+
+static
+int get_hexbyte(void) {
+
+ uint8_t i,j;
+
+ if ((i = (uint8_t) get_hexdigit()) < 0x10)
+ if ((j = (uint8_t) get_hexdigit()) < 0x10) {
+ return (i<<4) + j;
+ }
+
+ return -1;
+}
+
+
+static
+int ihex_get_record(ihex_t *rec) {
+
+ int c;
+ uint8_t sum;
+
+ rec->status = IHX_BROKEN;
+ rec->len = 0;
+ rec->type = 0xff;
+
+ while ((c = my_getchar(0)) != ':') {
+ if (c == 0x03)
+ return -1; /* Control-C */
+ if (c == 0x04) {
+ rec->status = IHX_OK;
+ return 0; /*Control-D, EOF */
+ }
+ }
+
+ if ((c = get_hexbyte()) < 0) /* Start code */
+ return -1;
+ sum = c;
+ rec->len = c;
+ if ((c = get_hexbyte()) < 0) /* Byte Count */
+ return -1;
+ sum += c;
+ rec->address = c * 256;
+ if ((c = get_hexbyte()) < 0) /* Address */
+ return -1;
+ sum += c;
+ rec->address += c;
+ if ((c = get_hexbyte()) < 0) /* Record type */
+ return -1;
+ sum += c;
+ rec->type = c;
+
+ if (rec->len) { /* Record Data */
+ uint8_t n;
+
+ for (n = 0; n < rec->len; n++) {
+ if ((c = get_hexbyte()) < 0)
+ break;
+ sum += c;
+ rec->data[n] = c;
+ }
+
+ if (n < rec->len) {
+ return -1;
+ }
+ }
+
+ c = get_hexbyte(); /* Check sum */
+
+ if (c >= 0) {
+ sum += c;
+ if (sum == 0)
+ rec->status = IHX_OK;
+ else
+ rec->status = IHX_CHKSUMERR;
+ }
+
+ return rec->len;
+}
+
+
+command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ long offset = 0;
+ uint32_t base_address = 0;
+ uint32_t address_max = detect_ramsize();
+ uint32_t address_high = 0;
+ uint32_t address_low = address_max;
+ command_ret_t rcode = CMD_RET_FAILURE;
+ ihex_t rec;
+ bool firstrec = true;
+
+ (void) cmdtp; (void) flag;
+
+
+ if (argc > 1)
+ offset = strtol(argv[1], NULL, 16);
+
+ printf_P(PSTR("Waiting for Intel Hex Records...\n"));
+
+ while (ihex_get_record(&rec) > 0 &&
+ rec.status == IHX_OK &&
+ rec.type != 1 ) {
+
+ switch (rec.type) {
+ case 0: /* Data record */
+ if (firstrec) {
+ printf_P(PSTR("Loading: 0x....."));
+ firstrec = false;
+ }
+ if (rec.len) {
+ uint32_t addr = base_address + rec.address + offset;
+ if (addr < address_low)
+ address_low = addr;
+ if (addr+rec.len > address_high)
+ address_high = addr + rec.len;
+
+// debug("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n",
+// address_low, address_high, address_max, addr, rec.len);
+ printf_P(PSTR("\b\b\b\b\b%.5lX"), addr);
+ if (addr < address_max) {
+ uint32_t tmplen = address_max - addr;
+ if (rec.len > tmplen)
+ rec.len = tmplen;
+
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return CMD_RET_FAILURE;
+ }
+ z80_write_block(rec.data, /* src */
+ addr, /* dest */
+ rec.len); /* len */
+ z80_bus_cmd(Release);
+ }
+ }
+ break;
+
+#if 0
+ case 1: /* EOF record */
+ break;
+#endif
+ case 2: /* Extended Segment Address Record */
+ base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 4;
+ break;
+
+ case 4: /* Extended Linear Address Record */
+ base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16;
+ break;
+
+ case 3: /* Start Segment Address Record (ignored)*/
+ case 5: /* Start Linear Address Record (ignored)*/
+ break;
+
+ }
+ }
+
+ switch (rec.status) {
+ case IHX_OK:
+ rcode = CMD_RET_SUCCESS;
+ break;
+
+ case IHX_BROKEN:
+ case IHX_CHKSUMERR:
+ printf_P(PSTR("Broken Hex Record or loading interrupted!\n"));
+ break;
+ }
+
+
+ for (uint_fast8_t i=0; i<100; ++i) {
+ /* flush input buffer */
+ while (my_getchar(0) > 0)
+ ;
+ udelay(1000);
+ }
+
+
+ printf_P(PSTR("\nData loaded: "));
+ if (address_low >= MIN(address_high, address_max))
+ printf_P(PSTR("None.\n"));
+ else
+ printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low,
+ MIN(address_high, address_max) - 1);
+
+ if (address_high > address_max)
+ printf_P(PSTR("Data above highest RAM address "
+ "(in range 0x%.5lX - 0x%.5lX) ignored!\n"), address_max, address_high - 1);
+
+ return rcode;
+}
diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c
index 0bc5742..101b912 100644
--- a/avr/cmd_mem.c
+++ b/avr/cmd_mem.c
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -14,13 +16,15 @@
#include "common.h"
#include <stdlib.h>
#include <ctype.h>
+#include <avr/interrupt.h>
#include "command.h"
#include "cli_readline.h"
#include "print-utils.h"
#include "con-utils.h"
+#include "timer.h"
#include "z80-if.h"
-//#include "debug.h"
+#include "debug.h"
#ifndef CONFIG_SYS_MEMTEST_SCRATCH
@@ -148,8 +152,8 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
if (incrflag)
addr += nbytes ? -1 : 1;
nbytes = 1;
- }
- else {
+
+ } else {
char *endp;
data = strtoul(console_buffer, &endp, 16);
nbytes = endp - console_buffer;
@@ -220,55 +224,35 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
#ifdef CONFIG_MX_CYCLIC
command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- int i;
uint32_t count;
+ uint32_t ts;
+
+ (void) cmdtp;
+ (void) flag;
if (argc < 4)
return CMD_RET_USAGE;
count = strtoul(argv[3], NULL, 10);
+ clear_ctrlc(); /* forget any previous Control C */
for (;;) {
- do_mem_md (NULL, 0, 3, argv);
-
- /* delay for <count> ms... */
-/* TODO: use timer */
- for (i=0; i<count; i++)
- udelay (1000);
-
- /* check for ctrl-c to abort... */
- if (ctrlc()) {
- my_puts_P(PSTR("Abort\n"));
- return CMD_RET_SUCCESS;
- }
- }
-
- return CMD_RET_SUCCESS;
-}
-
-command_ret_t do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- int i;
- uint32_t count;
- if (argc < 4)
- return CMD_RET_USAGE;
-
- count = strtoul(argv[3], NULL, 10);
+ if (argv[0][1] == 'd')
+ do_mem_md (NULL, 0, 3, argv);
+ else
+ do_mem_mw (NULL, 0, 3, argv);
- for (;;) {
- do_mem_mw (NULL, 0, 3, argv);
/* delay for <count> ms... */
-/* TODO: use timer */
- for (i=0; i<count; i++)
- udelay (1000);
-
- /* check for ctrl-c to abort... */
- if (ctrlc()) {
- my_puts_P(PSTR("Abort\n"));
- return CMD_RET_SUCCESS;
- }
+ ts = get_timer(0);
+ do {
+ /* check for ctrl-c to abort... */
+ if (had_ctrlc() || ctrlc()) {
+ my_puts_P(PSTR("Abort\n"));
+ return CMD_RET_SUCCESS;
+ }
+ } while (get_timer(ts) < count);
}
return CMD_RET_SUCCESS;
@@ -415,27 +399,26 @@ command_ret_t do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
my_puts_P(PSTR("Bus timeout\n"));
return CMD_RET_FAILURE;
}
+ cli();
for (;;)
z80_read(addr);
- z80_bus_cmd(Release);
}
if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
my_puts_P(PSTR("Bus timeout\n"));
return CMD_RET_FAILURE;
}
+ cli();
for (;;) {
uint32_t i = length;
uint32_t p = addr;
while (i-- > 0)
z80_read(p++);
}
- z80_bus_cmd(Release);
return CMD_RET_SUCCESS;
}
-#ifdef CONFIG_LOOPW
command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
uint32_t addr, length;
@@ -455,7 +438,8 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a
data = strtoul(argv[3], NULL, 16);
- /* We want to optimize the loops to run as fast as possible.
+ /*
+ * We want to optimize the loops to run as fast as possible.
* If we have only one object, just run infinite loops.
*/
if (length == 1) {
@@ -463,6 +447,7 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a
my_puts_P(PSTR("Bus timeout\n"));
return CMD_RET_FAILURE;
}
+ cli();
for (;;)
z80_write(addr, data);
}
@@ -471,6 +456,7 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a
my_puts_P(PSTR("Bus timeout\n"));
return CMD_RET_FAILURE;
}
+ cli();
for (;;) {
uint32_t i = length;
uint32_t p = addr;
@@ -478,35 +464,33 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a
z80_write(p++, data);
}
}
-#endif /* CONFIG_LOOPW */
+
+//#define CONFIG_SYS_ALT_MEMTEST
#ifdef CONFIG_CMD_MEMTEST
-static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_addr,
- vu_long *dummy)
+static uint32_t mem_test_alt(uint32_t start_addr, uint32_t end_addr)
{
- vu_long *addr;
+ uint32_t addr;
+ uint32_t dummy;
uint32_t errs = 0;
- uint32_t val, readback;
- int j;
- vu_long offset;
- vu_long test_offset;
- vu_long pattern;
- vu_long temp;
- vu_long anti_pattern;
- vu_long num_words;
- static const FLASH uint32_t bitpattern[] = {
- 0x00000001, /* single bit */
- 0x00000003, /* two adjacent bits */
- 0x00000007, /* three adjacent bits */
- 0x0000000F, /* four adjacent bits */
- 0x00000005, /* two non-adjacent bits */
- 0x00000015, /* three non-adjacent bits */
- 0x00000055, /* four non-adjacent bits */
- 0xaaaaaaaa, /* alternating 1/0 */
+ uint32_t offset;
+ uint32_t test_offset;
+ uint8_t pattern;
+ uint8_t anti_pattern;
+ uint8_t temp;
+ uint32_t num_bytes;
+
+ static const FLASH uint8_t bitpattern[] = {
+ 0x01, /* single bit */
+ 0x03, /* two adjacent bits */
+ 0x07, /* three adjacent bits */
+ 0x0F, /* four adjacent bits */
+ 0x05, /* two non-adjacent bits */
+ 0x15, /* three non-adjacent bits */
+ 0x55, /* four non-adjacent bits */
+ 0xaa, /* alternating 1/0 */
};
- num_words = (end_addr - start_addr) / sizeof(vu_long);
-
/*
* Data line test: write a pattern to the first
* location, write the 1's complement to a 'parking'
@@ -524,35 +508,39 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
* '0's and '0' bits through a field of '1's (i.e.
* pattern and ~pattern).
*/
- addr = buf;
- for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
- val = bitpattern[j];
- for (; val != 0; val <<= 1) {
- *addr = val;
- *dummy = ~val; /* clear the test data off the bus */
- readback = *addr;
- if (readback != val) {
+ addr = start_addr;
+ dummy = start_addr+1;
+ for (unsigned int j = 0; j < ARRAY_SIZE(bitpattern); j++) {
+ pattern = bitpattern[j];
+ for (; pattern != 0; pattern <<= 1) {
+ anti_pattern = ~pattern;
+ z80_write(addr, pattern);
+ z80_write(dummy, anti_pattern); /* clear the test data off the bus */
+ temp = z80_read(addr);
+ if (temp != pattern) {
printf_P(PSTR("FAILURE (data line): "
- "expected %05lx, actual %05lx\n"),
- val, readback);
+ "expected %02x, actual %02x\n"),
+ pattern, temp);
errs++;
- if (ctrlc())
- return -1;
}
- *addr = ~val;
- *dummy = val;
- readback = *addr;
- if (readback != ~val) {
+ z80_write(addr, anti_pattern);
+ z80_write(dummy, pattern); /* clear the test data off the bus */
+ temp = z80_read(addr);
+ if (temp != anti_pattern) {
printf_P(PSTR("FAILURE (data line): "
- "Is %05lx, should be %05lx\n"),
- readback, ~val);
+ "Is %02x, should be %02x\n"),
+ temp, anti_pattern);
errs++;
- if (ctrlc())
- return -1;
}
}
+
+ if (ctrlc())
+ return -1;
}
+ if (errs)
+ return errs;
+
/*
* Based on code whose Original Author and Copyright
* information follows: Copyright (c) 1998 by Michael
@@ -587,59 +575,61 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
*
* Returns: 0 if the test succeeds, 1 if the test fails.
*/
- pattern = (vu_long) 0xaaaaaaaa;
- anti_pattern = (vu_long) 0x55555555;
- debug("%s:%d: length = 0x%.5lx\n", __func__, __LINE__, num_words);
+ num_bytes = (end_addr - start_addr) / sizeof(uint8_t);
+
+ pattern = 0xaa;
+ anti_pattern = 0x55;
+
+// debug("## %s:%d: length = 0x%.5lx\n", __func__, __LINE__, num_bytes);
/*
* Write the default pattern at each of the
* power-of-two offsets.
*/
- for (offset = 1; offset < num_words; offset <<= 1)
- addr[offset] = pattern;
+ for (offset = 1; offset < num_bytes; offset <<= 1)
+ z80_write(addr+offset, pattern);
/*
* Check for address bits stuck high.
*/
- test_offset = 0;
- addr[test_offset] = anti_pattern;
+ z80_write(start_addr, anti_pattern);
- for (offset = 1; offset < num_words; offset <<= 1) {
- temp = addr[offset];
+ for (offset = 1; offset < num_bytes; offset <<= 1) {
+ temp = z80_read(start_addr + offset);
if (temp != pattern) {
- printf_P(PSTR("\nFAILURE: Address bit stuck high @ 0x%.5lx:"
- " expected 0x%.5lx, actual 0x%.5lx\n"),
- start_addr + offset*sizeof(vu_long),
- pattern, temp);
+ printf_P(PSTR("FAILURE: Address bit stuck high @ 0x%.5lx:"
+ " expected 0x%.2x, actual 0x%.2x\n"),
+ start_addr + offset, pattern, temp);
errs++;
if (ctrlc())
return -1;
}
}
- addr[test_offset] = pattern;
+ z80_write(start_addr, pattern);
/*
* Check for addr bits stuck low or shorted.
*/
- for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
- addr[test_offset] = anti_pattern;
+ for (test_offset = 1; test_offset < num_bytes; test_offset <<= 1) {
+ z80_write(start_addr + test_offset, anti_pattern);
- for (offset = 1; offset < num_words; offset <<= 1) {
- temp = addr[offset];
+ for (offset = 1; offset < num_bytes; offset <<= 1) {
+ temp = z80_read(start_addr + offset);
if ((temp != pattern) && (offset != test_offset)) {
- printf_P(PSTR("\nFAILURE: Address bit stuck low or"
- " shorted @ 0x%.5lx: expected 0x%.5lx,"
- " actual 0x%.5lx\n"),
- start_addr + offset*sizeof(vu_long),
- pattern, temp);
+ printf_P(PSTR("FAILURE: Address bit stuck low or shorted"
+ " @ 0x%.5lx: expected 0x%.2x, actual 0x%.2x\n"),
+ start_addr + offset, pattern, temp);
errs++;
if (ctrlc())
return -1;
}
}
- addr[test_offset] = pattern;
+ z80_write(start_addr + test_offset, pattern);
}
+ if (errs)
+ return errs;
+
/*
* Description: Test the integrity of a physical
* memory device by performing an
@@ -652,111 +642,50 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
*
* Returns: 0 if the test succeeds, 1 if the test fails.
*/
- num_words++;
+ num_bytes++;
/*
* Fill memory with a known pattern.
*/
- for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
- addr[offset] = pattern;
- }
+ for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++)
+ z80_write(addr, pattern);
/*
* Check each location and invert it for the second pass.
*/
- for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
- temp = addr[offset];
+ for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++) {
+ temp = z80_read(addr);
if (temp != pattern) {
- printf_P(PSTR("\nFAILURE (read/write) @ 0x%.5lx:"
- " expected 0x%.5lx, actual 0x%.5lx)\n"),
- start_addr + offset*sizeof(vu_long),
- pattern, temp);
+ printf_P(PSTR("FAILURE (read/write) @ 0x%.5lx:"
+ " expected 0x%.2x, actual 0x%.2x)\n"),
+ addr, pattern, temp);
errs++;
if (ctrlc())
return -1;
}
anti_pattern = ~pattern;
- addr[offset] = anti_pattern;
+ z80_write(addr, anti_pattern);
}
/*
* Check each location for the inverted pattern and zero it.
*/
- for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
- WATCHDOG_RESET();
+ for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++) {
anti_pattern = ~pattern;
- temp = addr[offset];
+ temp = z80_read(addr);
if (temp != anti_pattern) {
- printf_P(PSTR("\nFAILURE (read/write): @ 0x%.5lx:"
- " expected 0x%.5lx, actual 0x%.5lx)\n"),
- start_addr + offset*sizeof(vu_long),
- anti_pattern, temp);
+ printf_P(PSTR("FAILURE (read/write) @ 0x%.5lx:"
+ " expected 0x%.2x, actual 0x%.2x)\n"),
+ start_addr, anti_pattern, temp);
errs++;
if (ctrlc())
return -1;
}
- addr[offset] = 0;
+ z80_write(addr, 0);
}
- return 0;
-}
-
-static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_addr,
- vu_long pattern, int iteration)
-{
- vu_long *end;
- vu_long *addr;
- uint32_t errs = 0;
- uint32_t incr, length;
- uint32_t val, readback;
-
- /* Alternate the pattern */
- incr = 1;
- if (iteration & 1) {
- incr = -incr;
- /*
- * Flip the pattern each time to make lots of zeros and
- * then, the next time, lots of ones. We decrement
- * the "negative" patterns and increment the "positive"
- * patterns to preserve this feature.
- */
- if (pattern & 0x80000000)
- pattern = -pattern; /* complement & increment */
- else
- pattern = ~pattern;
- }
- length = (end_addr - start_addr) / sizeof(uint32_t);
- end = buf + length;
- printf_P(PSTR("\rPattern %08lX Writing..."
- "%12s"
- "\b\b\b\b\b\b\b\b\b\b"),
- pattern, "");
-
- for (addr = buf, val = pattern; addr < end; addr++) {
- *addr = val;
- val += incr;
- }
-
- my_puts_P(PSTR("Reading..."));
-
- for (addr = buf, val = pattern; addr < end; addr++) {
- readback = *addr;
- if (readback != val) {
- uint32_t offset = addr - buf;
-
- printf_P(PSTR("\nMem error @ 0x%08X: "
- "found %08lX, expected %08lX\n"),
- (unsigned int)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
- readback, val);
- errs++;
- if (ctrlc())
- return -1;
- }
- val += incr;
- }
-
- return 0;
+ return errs;
}
/*
@@ -767,77 +696,61 @@ static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_a
command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
- uint32_t start, end;
- vu_long *buf, *dummy;
- int iteration_limit;
-/* TODO: command_ret_t */
+ uint32_t start = 0;
+ uint32_t end;
+ unsigned int iteration_limit = 0;
+ unsigned int iteration;
+ uint32_t errs = 0; /* number of errors */
int ret;
- uint32_t errs = 0; /* number of errors, or -1 if interrupted */
- uint32_t pattern;
- int iteration;
-#if defined(CONFIG_SYS_ALT_MEMTEST)
- const int alt_test = 1;
-#else
- const int alt_test = 0;
-#endif
+
+ (void) cmdtp;
+ (void) flag;
if (argc > 1)
start = strtoul(argv[1], NULL, 16);
- else
- start = CONFIG_SYS_MEMTEST_START;
if (argc > 2)
end = strtoul(argv[2], NULL, 16);
else
- end = CONFIG_SYS_MEMTEST_END;
+ end = CONFIG_SYS_RAMSIZE_MAX - 1;
if (argc > 3)
- pattern = (uint32_t)strtoul(argv[3], NULL, 16);
- else
- pattern = 0;
+ iteration_limit = (unsigned int) strtoul(argv[3], NULL, 16);
- if (argc > 4)
- iteration_limit = (uint32_t)strtoul(argv[4], NULL, 16);
- else
- iteration_limit = 0;
+ printf_P(PSTR("Testing %05lx ... %05lx:\n"), start, end);
+// debug("## %s:%d: start %#05lx end %#05lx\n", __func__, __LINE__, start, end);
- printf_P(PSTR("Testing %08x ... %08x:\n"), (unsigned int)start, (unsigned int)end);
- debug("%s:%d: start %#05lx end %#05lx\n", __func__, __LINE__,
- start, end);
+ clear_ctrlc(); /* forget any previous Control C */
-/* TODO: */
-// buf = map_sysmem(start, end - start);
-// dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
for (iteration = 0;
!iteration_limit || iteration < iteration_limit;
iteration++) {
- if (ctrlc()) {
- errs = -1UL;
- break;
- }
printf_P(PSTR("Iteration: %6d\r"), iteration + 1);
- debug("\n");
- if (alt_test) {
- errs = mem_test_alt(buf, start, end, dummy);
- } else {
- errs = mem_test_quick(buf, start, end, pattern,
- iteration);
+// debug("\n");
+
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return CMD_RET_FAILURE;
}
- if (errs == -1UL)
+ errs += mem_test_alt(start, end);
+ z80_bus_cmd(Release);
+
+ if (had_ctrlc() || ctrlc()) {
break;
+ }
}
- if (errs == -1UL) {
+ if (had_ctrlc()) {
/* Memory test was aborted - write a newline to finish off */
- putc('\n');
- ret = 1;
+ putchar('\n');
+ ret = CMD_RET_FAILURE;
} else {
printf_P(PSTR("Tested %d iteration(s) with %lu errors.\n"),
iteration, errs);
- ret = errs != 0;
+ ret = errs ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
}
- return ret; /* not reached */
+ return ret;
}
#endif /* CONFIG_CMD_MEMTEST */
diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c
index 315b959..c9a3c45 100644
--- a/avr/cmd_misc.c
+++ b/avr/cmd_misc.c
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* Copyright 2000-2009
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -7,46 +9,43 @@
#include "common.h"
#include <stdlib.h>
+#include <stdbool.h>
#include "command.h"
#include "timer.h"
#include "con-utils.h"
+#include "getopt-min.h"
command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- uint_fast8_t putnl = 1;
+ bool put_newline = true;
(void) cmdtp; (void) flag;
- for (uint_fast8_t i = 1; i < argc; i++) {
+ /* reset getopt() */
+ optind = 1;
+
+ int opt;
+ while ((opt = getopt(argc, argv, PSTR("n"))) != -1) {
+ switch (opt) {
+ case 'n':
+ put_newline = false;
+ break;
+ default: /* '?' */
+ return CMD_RET_USAGE;
+ }
+ }
- uint_fast8_t backslash = 0;
- char *p = argv[i];
- char c;
+ for (uint_fast8_t i = optind; i < argc; i++) {
- if (i != 1)
+ if (i != optind)
putchar(' ');
- while ((c = *p++) != '\0') {
-
- if(backslash) {
- backslash = 0;
- if (c == 'c') {
- putnl = 0;
- continue;
- } else
- putchar('\\');
- } else {
- if (c == '\\') {
- backslash = 1;
- continue;
- }
- }
- putchar(c);
- }
+
+ my_puts(argv[i]);
}
- if (putnl)
+ if (put_newline)
putchar('\n');
return CMD_RET_SUCCESS;
@@ -88,4 +87,3 @@ command_ret_t do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
return CMD_RET_SUCCESS;
}
-
diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c
index 5494a13..6b75d6e 100644
--- a/avr/cmd_sd.c
+++ b/avr/cmd_sd.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <stdlib.h>
@@ -9,11 +15,11 @@
/*
- * di <pd#> - Initialize disk
+ * status <pd#> - Show socket status
*
*/
static
-command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
DSTATUS res;
BYTE dev;
@@ -25,26 +31,50 @@ command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
dev = (BYTE) strtoul(argv[1], 0, 10);
res = disk_status(dev);
- printf_P(PSTR("disk_status=%.2x\n"), res);
+ printf_P(PSTR("Socket status: %02x\n"), res);
+
+ return CMD_RET_SUCCESS;
+}
+
+/*
+ * init <pd#> - Initialize disk
+ *
+ */
+static
+command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ DSTATUS res;
+ BYTE dev;
+
+ (void) cmdtp; (void) flag;
- if ((res & STA_NODISK) == 0) {
- res = disk_initialize(dev);
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ dev = (BYTE) strtoul(argv[1], 0, 10);
+
+ if (disk_status(dev) & STA_NODISK) {
+ printf_P(PSTR("No Disk\n"));
+ return CMD_RET_FAILURE;
}
+
+ res = disk_initialize(dev);
printf_P(PSTR("rc=%.2x\n"), res);
- if (res) {
+
+ if (res & (STA_NODISK | STA_NOINIT))
return CMD_RET_FAILURE;
- }
return CMD_RET_SUCCESS;
}
/*
- * ds <pd#> - Show disk status
+ * info <pd#> - Show disk info
*
*/
static
-command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ DSTATUS res;
BYTE dev;
union {
@@ -60,6 +90,12 @@ command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
dev = (BYTE) strtoul(argv[1], 0, 10);
+ res = disk_status(dev);
+ if (res & (STA_NODISK | STA_NOINIT)) {
+ printf_P(res & STA_NODISK ?
+ PSTR("No disk\n") : PSTR("Not initialized\n"));
+ return CMD_RET_FAILURE;
+ }
if (disk_ioctl(dev, GET_SECTOR_COUNT, &dat.ul) == RES_OK)
printf_P(PSTR("Drive size: %lu sectors\n"), dat.ul);
@@ -259,7 +295,7 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
/*
* Disk ioctl
- * dcs <pd#> - CTRL_SYNC
+ * sync <pd#> - CTRL_SYNC
*
*/
static
@@ -284,29 +320,34 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
cmd_tbl_t cmd_sd_sub[] = {
CMD_TBL_ITEM(
+ status, 2, 1, do_status,
+ "Socket staus",
+ ""
+),
+CMD_TBL_ITEM(
init, 2, 1, do_init,
"Initialize disk",
""
),
CMD_TBL_ITEM(
- status, 2, 1, do_status,
- "Disk status",
+ info, 2, 1, do_info,
+ "Disk info",
""
),
CMD_TBL_ITEM(
dump, CONFIG_SYS_MAXARGS, 1, do_dump,
- "Dump sector",
- ""
+ "Dump sector(s)",
+ "<drive> [sector [count ]]"
),
CMD_TBL_ITEM(
read, 2, 1, do_read,
- "read disk sector(s) into meomory",
- "drive [sector [count [memaddr]]]"
+ "Read disk sector(s) into meomory",
+ "<drive> [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
write, 2, 1, do_write,
- "write sector(s) from meomory to disk",
- "drive [sector [count [memaddr]]]"
+ "Write sector(s) from meomory to disk",
+ "<drive> [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
sync, 2, 1, do_ioctl_sync,
@@ -316,7 +357,7 @@ CMD_TBL_ITEM(
CMD_TBL_ITEM(
help, CONFIG_SYS_MAXARGS, 1, do_help,
- "print sub command description/usage",
+ "Print sub command description/usage",
"\n"
" - print brief description of all sub commands\n"
"sd help command ...\n"
@@ -325,7 +366,7 @@ CMD_TBL_ITEM(
/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
{FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
- FSTR("alias for 'help'"),
+ FSTR("Alias for 'help'"),
#ifdef CONFIG_SYS_LONGHELP
FSTR(""),
#endif /* CONFIG_SYS_LONGHELP */
diff --git a/avr/command.c b/avr/command.c
index c080527..ed25dee 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -1,4 +1,13 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
* Command Processor Table
*/
@@ -111,7 +120,7 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
*/
for (i = 1; i < argc; ++i) {
if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) {
- rcode = cmd_usage(cmdtp);
+ cmd_usage(cmdtp);
} else {
printf_P(PSTR("Unknown command '%s' - try 'help'"
" without arguments.\n\n"), argv[i]
@@ -140,8 +149,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
for (cmdtp = table;
cmdtp != table + table_len;
cmdtp++) {
- if (strncmp_P (cmd, cmdtp->name, len) == 0) {
- if (len == strlen (cmdtp->name))
+ if (strncmp_P(cmd, cmdtp->name, len) == 0) {
+ if (len == strlen_P(cmdtp->name))
return cmdtp; /* full match */
cmdtp_temp = cmdtp; /* abbreviated command ? */
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index 02d8ac8..72a87b9 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -1,10 +1,13 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
#include "common.h"
-
#include "command.h"
#include "cmd_mem.h"
-
extern command_ret_t do_help(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_echo(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_sleep(cmd_tbl_t *, int, int, char * const []);
@@ -13,10 +16,17 @@ extern command_ret_t do_env_default(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_env_set(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_env_save(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_loadf(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_loadcpm3(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_loadihex(cmd_tbl_t *, int, int, char * const []);
+#if defined(CONFIG_CMD_LOADB)
+extern command_ret_t do_load_serial_bin(cmd_tbl_t *, int, int, char * const []);
+#endif
extern command_ret_t do_go(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_restart(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_console(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_dump_mem(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_mem_mm_avr(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_mem_nm_avr(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_eep_cp(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_busreq_pulse(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_date(cmd_tbl_t *, int, int, char * const []);
@@ -24,8 +34,9 @@ extern command_ret_t do_gpio(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_sd(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_fat_stat(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_fat_ls(cmd_tbl_t *, int, int, char * const []);
-extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []);
-extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []);
+//extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []);
+//extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_fat_rw(cmd_tbl_t *, int, int, char * const []);
#ifdef CONFIG_SYS_LONGHELP
const FLASH char sd_help_text[] =
@@ -38,14 +49,14 @@ cmd_tbl_t cmd_tbl[] = {
CMD_TBL_ITEM(
date, 2, 1, do_date,
- "get/set/reset date & time",
+ "get/set date & time",
"[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n"
" - without arguments: print date & time\n"
" - with numeric argument: set the system date & time\n"
- " - with 'reset' argument: reset the RTC"
),
#ifdef DEBUG
+
CMD_TBL_ITEM(
!mdr, 3, 1, do_dump_mem,
"RAM dump",
@@ -57,10 +68,25 @@ CMD_TBL_ITEM(
"address [count]"
),
CMD_TBL_ITEM(
+ !mdf, 3, 1, do_dump_mem,
+ "FLASH dump",
+ "address [count]"
+),
+CMD_TBL_ITEM(
!cpe, 4, 0, do_eep_cp,
"EEPROM copy",
"source target count"
),
+CMD_TBL_ITEM(
+ !mm, 2, 1, do_mem_mm_avr,
+ "avr memory modify (auto-incrementing address)",
+ "address"
+),
+CMD_TBL_ITEM(
+ !nm, 2, 1, do_mem_nm_avr,
+ "avr memory modify (constant address)",
+ "address"
+),
#endif
CMD_TBL_ITEM(
mstep, 2, 1, do_busreq_pulse,
@@ -70,9 +96,10 @@ CMD_TBL_ITEM(
),
CMD_TBL_ITEM(
echo, CONFIG_SYS_MAXARGS, 1, do_echo,
- "echo args to console",
- "[args..]\n"
- " - echo args to console; \\c suppresses newline"
+ "display a line of text",
+ "[-n] [argument ...]\n"
+ " - echo the argument(s) to console.\n"
+ " -n do not output the trailing newline"
),
CMD_TBL_ITEM(
sleep , 2, 1, do_sleep,
@@ -122,6 +149,43 @@ CMD_TBL_ITEM(
""
),
CMD_TBL_ITEM(
+ loadcpm3, 3, 0, do_loadcpm3,
+ "load CPM3.SYS file",
+ "[filename] [common base] [banked base]] \n"
+ " Load CP/M 3 system file from FAT filesystem. This command makes\n"
+ " CPMLDR superfluous. Uses the following environment variable if set:\n"
+ " '"ENV_CPM3_SYSFILE"' File to load. Default is '"CONFIG_CPM3_SYSFILE"'.\n"
+ " '"ENV_CPM3_COMMON_BASE"' Default is '"CONFIG_CPM3_COMMON_BASE_STR"'.\n"
+ " '"ENV_CPM3_BANKED_BASE"' Default is '"CONFIG_CPM3_BANKED_BASE_STR"'.\n"
+),
+CMD_TBL_ITEM(
+ loadi, 2, 0, do_loadihex,
+ "load intel hex file over serial line",
+ "[[-]offset]\n"
+ " - load Intel-Hex-Record file over serial line with offset 'offset'"
+),
+
+#if defined(CONFIG_CMD_LOADB)
+CMD_TBL_ITEM(
+ loadb, 1, 0, do_load_serial_bin,
+ "load binary file over serial line (kermit mode)",
+ " - load binary file over serial line"
+),
+
+CMD_TBL_ITEM(
+ loadx, 1, 0, do_load_serial_bin,
+ "load binary file over serial line (xmodem mode)",
+ " - load binary file over serial line"
+),
+
+CMD_TBL_ITEM(
+ loady, 1, 0, do_load_serial_bin,
+ "load binary file over serial line (ymodem mode)",
+ " - load binary file over serial line"
+),
+#endif /* CONFIG_CMD_LOADB */
+
+CMD_TBL_ITEM(
go, 2, 0, do_go,
"start application at address 'addr'",
"addr\n"
@@ -140,7 +204,7 @@ CMD_TBL_ITEM(
""
),
CMD_TBL_ITEM(
- connect, 1, 1, do_console,
+ connect, 1, 0, do_console,
"Connect to CPU console i/o",
""
),
@@ -202,23 +266,21 @@ CMD_TBL_ITEM(
" - set address offset for memory commands to 'offset'"
),
CMD_TBL_ITEM(
- loop, 3, 1, do_mem_loop,
+ mloop, 3, 1, do_mem_loop,
"infinite loop on address range",
"address number_of_bytes"
),
-#ifdef CONFIG_LOOPW
CMD_TBL_ITEM(
- loopw, 4, 1, do_mem_loopw,
+ mloopw, 4, 1, do_mem_loopw,
"infinite write loop on address range",
"address number_of_bytes data_to_write"
),
-#endif /* CONFIG_LOOPW */
#ifdef CONFIG_CMD_MEMTEST
CMD_TBL_ITEM(
- mtest, 5, 1, do_mem_mtest,
+ mtest, 4, 1, do_mem_mtest,
"simple RAM read/write test",
- "[start [end [pattern [iterations]]]]"
+ "[start [end [iterations]]]"
),
#endif /* CONFIG_CMD_MEMTEST */
@@ -229,7 +291,7 @@ CMD_TBL_ITEM(
"address count delay(ms)"
),
CMD_TBL_ITEM(
- mwc, 4, 1, do_mem_mwc,
+ mwc, 4, 1, do_mem_mdc,
"memory write cyclic",
"address value delay(ms)"
),
@@ -254,7 +316,7 @@ CMD_TBL_ITEM(
"path"
),
CMD_TBL_ITEM(
- fatload, 5, 0, do_fat_read,
+ fatload, 5, 0, do_fat_rw,
"load binary file from a dos filesystem",
"<d:/path/filename> <addr> [bytes [pos]]\n"
" - Load binary file 'path/filename' on logical drive 'd'\n"
@@ -265,11 +327,12 @@ CMD_TBL_ITEM(
" the load stops on end of file."
),
CMD_TBL_ITEM(
- fatwrite, 4, 0, do_fat_write,
+ fatwrite, 4, 0, do_fat_rw,
"write file into a dos filesystem",
"<d:/path/filename> <addr> <bytes>\n"
- " - write file 'filename' from the address 'addr' in RAM\n"
- " to 'dev' on 'interface'"
+ " - Write file to 'path/filename' on logical drive 'd' from RAM\n"
+ " starting at address 'addr'. 'bytes' gives the size to load.\n"
+ " If 'bytes' is 0 or omitted, the load stops on end of file."
),
CMD_TBL_ITEM(
diff --git a/avr/con-utils.c b/avr/con-utils.c
index f4023ff..5ee1ff1 100644
--- a/avr/con-utils.c
+++ b/avr/con-utils.c
@@ -1,7 +1,14 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
-#include <string.h>
#include "common.h"
+#include <string.h>
+#include <avr/wdt.h>
+#include "config.h"
#include "serial.h"
#include "background.h"
#include "con-utils.h"
@@ -21,6 +28,31 @@ int my_getchar(uint_fast8_t waitforchar)
c = serial_getc();
} while ((c < 0) && waitforchar);
+#ifdef CONFIG_SYS_FBOOTSIG
+ if (c < 0)
+ return c;
+
+ static const FLASH unsigned char bootsig[] = {CONFIG_SYS_FBOOTSIG};
+ static uint8_t pb;
+ unsigned char uc = c;
+
+
+ if (bootsig[pb] == 0) {
+ if (uc == 0xff) {
+ wdt_enable(WDTO_15MS);
+ for(;;)
+ ;
+ } else
+ pb = 0;
+
+ } else {
+ if (bootsig[pb] == uc)
+ pb++;
+ else
+ pb = 0;
+ }
+#endif
+
return c;
}
diff --git a/avr/date.c b/avr/date.c
deleted file mode 100644
index c85361f..0000000
--- a/avr/date.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier: GPL-2.0+
- */
-
-/*
- * Date & Time support for RTC
- */
-
-#include <common.h>
-#include <command.h>
-#include <rtc.h>
-
-
-#define FEBRUARY 2
-#define STARTOFTIME 1970
-#define SECDAY 86400L
-#define SECYR (SECDAY * 365)
-#define leapyear(year) ((year) % 4 == 0)
-#define days_in_year(a) (leapyear(a) ? 366 : 365)
-#define days_in_month(a) (month_days[(a) - 1])
-
-
-static const FLASH int MonthOffset[] = {
- 0,31,59,90,120,151,181,212,243,273,304,334
-};
-
-/*
- * This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
- */
-void GregorianDay(struct rtc_time * tm)
-{
- int leapsToDate;
- int lastYear;
- int day;
-
- lastYear=tm->tm_year-1;
-
- /*
- * Number of leap corrections to apply up to end of last year
- */
- leapsToDate = lastYear/4 - lastYear/100 + lastYear/400;
-
- /*
- * This year is a leap year if it is divisible by 4 except when it is
- * divisible by 100 unless it is divisible by 400
- *
- * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be
- */
- if((tm->tm_year%4==0) &&
- ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) &&
- (tm->tm_mon>2)) {
- /*
- * We are past Feb. 29 in a leap year
- */
- day=1;
- } else {
- day=0;
- }
-
- day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday;
-
- tm->tm_wday=day%7;
-}
-
-void to_tm(unsigned long tim, struct rtc_time * tm)
-{
- char month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
- register int i;
- register long hms, day;
-
- day = tim / SECDAY;
- hms = tim % SECDAY;
-
- /* Hours, minutes, seconds are easy */
- tm->tm_hour = hms / 3600;
- tm->tm_min = (hms % 3600) / 60;
- tm->tm_sec = (hms % 3600) % 60;
-
- /* Number of years in days */
- for (i = STARTOFTIME; day >= days_in_year(i); i++) {
- day -= days_in_year(i);
- }
- tm->tm_year = i;
-
- /* Number of months in days left */
- if (leapyear(tm->tm_year)) {
- days_in_month(FEBRUARY) = 29;
- }
- for (i = 1; day >= days_in_month(i); i++) {
- day -= days_in_month(i);
- }
- days_in_month(FEBRUARY) = 28;
- tm->tm_mon = i;
-
- /* Days are what is left over (+1) from all that. */
- tm->tm_mday = day + 1;
-
- /*
- * Determine the day of week
- */
- GregorianDay(tm);
-}
-
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
- * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
- * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
- *
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
- */
-unsigned long
-mktime (unsigned int year, unsigned int mon,
- unsigned int day, unsigned int hour,
- unsigned int min, unsigned int sec)
-{
- if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
- mon += 12; /* Puts Feb last since it has leap day */
- year -= 1;
- }
-
- return (((
- (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
- year*365 - 719499
- )*24 + hour /* now have hours */
- )*60 + min /* now have minutes */
- )*60 + sec; /* finally seconds */
-}
-
diff --git a/avr/debug.c b/avr/debug.c
index 27b5329..f3632c2 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <stdlib.h>
#include <string.h>
@@ -5,8 +11,10 @@
#include <avr/eeprom.h>
#include "command.h"
+#include "cli_readline.h"
#include "print-utils.h"
#include "debug.h"
+
/*
* Debugging
*/
@@ -32,7 +40,7 @@ void dump_heap(void)
*/
command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count);
+ void (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
(void) cmdtp; (void) flag;
@@ -42,12 +50,19 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
uint32_t addr;
uint32_t length = 128;
- if (strchr(argv[0],'r') != NULL)
- readhow = ram_read_buf;
- else if (strchr(argv[0],'e') != NULL)
- readhow = eeprom_read_buf;
- else
+ switch (argv[0][3]) {
+ case 'r':
+ readwhat = ram_read_buf;
+ break;
+ case 'e':
+ readwhat = eeprom_read_buf;
+ break;
+ case 'f':
+ readwhat = flash_read_buf;
+ break;
+ default:
return CMD_RET_USAGE;
+ }
/* Address is specified since argc > 1 */
addr = strtoul(argv[1], NULL, 16);
@@ -57,7 +72,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
length = (uint16_t) strtoul(argv[2], NULL, 16);
/* Print the lines. */
- dump_mem(addr, addr, length, readhow, NULL);
+ dump_mem(addr, addr, length, readwhat, NULL);
return CMD_RET_SUCCESS;
}
@@ -112,8 +127,85 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
return CMD_RET_SUCCESS;
}
-/*------------------------------------------------------------------------------*/
+/* Modify memory.
+ *
+ * Syntax:
+ * !mm {addr}
+ * !nm {addr}
+ */
+
+ static uint8_t *mm_last_addr;
+
+static command_ret_t
+mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
+{
+ uint8_t *addr;
+ uint8_t data;
+ int nbytes;
+
+ (void) cmdtp;
+
+ if (argc != 2)
+ return CMD_RET_USAGE;
+
+ /* We use the last specified parameters, unless new ones are
+ * entered.
+ */
+ addr = mm_last_addr;
+
+ if ((flag & CMD_FLAG_REPEAT) == 0) {
+ /* New command specified.
+ */
+
+ /* Address is specified since argc > 1
+ */
+ addr = (uint8_t *) (size_t) strtoul(argv[1], NULL, 16);
+ }
+
+ /* Print the address, followed by value. Then accept input for
+ * the next value. A non-converted value exits.
+ */
+ do {
+ data = *addr;
+ printf_P(PSTR("%04x: %02x"), addr, data);
+
+ nbytes = cli_readline(PSTR(" ? "));
+ if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
+ /* <CR> pressed as only input, don't modify current
+ * location and move to next. "-" pressed will go back.
+ */
+ if (incrflag)
+ addr += nbytes ? -1 : 1;
+ nbytes = 1;
+
+ } else {
+ char *endp;
+ data = strtoul(console_buffer, &endp, 16);
+ nbytes = endp - console_buffer;
+ if (nbytes) {
+ *addr = data;
+ if (incrflag)
+ addr++;
+ }
+ }
+ } while (nbytes);
+
+ mm_last_addr = addr;
+ return CMD_RET_SUCCESS;
+}
+
+
+command_ret_t do_mem_mm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ return mod_mem_avr (cmdtp, 1, flag, argc, argv);
+}
+command_ret_t do_mem_nm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ return mod_mem_avr (cmdtp, 0, flag, argc, argv);
+}
+
+/*------------------------------------------------------------------------------*/
#if 1
diff --git a/avr/env.c b/avr/env.c
index 017053c..9ea355f 100644
--- a/avr/env.c
+++ b/avr/env.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <string.h>
#include <stdlib.h>
@@ -8,7 +14,6 @@
#include "xmalloc.h"
#include "crc.h"
#include "command.h"
-
#include "env.h"
@@ -26,13 +31,17 @@
#define DELIM "\0"
const FLASH char default_env[] = {
- "bootdelay=" "3" DELIM
- "bootcmd=" "reset; loadf; go ${startaddr}" DELIM
- "baudrate=" "115200" DELIM
- "startaddr=" "0" DELIM
+ ENV_BAUDRATE "=" "115200" DELIM
+ ENV_BOOTDELAY "=" "3" DELIM
+ ENV_BOOTCMD "=" "reset; loadf; go ${startaddr}" DELIM
+ ENV_CPM3_SYSFILE "=" CONFIG_CPM3_SYSFILE DELIM
+ ENV_PINALIAS "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7,"
+ "6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM
+ ENV_STARTADDRESS "=" "0" DELIM
DELIM
};
+
/* EEPROM storage */
typedef struct environment_s {
uint16_t crc; /* CRC16 over data bytes */
@@ -447,7 +456,6 @@ command_ret_t _do_env_set(int flag, int argc, char * const argv[])
env_item_t e, *ep;
(void) flag;
- debug("Initial value for argc=%d\n", argc);
name = argv[1];
value = argv[2];
@@ -514,15 +522,35 @@ command_ret_t _do_env_set(int flag, int argc, char * const argv[])
* @return 0 if ok, 1 on error
*/
static
-int setenv(const char *varname, const char *varvalue)
+int setenv(const MEMX char *varname, const char *varvalue)
{
- const char * const argv[3] = { NULL, varname, varvalue };
+ int rc;
+
+#ifdef __MEMX
+ char *tmpname = NULL;
+ if (__builtin_avr_flash_segment(varname) != -1) {
+ tmpname = malloc(strlen_P(varname)+1);
+ if (tmpname == NULL) {
+ printf_P(PSTR("setenv: Out of Memory!\n"));
+ return 1;
+ }
+ strcpy_P(tmpname, varname);
+ } else
+ tmpname = (char *) varname;
+#endif
+
+ const char * const argv[3] = { NULL, tmpname, varvalue };
int argc = 3;
if (varvalue == NULL || varvalue[0] == '\0')
--argc;
- return (int) _do_env_set(0, argc, (char * const *)argv);
+ rc = (int) _do_env_set(0, argc, (char * const *)argv);
+
+#ifdef __MEMX
+ free(tmpname);
+#endif
+ return rc;
}
/**
diff --git a/avr/getopt-min.c b/avr/getopt-min.c
index 8e5dd6c..f5ad912 100644
--- a/avr/getopt-min.c
+++ b/avr/getopt-min.c
@@ -1,6 +1,3 @@
-#include "common.h"
-
-
/*
* Minimum getopt, original version was:
*/
@@ -13,7 +10,8 @@
*/
/* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */
-#include <string.h>
+#include "common.h" /* definition of FLASH */
+#include <string.h>
int optind = 1; /* next argv[] index */
char *optarg; /* option parameter if any */
@@ -40,7 +38,7 @@ getopt( /* returns letter, '?', EOF */
)
return -1;
}
-
+
c = argv[optind][sp]; /* option letter */
osp = sp++; /* get ready for next letter */
@@ -72,4 +70,3 @@ getopt( /* returns letter, '?', EOF */
return c;
}
-
diff --git a/avr/gpio.c b/avr/gpio.c
index 3c47247..73e9c39 100644
--- a/avr/gpio.c
+++ b/avr/gpio.c
@@ -1,42 +1,46 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <util/atomic.h>
#include <limits.h>
#include "debug.h"
#include "gpio.h"
-
/*
-Pin Name Port Timer Mode max div max div min f [Hz]
-----------------------------------------------------------------------------------
-0 PG5 OC0B PWM (2**8)*1024 262144 70.31
-1 PG4
-2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16
-3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746
-4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746
-5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16
-6 PG3
-7 PG2
-8 PG1
-9 PG0
-10 CLKO PE7
-
-
-pre Timer0 Timer1 Timer2
+Pin Name Port Timer Mode max div max div min f [Hz]
+--------------------------------------------------------------------------------
+0 PG5 OC0B PWM (2**8)*1024 262144 70.31
+1 PG4
+2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16
+3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746
+4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746
+5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16
+6 PG3
+7 PG2
+8 PG1
+9 PG0
+10 CLKO PE7
+--------------------------------------------------------------------------------
+
+
+pre Timer0 Timer1 Timer2
--------------------------------------------------
-0 0 0 0
-1 1 1 1
-2 8 x8 8 x8 8 x8
-3 64 x8 64 x8 32 x4
-4 256 x4 256 x4 64 x2
-5 1024 x4 1024 x4 128 x2
-6 256 x2
-7 1024 x4
+0 0 0 0
+1 1 1 1
+2 8 x8 8 x8 8 x8
+3 64 x8 64 x8 32 x4
+4 256 x4 256 x4 64 x2
+5 1024 x4 1024 x4 128 x2
+6 256 x2
+7 1024 x4
--------------------------------------------------
-
*/
-
#define PWMTOGGLE 0b01
#define PWMPOS 0b10
#define PWMNEG 0b11
@@ -312,7 +316,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider)
top = ltop - 1;
- PING |= _BV(0); /* Debug */
+// PING |= _BV(0); /* Debug */
switch (timertype & TIMER) {
case TIMER0:
@@ -363,7 +367,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider)
break;
}
- PING |= _BV(0); /* Debug */
+// PING |= _BV(0); /* Debug */
gpio_config(pin, OUTPUT_TIMER);
diff --git a/avr/i2c.c b/avr/i2c.c
index d181ff6..ae2f8da 100644
--- a/avr/i2c.c
+++ b/avr/i2c.c
@@ -1,3 +1,8 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
/*
* I2C (TWI) master interface.
@@ -371,6 +376,3 @@ int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen,
return !((rc & (XMIT_DONE|DATA_ACK)) == (XMIT_DONE|DATA_ACK));
}
-
-
-
diff --git a/avr/main.c b/avr/main.c
index 7e832bf..3852e75 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -1,15 +1,18 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include "common.h"
-
#include <avr/interrupt.h>
+#include <avr/wdt.h>
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
-#include "debug.h"
+#include "ff.h"
#include "z80-if.h"
#include "i2c.h"
#include "con-utils.h"
@@ -18,14 +21,14 @@
#include "cli.h"
#include "env.h"
#include "z180-serv.h"
-#include "spi.h"
#include "gpio.h"
+#include "time.h"
+#include "rtc.h"
+#include "debug.h"
-static uint8_t mcusr;
+uint8_t mcusr __attribute__ ((section (".noinit")));
-/*--------------------------------------------------------------------------*/
#if DEBUG
-
__attribute__ ((naked)) __attribute__ ((section (".init3")))
void preset_ram (void)
{
@@ -33,6 +36,21 @@ void preset_ram (void)
*p = 0xdd;
}
+#endif
+
+__attribute__ ((naked)) __attribute__ ((section (".init3")))
+void get_mcusr (void)
+{
+ /* save and clear reset reason(s) */
+ /* TODO: move to init section? */
+ mcusr = MCUSR;
+ MCUSR = 0;
+
+ wdt_disable();
+}
+
+/*--------------------------------------------------------------------------*/
+#if DEBUG
static const FLASH char * const FLASH rreasons[] = {
FSTR("Power on"),
@@ -74,13 +92,6 @@ ISR(INT6_vect)
static
void setup_avr(void)
{
- /* save and clear reset reason(s) */
- /* TODO: move to init section? */
- mcusr = MCUSR;
- MCUSR = 0;
-
- /* WD */
-
/* CPU */
/* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
@@ -110,13 +121,6 @@ void setup_avr(void)
TCCR3B = (0b01<<WGM32)|(0b001<<CS30); /* CTC Mode, Prescaler 1 */
TIMSK3 = _BV(OCIE3A); /* Enable TC2.oca interrupt */
- /* SPI as master */
- PRR0 &= ~_BV(PRSPI);
- SPI_DDR = (SPI_DDR & ~_BV(SPI_MISO))
- | _BV(SPI_MOSI) | _BV(SPI_SCK) | _BV(SPI_SS);
- SPI_PORT = (SPI_PORT & ~(_BV(SPI_MOSI) | _BV(SPI_SCK)))
- | _BV(SPI_SS);
-
/* INT5, INT6: falling edge */
EICRB = (EICRB & ~((0b11 << ISC50) | (0b11 << ISC60))) |
(0b10 << ISC50) | (0b10 << ISC60);
@@ -132,6 +136,27 @@ int reset_reason_is_power_on(void)
return (mcusr & _BV(PORF)) != 0;
}
+static
+void setup_system_time(void)
+{
+ struct tm rtc_time;
+
+ rtc_get(&rtc_time);
+ rtc_time.tm_isdst = 0;
+ set_system_time(mk_gmtime(&rtc_time) );
+}
+
+
+
+static void setup_fatfs(void)
+{
+ static FATFS FatFs0;
+ static FATFS FatFs1;
+
+ f_mount(&FatFs0, "0:", 0);
+ f_mount(&FatFs1, "1:", 0);
+}
+
/*--------------------------------------------------------------------------*/
/* Stored value of bootdelay, used by autoboot_command() */
@@ -228,10 +253,13 @@ void main_loop(void)
int main(void)
{
- setup_avr();
- z80_setup_bus();
+ extern void setup_mmc(void);
+
for (int i = 0; i < GPIO_MAX; i++)
gpio_config(i, INPUT_PULLUP);
+ setup_avr();
+ setup_mmc();
+ z80_setup_bus();
env_init();
if (reset_reason_is_power_on())
@@ -245,13 +273,9 @@ int main(void)
print_reset_reason();
#endif
-#if DEBUG
- unsigned long i_speed = getenv_ulong(PSTR("i2c_clock"), 10, CONFIG_SYS_I2C_CLOCK);
- debug("### Setting I2C clock Frequency to %lu Hz.\n", i_speed);
- i2c_init(i_speed);
-#else
i2c_init(CONFIG_SYS_I2C_CLOCK);
-#endif
+ setup_system_time();
+ setup_fatfs();
printf_P(PSTR("\nATMEGA1281+Z8S180 Stamp Monitor\n\n"));
diff --git a/avr/mmc.c b/avr/mmc.c
index d780fef..7c4da24 100644
--- a/avr/mmc.c
+++ b/avr/mmc.c
@@ -10,41 +10,43 @@
#include "timer.h"
#include "spi.h"
#include "diskio.h"
-//#include "debug.h"
+#include "debug.h"
#define MAX_DRV 2
/* Port Controls (Platform dependent) */
/* SD card socket connections */
-//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */
+/* TODO: config.h cofig macros */
+
+//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */
//#define SD_CD_0_IN SBIT(PIN,)
//#define SD_CD_0_DDR SBIT(DDR,)
-//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */
+//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */
//#define SD_WP_0_IN SBIT(PIN,)
//#define SD_WP_0_DDR SBIT(DDR,)
-#define SD_CS_0 SBIT(PORTB,0) /* Chip select pin */
+#define SD_CS_0 SBIT(PORTB,0) /* Chip select pin */
#define SD_CS_0_IN SBIT(PINB,0)
#define SD_CS_0_DDR SBIT(DDRB,0)
-#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */
-#define SD_CD_1_IN SBIT(PING,3)
-#define SD_CD_1_DDR SBIT(DDRG,3)
-//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */
-#define SD_WP_1_IN SBIT(PING,5)
-#define SD_WP_1_DDR SBIT(DDRG,5)
+//#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */
+//#define SD_CD_1_IN SBIT(PING,3)
+//#define SD_CD_1_DDR SBIT(DDRG,3)
+
+//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */
+//#define SD_WP_1_IN SBIT(PING,5)
+//#define SD_WP_1_DDR SBIT(DDRG,5)
#define SD_CS_1 SBIT(PORTG,4) /* Chip select pin */
#define SD_CS_1_IN SBIT(PING,4)
#define SD_CS_1_DDR SBIT(DDRG,4)
-#define FCLK_SLOW() SPISetMMCInitClock() /* Set slow clock (100k-400k) */
-#define FCLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */
-
+#define SPI_CLK_SLOW() SPISetMMCInitClock() /* Set slow clock (100k-400k) */
+#define SPI_CLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */
/*--------------------------------------------------------------------------
Definitions for MMC/SDC command
@@ -113,14 +115,33 @@ int wait_ready (void) /* 1:OK, 0:Timeout */
static
void deselect(BYTE drv)
{
-// debug("*** enter deselect()\n");
+ //debug("*** enter deselect()\n");
if (drv == 0)
SD_CS_0 = 1;
- else
+ else {
SD_CS_1 = 1;
+ }
+
/* Dummy clock (TODO: force DO hi-z for multiple slave SPI) */
+ if (socket[drv].stat & STA_FAST)
+ SPI_CLK_FAST();
+ else
+ SPI_CLK_SLOW();
spi_rcvr();
-// debug("*** exit deselect()\n");
+ SPI_OFF();
+
+ if (drv == 0) {
+#ifdef SD_CS_0_IN
+ SD_CS_0_DDR = 0;
+ SD_CS_0 = 0;
+#endif
+ } else {
+#ifdef SD_CS_1_IN
+ SD_CS_1_DDR = 0;
+ SD_CS_1 = 0;
+#endif
+ }
+ //debug("*** exit deselect()\n");
}
/*-----------------------------------------------------------------------*/
@@ -130,20 +151,35 @@ void deselect(BYTE drv)
static
int select(BYTE drv) /* 1:Successful, 0:Timeout */
{
-// debug("*** enter select()\n");
- if (drv == 0)
+ //debug("*** enter select()\n");
+ if (drv == 0) {
+#ifdef SD_CS_0_IN
+ SD_CS_0 = 1;
+ SD_CS_0_DDR = 1;
+#endif
SD_CS_0 = 0;
- else
+ } else {
+#ifdef SD_CS_1_IN
+ SD_CS_1 = 1;
+ SD_CS_1_DDR = 1;
+#endif
SD_CS_1 = 0;
+ }
+
+ if (socket[drv].stat & STA_FAST)
+ SPI_CLK_FAST();
+ else
+ SPI_CLK_SLOW();
+
/* Dummy clock (force DO enabled) */
spi_rcvr();
if (wait_ready()) {
-// debug("*** exit select() == 1\n");
+ //debug("*** exit select() == 1\n");
return 1; /* OK */
}
deselect(drv);
-// debug("*** exit select() == 0\n");
+ //debug("*** exit select() == 0\n");
return 0; /* Timeout */
}
@@ -157,57 +193,29 @@ int select(BYTE drv) /* 1:Successful, 0:Timeout */
static
void power_on(BYTE drv)
{
-// debug("*** enter power_on()\n");
+ //debug("*** enter power_on()\n");
if (drv == 0) {
#ifdef SD_PWR_0
- SD_PWR_0_DDR = 1; /* Turns on PWR pin as output */
SD_PWR_0 = 0; /* Drives PWR pin high */
-
- for (uint32_t to = get_timer(0); get_timer(to) < 30;)
- ; /* Wait for 30ms */
#endif
-#ifdef SD_CD_0
- /* Card detect, input with pullup */
- SD_CD_0_DDR = 0;
- SD_CD_0 = 1;
-#endif
-#ifdef SD_WP_0
- SD_WP_0_DDR = 0;
- SD_WP_0 = 1;
-#endif
- SD_CS_0 = 1;
- SD_CS_0_DDR = 1;
} else {
#ifdef SD_PWR_1
- SD_PWR_1_DDR = 1; /* Turns on PWR pin as output */
SD_PWR_1 = 0; /* Drives PWR pin high */
-
+#endif
+ }
+#if defined SD_PWR_0 || defined SD_PWR_1
for (uint32_t to = get_timer(0); get_timer(to) < 30;)
; /* Wait for 30ms */
#endif
-
-#ifdef SD_CD_1
- /* Card detect, input with pullup */
- SD_CD_1_DDR = 0;
- SD_CD_1 = 1;
-#endif
-#ifdef SD_WP_1
- SD_WP_1_DDR = 0;
- SD_WP_1 = 1;
-#endif
- SD_CS_1 = 1;
- SD_CS_1_DDR = 1;
- }
-
-// debug("*** exit power_on()\n");
+ //debug("*** exit power_on()\n");
}
static
void power_off(BYTE drv)
{
-// debug("*** enter power_off()\n");
+ //debug("*** enter power_off()\n");
select(drv); /* Wait for card ready */
deselect(drv);
@@ -221,7 +229,7 @@ void power_off(BYTE drv)
#endif
}
socket[drv].stat |= STA_NOINIT;
-// debug("*** exit power_off()\n");
+ //debug("*** exit power_off()\n");
}
#if 0
@@ -330,7 +338,7 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
} argtmp;
BYTE n, res;
-// debug("*** send_cmd( %.2x )\n", cmd);
+ //debug("*** send_cmd( %.2x )\n", cmd);
if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
cmd &= 0x7F;
@@ -378,6 +386,55 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
---------------------------------------------------------------------------*/
+void setup_mmc(void)
+{
+#ifdef SD_PWR_0
+ SD_PWR_1 = 1; /* Drives PWR pin low */
+ SD_PWR_0_DDR = 1; /* Turns on PWR pin as output */
+#endif
+#ifdef SD_WP_0
+ SD_WP_0_DDR = 0;
+ SD_WP_0 = 1; /* Pullup */
+#endif
+
+#ifdef SD_PWR_1
+ SD_PWR_1 = 1; /* Drives PWR pin low */
+ SD_PWR_1_DDR = 1; /* Turns on PWR pin as output */
+#endif
+#ifdef SD_WP_1
+ SD_WP_1_DDR = 0;
+ SD_WP_1 = 1; /* Pullup */
+#endif
+
+ /* SPI as master */
+ PRR0 &= ~_BV(PRSPI);
+ SPI_DDR = (SPI_DDR & ~(_BV(SPI_MISO) | _BV(SPI_SS)))
+ | _BV(SPI_MOSI) | _BV(SPI_SCK);
+ SPI_PORT = SPI_PORT & ~(_BV(SPI_MOSI) | _BV(SPI_SCK));
+
+#if defined SD_CD_0
+ SD_CD_0_DDR = 0;
+ SD_CD_0 = 1;
+#elif defined SD_CS_0_IN
+ SD_CS_0_DDR = 0;
+ SD_CS_0 = 0;
+#else
+ SD_CS_0_DDR = 1;
+ SD_CS_0 = 1;
+#endif
+
+#if defined SD_CD_1
+ SD_CD_1_DDR = 0;
+ SD_CD_1 = 1;
+#elif defined SD_CS_1_IN
+ SD_CS_1_DDR = 0;
+ SD_CS_1 = 0;
+#else
+ SD_CS_1_DDR = 1;
+ SD_CS_1 = 1;
+#endif
+}
+
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
@@ -393,10 +450,11 @@ DSTATUS disk_initialize (
if (drv >= MAX_DRV)
return STA_NOINIT; /* Supports only single drive */
if (socket[drv].stat & STA_NODISK)
- return socket[drv].stat; /* No card in the socket */
+ return socket[drv].stat & STAT_MASK; /* No card in the socket */
power_on(drv); /* Force socket power on */
- FCLK_SLOW();
+ socket[drv].stat &= ~STA_FAST;
+ SPI_CLK_SLOW();
for (n = 10; n; n--)
spi_rcvr(); /* 80 dummy clocks */
@@ -441,12 +499,13 @@ DSTATUS disk_initialize (
deselect(drv);
if (ty) { /* Initialization succeded */
- socket[drv].stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
+ /* Clear STA_NOINIT */
+ socket[drv].stat = (socket[drv].stat & ~STA_NOINIT) | STA_FAST;
} else { /* Initialization failed */
power_off(drv);
}
- return socket[drv].stat;
+ return socket[drv].stat & STAT_MASK;
}
/*-----------------------------------------------------------------------*/
@@ -459,7 +518,7 @@ DSTATUS disk_status (
{
if (drv >= MAX_DRV)
return STA_NOINIT;
- return socket[drv].stat;
+ return socket[drv].stat & STAT_MASK;
}
/*-----------------------------------------------------------------------*/
@@ -483,7 +542,6 @@ DRESULT disk_read (
/* Convert to byte address if needed */
if (!(socket[drv].CardType & CT_BLOCK))
sector *= 512;
- FCLK_FAST();
/* READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */
cmd = count > 1 ? CMD18 : CMD17;
@@ -523,7 +581,6 @@ DRESULT disk_write (
/* Convert to byte address if needed */
if (!(socket[drv].CardType & CT_BLOCK))
sector *= 512;
- FCLK_FAST();
if (count == 1) {
/* Single block write */
@@ -574,7 +631,8 @@ DRESULT disk_ioctl (
if (socket[drv].stat & STA_NOINIT)
return RES_NOTRDY;
- FCLK_FAST();
+ /* TODO: SPI clock? */
+
switch (cmd) {
case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */
if (select(drv))
@@ -682,29 +740,45 @@ void disk_timerproc (void)
#ifdef SD_WP_0
if (SD_WP_0_IN == 0) /* Write protected */
s |= STA_PROTECT;
- else /* Write enabled */
+ else /* Write enabled */
s &= ~STA_PROTECT;
#endif
-#ifdef SD_CD_0
+
+#if defined SD_CD_0
if (SD_CD_0_IN == 0) /* Card inserted */
s &= ~STA_NODISK;
- else /* Socket empty */
+ else /* Socket empty */
s |= (STA_NODISK | STA_NOINIT);
+#elif defined SD_CS_0_IN
+ if (SD_CS_0_DDR == 0) {
+ if (SD_CS_0_IN == 1) /* Card inserted */
+ s &= ~STA_NODISK;
+ else /* Socket empty */
+ s |= (STA_NODISK | STA_NOINIT);
+ }
#endif
- socket[0].stat = s; /* Update MMC status */
+ socket[0].stat = s; /* Update MMC status */
s = socket[1].stat;
#ifdef SD_WP_1
if (SD_WP_1_IN == 0) /* Write protected */
s |= STA_PROTECT;
- else /* Write enabled */
+ else /* Write enabled */
s &= ~STA_PROTECT;
#endif
-#ifdef SD_CD_1
+
+#if defined SD_CD_1
if (SD_CD_1_IN == 0) /* Card inserted */
s &= ~STA_NODISK;
- else /* Socket empty */
+ else /* Socket empty */
s |= (STA_NODISK | STA_NOINIT);
+#elif defined SD_CS_1_IN
+ if (SD_CS_1_DDR == 0) {
+ if (SD_CS_1_IN == 1) /* Card inserted */
+ s &= ~STA_NODISK;
+ else /* Socket empty */
+ s |= (STA_NODISK | STA_NOINIT);
+ }
#endif
socket[1].stat = s; /* Update MMC status */
}
diff --git a/avr/pcf8583.c b/avr/pcf8583.c
index af1331d..169e4e9 100644
--- a/avr/pcf8583.c
+++ b/avr/pcf8583.c
@@ -1,13 +1,20 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
* Date & Time support for Philips PCF8583 RTC
*/
#include "common.h"
#include <stdlib.h>
-#include "debug.h"
-#include "command.h"
+#include "time.h"
#include "rtc.h"
#include "i2c.h"
+#include "command.h"
+#include "debug.h"
#define DEBUG_RTC 0
@@ -34,17 +41,17 @@ static uint_fast8_t bcd2bin(uint8_t val)
static uint8_t bin2bcd (uint_fast8_t val)
{
div_t d = div(val, 10);
-
+
return (d.quot << 4) | d.rem;
}
-int rtc_get (struct rtc_time *tmp)
+int rtc_get (struct tm *tmp)
{
int rel = 0;
uint8_t rtcbuf[NR_OF_REGS];
- uint16_t year;
-
+ int16_t year;
+
i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, rtcbuf, NR_OF_REGS);
i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0x10, 1, (uint8_t *) &year, 2);
@@ -56,12 +63,12 @@ int rtc_get (struct rtc_time *tmp)
tmp->tm_min = bcd2bin (rtcbuf[REG_MIN] & 0x7F);
tmp->tm_hour = bcd2bin (rtcbuf[REG_HOUR] & 0x3F);
tmp->tm_mday = bcd2bin (rtcbuf[REG_YRDATE] & 0x3F);
- tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F);
+ tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F) - 1;
while (year%4 < (rtcbuf[REG_YRDATE]>>6)) {
year++;
/* TODO: update RTC ram */
}
- tmp->tm_year = year;
+ tmp->tm_year = year;
tmp->tm_wday = rtcbuf[REG_WDMON] >> 5;
tmp->tm_yday = 0;
tmp->tm_isdst= 0;
@@ -74,7 +81,7 @@ int rtc_get (struct rtc_time *tmp)
return rel;
}
-int rtc_set (struct rtc_time *tmp)
+int rtc_set (struct tm *tmp)
{
uint8_t rtcbuf[NR_OF_REGS];
@@ -84,7 +91,7 @@ int rtc_set (struct rtc_time *tmp)
rtcbuf[REG_CS] = 0x84;
rtcbuf[REG_CSEC] = 0x00;
- rtcbuf[REG_WDMON ] = bin2bcd(tmp->tm_mon) | ((tmp->tm_wday) << 5);
+ rtcbuf[REG_WDMON ] = (bin2bcd(tmp->tm_mon) + 1) | ((tmp->tm_wday) << 5);
rtcbuf[REG_YRDATE] = ((tmp->tm_year % 4) << 6) | bin2bcd(tmp->tm_mday);
rtcbuf[REG_HOUR ] = bin2bcd(tmp->tm_hour);
rtcbuf[REG_MIN ] = bin2bcd(tmp->tm_min);
diff --git a/avr/print-utils.c b/avr/print-utils.c
index 4205a90..9ce3e50 100644
--- a/avr/print-utils.c
+++ b/avr/print-utils.c
@@ -1,4 +1,11 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
+#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#include "con-utils.h"
@@ -22,6 +29,12 @@ void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
*buf++ = *(uint8_t *) (size_t) addr++;
}
+void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+{
+ while (count--)
+ *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+}
+
int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
{
diff --git a/avr/serial.c b/avr/serial.c
index e897c84..adbc3c4 100644
--- a/avr/serial.c
+++ b/avr/serial.c
@@ -1,4 +1,7 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include <avr/io.h>
@@ -12,7 +15,7 @@
static int _write(char c, FILE *stream);
-static FILE mystdout = FDEV_SETUP_STREAM(_write,
+static FILE mystdout = FDEV_SETUP_STREAM(_write,
NULL, _FDEV_SETUP_WRITE);
@@ -24,7 +27,7 @@ static FILE mystdout = FDEV_SETUP_STREAM(_write,
#endif
#if ((BUFFER_SIZE) > 256)
-# error: BUFFER_SIZE
+# error: BUFFER_SIZE
#endif
struct ring rx_ring;
@@ -119,5 +122,3 @@ uint_fast8_t serial_tstc(void)
{
return !ring_is_empty(&rx_ring);
}
-
-
diff --git a/avr/timer.c b/avr/timer.c
index 7907bba..f45f267 100644
--- a/avr/timer.c
+++ b/avr/timer.c
@@ -1,9 +1,13 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include "common.h"
#include <avr/interrupt.h>
#include <util/atomic.h>
+#include "time.h"
#include "timer.h"
/* timer interrupt/overflow counter */
@@ -11,14 +15,14 @@
static volatile
uint32_t timestamp;
-/*---------------------------------------------------------*/
-/* 1000Hz timer interrupt generated by OC3A */
-/*---------------------------------------------------------*/
-
+/*
+ * 1000Hz timer interrupt generated by OC3A
+ */
ISR(TIMER3_COMPA_vect)
{
static int_fast8_t tick_10ms;
- int_fast8_t i;
+ static int_fast8_t tick_1s;
+ int_fast8_t i, j;
extern void disk_timerproc(void);
@@ -26,11 +30,18 @@ ISR(TIMER3_COMPA_vect)
i = tick_10ms + 1;
if (i == 10) {
- i = 0;
Stat |= S_10MS_TO;
/* Drive timer procedure of low level disk I/O module */
disk_timerproc();
+
+ j = tick_1s - 1;
+ if (j == 0) {
+ system_tick();
+ j = 100;
+ }
+ tick_1s = j;
+ i = 0;
}
tick_10ms = i;
}
diff --git a/avr/xmalloc.c b/avr/xmalloc.c
index 9bf2684..d42d5c9 100644
--- a/avr/xmalloc.c
+++ b/avr/xmalloc.c
@@ -1,5 +1,10 @@
-#include <stdlib.h>
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include <stdlib.h>
#include "debug.h"
#include "xmalloc.h"
@@ -11,7 +16,7 @@ void* xmalloc(size_t size)
if (p == NULL)
debug("*** Out of memory!\n");
-
+
return p;
}
@@ -22,6 +27,6 @@ void* xrealloc(void *p, size_t size)
if (p == NULL)
debug("*** Out of memory!\n");
-
+
return p;
}
diff --git a/avr/z180-serv.c b/avr/z180-serv.c
index e3bca16..69bcd9c 100644
--- a/avr/z180-serv.c
+++ b/avr/z180-serv.c
@@ -1,27 +1,32 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
#include <util/atomic.h>
#include "background.h"
+#include "env.h"
+#include "ff.h"
#include "serial.h"
#include "z80-if.h"
#include "debug.h"
+#include "print-utils.h"
#include "z180-serv.h"
+#include "timer.h"
+#include "time.h"
+#include "bcd.h"
+#include "rtc.h"
+#define DEBUG_CPM_SDIO 0 /* set to 1 to debug */
-
-/*--------------------------------------------------------------------------*/
-
-
-uint8_t z80_get_byte(uint32_t adr)
-{
- uint8_t data;
-
- z80_bus_cmd(Request);
- data = z80_read(adr);
- z80_bus_cmd(Release);
-
- return data;
-}
+#define debug_cpmsd(fmt, args...) \
+ debug_cond(DEBUG_CPM_SDIO, fmt, ##args)
/*--------------------------------------------------------------------------*/
@@ -48,6 +53,25 @@ uint32_t msg_to_addr(uint8_t *msg)
}
+static int msg_xmit_header(uint8_t func, uint8_t subf, int len)
+{
+ z80_memfifo_putc(fifo_msgout, 0xAE);
+ z80_memfifo_putc(fifo_msgout, len+2);
+ z80_memfifo_putc(fifo_msgout, func);
+ z80_memfifo_putc(fifo_msgout, subf);
+
+ return 0;
+}
+
+int msg_xmit(uint8_t func, uint8_t subf, int len, uint8_t *msg)
+{
+ msg_xmit_header(func, subf, len);
+ while (len--)
+ z80_memfifo_putc(fifo_msgout, *msg++);
+
+ return 0;
+}
+
void do_msg_ini_memfifo(uint8_t subf, int len, uint8_t * msg)
{
(void)len;
@@ -64,6 +88,356 @@ void do_msg_char_out(uint8_t subf, int len, uint8_t * msg)
putchar(*msg++);
}
+/* echo message */
+void do_msg_echo(uint8_t subf, int len, uint8_t * msg)
+{
+ (void)subf;
+
+ /* send re-echo */
+ msg_xmit(1, 3, len, msg);
+}
+
+/* get timer */
+void do_msg_get_timer(uint8_t subf, int len, uint8_t * msg)
+{
+ uint32_t time_ms = (len >= 4) ? *(uint32_t *) msg : 0;
+
+ time_ms = get_timer(time_ms);
+ msg_xmit(3, subf, sizeof(time_ms), (uint8_t *) &time_ms);
+}
+
+/* ---------------------------------------------------------------------------*/
+
+#define CPM_DAY_OFFSET ((1978-1900) * 365 + 19) /* 19 leap years */
+
+/*
+ * Convert CP/M time stamp to a broken-down time structure
+ *
+ */
+int mk_date_time (int len, uint8_t *msg, struct tm *tmp)
+{
+ time_t stamp;
+
+ if (len != 5)
+ return -1;
+
+ /* days since 2000-01-01 */
+ long days = msg[3] + (msg[4] << 8) - 8036;
+
+ if (days < 0)
+ return -1;
+
+ stamp = days * ONE_DAY;
+ stamp += bcd2bin(msg[0]);
+ stamp += bcd2bin(msg[1]) * 60 ;
+ stamp += bcd2bin(msg[2]) * 3600L;
+ gmtime_r(&stamp, tmp);
+ return 0;
+}
+
+void mk_cpm_time(struct tm *tmp, uint8_t cpm_time[5])
+{
+ uint16_t days = 1;
+ uint_fast8_t leap=2;
+
+ for (int year=78; year < tmp->tm_year; year++) {
+ days = days + 365 + (leap == 0);
+ leap = (leap+1)%4;
+ }
+ days += tmp->tm_yday;
+
+ cpm_time[0] = bin2bcd(tmp->tm_sec);
+ cpm_time[1] = bin2bcd(tmp->tm_min);
+ cpm_time[2] = bin2bcd(tmp->tm_hour);
+ cpm_time[3] = days;
+ cpm_time[4] = days >> 8;
+}
+
+/* get/set cp/m time */
+void do_msg_get_set_time(uint8_t subf, int len, uint8_t * msg)
+{
+ struct tm t;
+ uint8_t cpm_time[5];
+ int rc;
+
+ memset(cpm_time, 0, ARRAY_SIZE(cpm_time));
+
+ switch (subf) {
+ case 3: /* set date & time */
+ /* initialize t with current time */
+ rc = rtc_get (&t);
+
+ if (rc == 0) {
+ /* insert new date & time */
+ if (mk_date_time (len, msg, &t) != 0) {
+ my_puts_P(PSTR("## set_time: Bad date format\n"));
+ break;
+ }
+
+ time_t time;
+ time = mk_gmtime(&t);
+ gmtime_r(&time, &t);
+
+ /* and write to RTC */
+ rc = rtc_set (&t);
+ if(rc)
+ my_puts_P(PSTR("## set_time: Set date failed\n"));
+ } else {
+ my_puts_P(PSTR("## set_time: Get date failed\n"));
+ }
+ /* FALL TROUGH */
+ case 2: /* get date & time */
+ rc = rtc_get (&t);
+
+ if (rc) {
+ my_puts_P(PSTR("## get_time: Get date failed\n"));
+ break;
+ }
+
+ time_t time;
+ time = mk_gmtime(&t);
+ //mktime(&t);
+ gmtime_r(&time, &t);
+
+
+ mk_cpm_time(&t, cpm_time);
+ break;
+ }
+
+ msg_xmit(3, subf, sizeof(cpm_time), cpm_time);
+}
+
+/* ---------------------------------------------------------------------------*/
+
+#define MAX_DRIVE 4
+#define BLOCK_SIZE 512
+//#define TPA_BASE 0x10000
+//#define COMMON_BASE 0xC000
+
+struct cpm_drive_s {
+ uint8_t drv;
+ uint8_t device;
+ char *img_name;
+ bool dirty;
+ FIL fd;
+};
+
+static uint8_t disk_buffer[BLOCK_SIZE];
+static struct cpm_drive_s drv_table[MAX_DRIVE];
+static int handle_cpm_drv_to;
+
+#define f_dirty(fp) ((fp)->fs->wflag != 0)
+
+
+int cpm_drv_to(int state)
+{
+ static uint32_t ts;
+
+ switch(state) {
+ case 0:
+ break;
+
+ case 1:
+ ts = get_timer(0);
+ state = 2;
+ break;
+
+ case 2:
+ if (get_timer(ts) > 1000) {
+ for (uint_fast8_t i=0; i < MAX_DRIVE; i++) {
+// if (&drv_table[i].fd && f_dirty(&drv_table[i].fd)) {
+ if (drv_table[i].dirty) {
+ f_sync(&drv_table[i].fd);
+ drv_table[i].dirty = false;
+ debug_cpmsd("## %7lu f_sync: %c:\n", get_timer(0), i+'A');
+ }
+ }
+ state = 0;
+ }
+ }
+ return state;
+}
+
+
+void msg_cpm_result(uint8_t subf, uint8_t rc, int res)
+{
+ uint8_t result_msg[3];
+
+ if (res)
+ rc |= 0x80;
+
+ result_msg[0] = rc;
+ result_msg[1] = res;
+ result_msg[2] = res >> 8;
+
+ if (rc) {
+ debug_cpmsd("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res);
+ }
+
+ msg_xmit(2, subf, sizeof(result_msg), result_msg);
+}
+
+/*
+ db 2 ; disk command
+ ds 1 ; subcommand (login/read/write)
+ ds 1 ; @adrv (8 bits) +0
+ ds 1 ; @rdrv (8 bits) +1
+ ds 3 ; @xdph (24 bits) +2
+*/
+
+void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg)
+{
+
+ FRESULT res = 0;
+ uint8_t drv;
+ char *np;
+
+ (void)subf;
+
+ if (len != 5) { /* TODO: check adrv, rdrv */
+ return msg_cpm_result(subf, 0x01, res);
+ }
+
+ debug_cpmsd("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A');
+
+
+ drv = msg[0];
+ if ( drv>= MAX_DRIVE) {
+ return msg_cpm_result(subf, 0x02, res);
+ }
+
+/*
+ uint32_t dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2];
+*/
+
+ if (drv_table[drv].img_name != NULL) {
+ debug_cpmsd("## %7lu close: '%s'\n", get_timer(0), drv_table[drv].img_name);
+ f_close(&drv_table[drv].fd);
+ drv_table[drv].dirty = false;
+ free(drv_table[drv].img_name);
+ drv_table[drv].img_name = NULL;
+ }
+
+ strcpy_P((char *)disk_buffer, PSTR("dsk0"));
+ disk_buffer[3] = msg[0] + '0';
+ if (((np = getenv((char*)disk_buffer)) == NULL) ||
+ ((drv_table[drv].img_name = strdup(np)) == NULL)) {
+ return msg_cpm_result(subf, 0x03, res);
+ }
+
+
+ res = f_open(&drv_table[drv].fd, drv_table[drv].img_name,
+ FA_WRITE | FA_READ);
+
+ debug_cpmsd("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0),
+ drv_table[drv].img_name, disk_buffer, res);
+
+ /* send result*/
+ msg_cpm_result(subf, 0x00, res);
+}
+
+
+/*
+ db 2 ; disk command
+ ds 1 ; subcommand (login/read/write)
+ ds 1 ; @adrv (8 bits) +0
+ ds 1 ; @rdrv (8 bits) +1
+ ds 2 ; @trk (16 bits) +2
+ ds 2 ; @sect(16 bits) +4
+ ds 1 ; @cnt (8 bits) +6
+ ds 3 ; phys. transfer addr +7
+*/
+
+#define ADRV 0
+#define RDRV 1
+#define TRK 2
+#define SEC 4
+#define CNT 6
+#define ADDR 7
+
+void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg)
+{
+ uint8_t drv;
+ uint32_t addr;
+ uint32_t pos;
+ uint8_t secs;
+ bool dowrite = (subf == 2);
+ FRESULT res = 0;
+ uint8_t rc = 0;
+ bool buserr = 0;
+
+ if (len != 10) { /* TODO: check adrv, rdrv */
+ return msg_cpm_result(subf, 0x01, res);
+ }
+
+ drv = msg[ADRV];
+ if ( drv>= MAX_DRIVE) {
+ return msg_cpm_result(subf, 0x02, res);
+ }
+
+ secs = msg[CNT];
+ addr = ((uint32_t)msg[ADDR+2] << 16) + ((uint16_t)msg[ADDR+1] << 8) + msg[ADDR];
+
+
+ /* TODO: tracks per sector from dpb */
+ pos = (((uint16_t)(msg[TRK+1] << 8) + msg[TRK]) * 8
+ + ((uint32_t)(msg[SEC+1] << 8) + msg[SEC])) * BLOCK_SIZE;
+
+ debug_cpmsd("## %7lu cpm_rw: %s %c: trk:%4d, sec: %d, pos: %.8lx, secs: %2d, "
+ "addr: %.5lx\n", get_timer(0), dowrite ? "write" : " read",
+ msg[ADRV]+'A', ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC],
+ pos, msg[CNT], addr);
+
+ res = f_lseek(&drv_table[drv].fd, pos);
+ while (!res && secs--) {
+ unsigned int brw;
+ if (dowrite) {
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ buserr = 1;
+ break;
+ } else {
+ z80_read_block(disk_buffer, addr, BLOCK_SIZE);
+ z80_bus_cmd(Release);
+ }
+ res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw);
+ } else {
+ res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw);
+ if (res == FR_OK && brw == BLOCK_SIZE) {
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ buserr = 1;
+ break;
+ } else {
+ z80_write_block(disk_buffer, addr, BLOCK_SIZE);
+ z80_bus_cmd(Release);
+ }
+ }
+ }
+
+ if (brw != BLOCK_SIZE) {
+ debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, brw);
+ dump_ram(disk_buffer, 0, 64, "Read Data");
+ res = -1;
+ }
+
+ addr += BLOCK_SIZE;
+ }
+
+ if (dowrite && !res) {
+// res = f_sync(&drv_table[drv].fd);
+ drv_table[drv].dirty = true;
+ bg_setstat(handle_cpm_drv_to, 1);
+ }
+
+
+ if (buserr) {
+ debug_cpmsd("Bus timeout\n");
+ rc = 0x03;
+ }
+
+ /* send result*/
+ msg_cpm_result(subf, rc, res);
+}
+
const FLASH struct msg_item z80_messages[] =
{
@@ -73,6 +447,21 @@ const FLASH struct msg_item z80_messages[] =
{ 1,
1, 1,
do_msg_char_out},
+ { 1,
+ 2, 2,
+ do_msg_echo},
+ { 2,
+ 0, 0,
+ do_msg_cpm_login},
+ { 2,
+ 1, 2,
+ do_msg_cpm_rw},
+ { 3,
+ 1, 1,
+ do_msg_get_timer},
+ { 3,
+ 2, 3, /* 2: get, 3: set time and date */
+ do_msg_get_set_time},
{ 0xff, /* end mark */
0, 0,
0},
@@ -165,7 +554,7 @@ void check_msg_fifo(void)
int msg_handling(int state)
{
- uint8_t pending;
+ bool pending;
ATOMIC_BLOCK(ATOMIC_FORCEON) {
pending = (Stat & S_MSG_PENDING) != 0;
@@ -173,21 +562,27 @@ int msg_handling(int state)
}
if (pending) {
- switch (state) {
- case 0:
+ uint8_t init_request;
+ z80_bus_cmd(Request);
+ init_request = z80_read(0x43);
+ z80_bus_cmd(Release);
+ if ( init_request != 0) {
+ /* Get address of fifo 0 */
z80_bus_cmd(Request);
- uint32_t addr = z80_read(0x40) +
- ((uint16_t) z80_read(0x41) << 8) +
- ((uint32_t) z80_read(0x42) << 16);
+ uint32_t fifo_addr = z80_read(0x40) +
+ ((uint16_t) z80_read(0x40+1) << 8) +
+ ((uint32_t) z80_read(0x40+2) << 16);
+ z80_write(0x43, 0);
z80_bus_cmd(Release);
- if (addr != 0) {
- z80_memfifo_init(fifo_msgin, addr);
+
+ if (fifo_addr != 0) {
+ z80_memfifo_init(fifo_msgin, fifo_addr);
state = 1;
- }
- break;
- case 1:
+ } else
+ state = 0;
+
+ } else {
check_msg_fifo();
- break;
}
}
@@ -201,21 +596,22 @@ void setup_z180_serv(void)
{
handle_msg_handling = bg_register(msg_handling, 0);
+ handle_cpm_drv_to = bg_register(cpm_drv_to, 0);
}
void restart_z180_serv(void)
{
z80_bus_cmd(Request);
- z80_write(0x40, 0);
- z80_write(0x41, 0);
- z80_write(0x42, 0);
+ z80_memset(0x40, 0, 4);
z80_bus_cmd(Release);
for (int i = 0; i < NUM_FIFOS; i++)
z80_memfifo_init(i, 0);
bg_setstat(handle_msg_handling, 0);
+
}
+#if 0
/*--------------------------------------------------------------------------*/
const FLASH uint8_t iniprog[] = {
@@ -267,3 +663,4 @@ const FLASH uint8_t test1[] = {
0x00, // db 0 ;dst
0x00, 0x00, // dw 0 ;count (64k)
};
+#endif
diff --git a/avr/z180-stamp-avr.c b/avr/z180-stamp-avr.c
deleted file mode 100644
index e6edb33..0000000
--- a/avr/z180-stamp-avr.c
+++ /dev/null
@@ -1,591 +0,0 @@
-/*
- */
-
-
-#include <avr/io.h>
-//#include <avr/power.h>
-//#include <avr/pgmspace.h>
-#include <avr/interrupt.h>
-//#include <util/atomic.h>
-//#include <avr/sleep.h>
-//#include <string.h>
-
-#include <stdio.h>
-
-
-#include "debug.h"
-#include "serial.h"
-#include "z80-if.h"
-
-#define const const __flash
-#include "../z180/hdrom.h"
-#undef const
-
-#define FLASH __flash
-//#define FLASH
-
-#define ESCCHAR ('^'-0x40)
-
-#define S_10MS_TO (1<<0)
-
-
-volatile int_fast8_t timeout_1s;
-//volatile uint_least8_t Stat;
-#define Stat GPIOR0
-
-unsigned int to_counter;
-
-/****************************************************************/
-
-#define P_ADL PORTA
-#define P_ADH PORTC
-#define P_ADB PORTE
-#define PIN_ADB PINE
-
-#define ADB_WIDTH 3
-#define ADB_SHIFT 2
-//#define ADB_PORT GPIOE
-
-#define MASK(n) ((1<<(n))-1)
-#define SMASK(w,s) (MASK(w) << (s))
-
-typedef union {
- uint32_t l;
- uint16_t w[2];
- uint8_t b[4];
-} addr_t;
-
-
-
-/*--------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------*/
-/* 1000Hz timer interrupt generated by OC1A */
-/*---------------------------------------------------------*/
-
-ISR(TIMER1_COMPA_vect)
-{
- static int_fast8_t tick_10ms;
-// static int_fast16_t count_ms;
-
- int_fast8_t i;
-
-
- i = tick_10ms + 1;
- if (i == 10) {
- i = 0;
- Stat |= S_10MS_TO;
-
- /* Drive timer procedure of low level disk I/O module */
- //disk_timerproc();
- }
- tick_10ms = i;
-
-#if 0
- count_ms++;
- if (count_ms == 1000) {
- count_ms = 0;
-
- i = timeout_1s;
- if (i)
- timeout_1s = i - 1;
- }
-#endif
-}
-
-
-/*--------------------------------------------------------------------------*/
-
-static uint32_t z80_sram_cmp(uint32_t addr, uint32_t length, uint8_t wval, int inc)
-{
- uint8_t rval;
- int_fast8_t errors = 0;
-
- DBG_P(1, "SRAM: Check 0x%.5lx byte... ", length);
- while (length--) {
- if ((rval = z80_read(addr)) != wval) {
- if (errors == 0) {
- DBG_P(1, "\nSRAM: Address W R\n" \
- " ------------------\n");
- }
- errors++;
- if (errors > 20) {
- DBG_P(1, " ...\n");
- break;
- }
- DBG_P(1, " 0x%.5lx 0x%.2x 0x%.2x\n", addr, wval, rval);
- }
- addr++;
- wval += inc;
- }
- DBG_P(1, "Done.\n");
-
- return addr;
-}
-
-static void z80_sram_fill(uint32_t addr, uint32_t length, uint8_t startval, int inc)
-{
- printf("SRAM: Write 0x%.5lx byte... ", length);
- while (length--) {
- z80_write(addr, startval);
- ++addr;
- startval += inc;
- }
- printf("Done.\n");
-}
-
-
-#if 0
-void z80_sram_fill_string(uint32_t addr, int length, const char *text)
-{
- char c;
- const char *p = text;
-
- while (length--) {
- z80_write(addr++, c = *p++);
- if (c == 0)
- p = text;
- }
-}
-
-
-uint32_t z80_sram_cmp_string(uint32_t addr, int length, const char *text)
-{
- char c;
- const char *p = text;
-
- while (length--) {
- c = *p++;
- if (z80_read(addr) != c)
- break;
- ++addr;
- if (c == 0)
- p = text;
- }
- return addr;
-}
-
-const char * const qbfox = "Zhe quick brown fox jumps over the lazy dog!";
-const char * const qbcat = "Zhe quick brown fox jumps over the lazy cat!";
-
-#endif
-
-uint8_t z80_get_byte(uint32_t adr)
-{
- uint8_t data;
-
- z80_request_bus();
- data = z80_read(adr),
- z80_release_bus();
-
- return data;
-}
-
-
-/*--------------------------------------------------------------------------*/
-
-static void do_10ms(void)
-{
- if (to_counter)
- to_counter--;
-}
-
-/*--------------------------------------------------------------------------*/
-
-struct msg_item {
- uint8_t fct;
- uint8_t sub_min, sub_max;
- void (*func)(uint8_t, int, uint8_t *);
-};
-
-uint32_t msg_to_addr(uint8_t *msg)
-{
- union {
- uint32_t as32;
- uint8_t as8[4];
- } addr;
-
- addr.as8[0] = msg[0];
- addr.as8[1] = msg[1];
- addr.as8[2] = msg[2];
- addr.as8[3] = 0;
-
- return addr.as32;
-}
-
-void do_msg_ini_msgfifo(uint8_t subf, int len, uint8_t * msg)
-{
- (void)subf; (void)len;
-
- z80_init_msg_fifo(msg_to_addr(msg));
-}
-
-
-void do_msg_ini_memfifo(uint8_t subf, int len, uint8_t * msg)
-{
- (void)len;
-
- z80_memfifo_init(subf - 1, msg_to_addr(msg));
-}
-
-
-void do_msg_char_out(uint8_t subf, int len, uint8_t * msg)
-{
- (void)subf;
-
- while (len--)
- putchar(*msg++);
-}
-
-
-const FLASH struct msg_item z80_messages[] =
-{
- { 0, /* fct nr. */
- 0, 0, /* sub fct nr. from, to */
- do_msg_ini_msgfifo},
- { 0,
- 1, 2,
- do_msg_ini_memfifo},
- { 1,
- 1, 1,
- do_msg_char_out},
- { 0xff, /* end mark */
- 0, 0,
- 0},
-
-};
-
-
-
-
-void do_message(int len, uint8_t *msg)
-{
- uint8_t fct, sub_fct;
- int_fast8_t i = 0;
-
- if (len >= 2) {
- fct = *msg++;
- sub_fct = *msg++;
- len -= 2;
-
- while (fct != z80_messages[i].fct)
- ++i;
-
- if (z80_messages[i].fct == 0xff) {
- DBG_P(1, "do_message: Unknown function: %i, %i\n",
- fct, sub_fct);
- return; /* TODO: unknown message # */
- }
-
- while (fct == z80_messages[i].fct) {
- if (sub_fct >= z80_messages[i].sub_min && sub_fct <= z80_messages[i].sub_max )
- break;
- ++i;
- }
-
- if (z80_messages[i].fct != fct) {
- DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
- fct, sub_fct);
- return; /* TODO: unknown message sub# */
- }
-
- (z80_messages[i].func)(sub_fct, len, msg);
-
-
- } else {
- /* TODO: error */
- DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len);
- }
-}
-
-
-
-#define CTRBUF_LEN 256
-
-void check_msg_fifo(void)
-{
- int ch;
- static int_fast8_t state;
- static int msglen,idx;
- static uint8_t buffer[CTRBUF_LEN];
-
- while (state != 3 && (ch = z80_msg_fifo_getc()) >= 0) {
- switch (state) {
- case 0: /* wait for start of message */
- if (ch == 0x81) {
- msglen = 0;
- idx = 0;
- state = 1;
- }
- break;
- case 1: /* get msg len */
- if (ch > 0 && ch <= CTRBUF_LEN) {
- msglen = ch;
- state = 2;
- } else
- state = 0;
- break;
- case 2: /* get message */
- buffer[idx++] = ch;
- if (idx == msglen)
- state = 3;
- break;
- }
- }
-
- if (state == 3) {
- do_message(msglen, buffer);
- state = 0;
- }
-}
-
-
-/*--------------------------------------------------------------------------*/
-
-void dump_mem(const __flash uint8_t *addr, uint32_t len)
-{
- DBG_P(1, "hdrom dump:");
- while (len) {
- DBG_P(1, "\n %.5x:", addr);
- for (unsigned i = 0; i<16; i++)
- DBG_P(1, " %.2x", *addr++);
- len -= len > 16 ? 16 : len;
- }
- DBG_P(1, "\n");
-}
-
-/*--------------------------------------------------------------------------*/
-
-void z80_load_mem(void)
-{
- unsigned sec = 0;
- uint32_t sec_base = hdrom_start;
-
- DBG_P(1, "Loading z80 memory... \n");
-
- while (sec < hdrom_sections) {
- DBG_P(2, " From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n",
- hdrom_address[sec],
- hdrom_address[sec]+hdrom_length_of_sections[sec] - 1,
- hdrom_length_of_sections[sec]);
-
- z80_write_block((const __flash unsigned char *) &hdrom[sec_base], /* src */
- hdrom_address[sec], /* dest */
- hdrom_length_of_sections[sec]); /* len */
- sec_base+=hdrom_length_of_sections[sec];
- sec++;
- }
-}
-
-/*--------------------------------------------------------------------------*/
-
-void z80_dump_mem(uint32_t addr, uint32_t len)
-{
- DBG_P(1, "Memory dump:");
- while (len) {
- DBG_P(1, "\n %.5lx:", addr);
- for (unsigned i = 0; i<16; i++)
- DBG_P(1, " %.2x", z80_read(addr++));
- len -= len > 16 ? 16 : len;
- }
- DBG_P(1, "\n");
-}
-
-/*--------------------------------------------------------------------------*/
-
-void setup_rtc(void)
-{
- /* TODO: */
-}
-
-void setup_avr(void)
-{
- /* WD */
-
- /* CPU */
-
- /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
- MCUCR = _BV(JTD);
- MCUCR = _BV(JTD);
-
- /* disable unused periphels */
- PRR0 = _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRADC);
- PRR1 = _BV(PRTIM5) | _BV(PRTIM4) | _BV(PRTIM3) |
- _BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1);
-
- /* disable analog comparator */
- ACSR = _BV(ACD);
- /* Ports */
-
- /* Clock */
- CLKPR = _BV(CLKPCE);
- CLKPR = 0;
-
- /* Timer */
-
- OCR1A = F_CPU / 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
- TCCR1B = 0b00001010;
- TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
-}
-
-const __flash uint8_t iniprog[] = {
- 0xAF, // xor a
- 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
- 0x3E, 0x30, // ld a,030h
- 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states
-};
-
-const __flash uint8_t sertest[] = {
- 0xAF, // xor a
- 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
- 0x3E, 0x30, // ld a,030h
- 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
- 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0
- 0xED, 0x39, 0x03, // out0 (cntlb1),a
- 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ;
- 0xED, 0x39, 0x01, // out0 (cntla1),a
- 0x3E, 0x00, // ld a,0
- 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts
- 0xED, 0x38, 0x05, //l0:in0 a,(stat1)
- 0xE6, 0x80, // and 80h
- 0x28, 0xF9, // jr z,l0
- 0xED, 0x00, 0x09, // in0 b,(rdr1)
- 0xED, 0x38, 0x05, //l1:in0 a,(stat1)
- 0xE6, 0x02, // and 02h
- 0x28, 0xF9, // jr z,l1
- 0xED, 0x01, 0x07, // out0 (tdr1),b
- 0x18, 0xEA, // jr l0
-};
-
-const __flash uint8_t test1[] = {
- 0xAF, // xor a
- 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
- 0x3E, 0x30, // ld a,030h
- 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
- 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers
- 0x06, 0x08, // ld b,dmct_e-dmclrt
- 0x0E, 0x20, // ld c,sar0l
- 0xED, 0x93, // otimr
- 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst
- 0xED, 0x39, 0x31, // out0 (dmode),a ;
- 0x3E, 0x62, // ld a,062h ;enable dma0,
- 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k
- 0x18, 0xFB, // jr cl_1 ;
- 0x00, 0x00, //dmclrt: dw 0 ;src (inc)
- 0x00, // db 0 ;src
- 0x00, 0x00, // dw 0 ;dst (inc),
- 0x00, // db 0 ;dst
- 0x00, 0x00, // dw 0 ;count (64k)
-};
-
-
-int main(void)
-{
- int_fast8_t state = 0;
- int ch;
-
- setup_avr();
- serial_setup();
- setup_rtc();
- sei();
-
- printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n"));
-
- DBG_P(1, "z80_setup_bus... ");
- z80_setup_msg_fifo();
- z80_setup_bus();
- DBG_P(1, "done.\n");
-
- DBG_P(1, "Get bus... ");
-/* Now done via S_Z180_RUNNING
- z80_busreq(LOW);
- z80_reset(HIGH);
-*/
- z80_request_bus();
- DBG_P(1, "got it!\n");
-
-// z80_sram_fill(0, (uint32_t)512 * 1024, 0x00, 3);
-// z80_sram_cmp(0, (uint32_t)512 * 1024, 0x00, 3);
-// z80_dump_mem(0, 0x400);
-
- z80_memset(0, 0x76, 0x80000);
-// z80_memset(0, 0x00, 0x80000);
-// z80_write_block(test1, 0, sizeof(test1));
-
-// z80_dump_mem(0, 0x100);
-
-// z80_sram_cmp(0, (uint32_t)512 * 1024, 0x76, 0);
-
- z80_load_mem();
-// z80_write(0, 0x76);
-// z80_dump_mem(0, 0x200);
-
-
-/* Now done via S_Z180_RUNNING
- z80_reset(LOW);
-*/
- z80_release_bus();
- DBG_P(1, "Bus released!\n");
- z80_reset(HIGH);
- DBG_P(1, "Reset released!\n");
-
- to_counter = 200;
-
- while (1) {
-
- if (Stat & S_10MS_TO) {
- Stat &= ~S_10MS_TO;
- do_10ms();
- }
-
-
- if ((ch = serial_getc()) >= 0) {
- switch (state) {
- case 0:
- if (ch == ESCCHAR) {
- state = 1;
- /* TODO: Timer starten */
- } else {
-// z80_memfifo_putc(fifo_out, ch);
- serial_putc(ch);
- if (ch == '\r')
- serial_putc('\n');
- }
- break;
- case 1:
- switch (ch) {
-
- case 'r':
- z80_reset_pulse();
- break;
-
- case 'b':
- z80_request_bus();
- z80_dump_mem(0, 0x2d20);
- z80_release_bus();
- break;
-
- case 'e':
- z80_request_bus();
- z80_dump_mem(0x80000-0x4000, 0x800);
- z80_dump_mem(0x80000-0x200, 0x200);
- z80_release_bus();
- break;
-
- case ESCCHAR:
- default:
-// z80_memfifo_putc(fifo_out, ch);
- serial_putc(ch);
- if (ch == '\r')
- serial_putc('\n');
- }
- state = 0;
- break;
- }
- }
-
-// check_msg_fifo();
- }
-
- return 0;
-}
diff --git a/avr/z80-if.c b/avr/z80-if.c
index cc0bab1..21ffeac 100644
--- a/avr/z80-if.c
+++ b/avr/z80-if.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
/**
*
* Pin assignments
@@ -50,7 +56,6 @@
* | | P | | af1 OSC32 |
* | | P | | af1 OSC32 |
-
*/
@@ -555,10 +560,9 @@ void z80_memfifo_init(const fifo_t f, uint32_t addr)
{
fifo_dsc[f].base = addr;
- if (addr != 0) {
-
DBG_P(2, "z80_memfifo_init: %i, %lx\n", f, addr);
+ if (addr != 0) {
z80_bus_cmd(Request);
fifo_dsc[f].mask = z80_read(addr + FIFO_BUFSIZE_MASK);
fifo_dsc[f].idx_in = z80_read(addr + FIFO_INDEX_IN);
@@ -588,7 +592,7 @@ int z80_memfifo_is_empty(const fifo_t f)
int z80_memfifo_is_full(const fifo_t f)
{
- int rc = 1;
+ int rc = 0;
if (fifo_dsc[f].base != 0) {
z80_bus_cmd(Request);
diff --git a/fatfs/src/ffconf.h b/fatfs/src/ffconf.h
deleted file mode 100644
index 059e85b..0000000
--- a/fatfs/src/ffconf.h
+++ /dev/null
@@ -1,269 +0,0 @@
-/*---------------------------------------------------------------------------/
-/ FatFs - FAT file system module configuration file R0.10c (C)ChaN, 2014
-/---------------------------------------------------------------------------*/
-
-#define _FFCONF 80376 /* Revision ID */
-
-/*---------------------------------------------------------------------------/
-/ Functions and Buffer Configurations
-/---------------------------------------------------------------------------*/
-
-#define _FS_TINY 0
-/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
-/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
-/ bytes. Instead of private sector buffer eliminated from the file object,
-/ common sector buffer in the file system object (FATFS) is used for the file
-/ data transfer. */
-
-
-#define _FS_READONLY 0
-/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
-/ Read-only configuration removes basic writing API functions, f_write(),
-/ f_sync(), f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(),
-/ f_getfree() and optional writing functions as well. */
-
-
-#define _FS_MINIMIZE 0
-/* This option defines minimization level to remove some API functions.
-/
-/ 0: All basic functions are enabled.
-/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
-/ f_truncate() and f_rename() function are removed.
-/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
-/ 3: f_lseek() function is removed in addition to 2. */
-
-
-#define _USE_STRFUNC 0
-/* This option switches string functions, f_gets(), f_putc(), f_puts() and
-/ f_printf().
-/
-/ 0: Disable string functions.
-/ 1: Enable without LF-CRLF conversion.
-/ 2: Enable with LF-CRLF conversion. */
-
-
-#define _USE_MKFS 0
-/* This option switches f_mkfs() function. (0:Disable or 1:Enable)
-/ To enable it, also _FS_READONLY need to be set to 0. */
-
-
-#define _USE_FASTSEEK 0
-/* This option switches fast seek feature. (0:Disable or 1:Enable) */
-
-
-#define _USE_LABEL 1
-/* This option switches volume label functions, f_getlabel() and f_setlabel().
-/ (0:Disable or 1:Enable) */
-
-
-#define _USE_FORWARD 0
-/* This option switches f_forward() function. (0:Disable or 1:Enable) */
-/* To enable it, also _FS_TINY need to be set to 1. */
-
-
-/*---------------------------------------------------------------------------/
-/ Locale and Namespace Configurations
-/---------------------------------------------------------------------------*/
-
-#define _CODE_PAGE 858
-/* This option specifies the OEM code page to be used on the target system.
-/ Incorrect setting of the code page can cause a file open failure.
-/
-/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
-/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
-/ 949 - Korean (DBCS, OEM, Windows)
-/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
-/ 1250 - Central Europe (Windows)
-/ 1251 - Cyrillic (Windows)
-/ 1252 - Latin 1 (Windows)
-/ 1253 - Greek (Windows)
-/ 1254 - Turkish (Windows)
-/ 1255 - Hebrew (Windows)
-/ 1256 - Arabic (Windows)
-/ 1257 - Baltic (Windows)
-/ 1258 - Vietnam (OEM, Windows)
-/ 437 - U.S. (OEM)
-/ 720 - Arabic (OEM)
-/ 737 - Greek (OEM)
-/ 775 - Baltic (OEM)
-/ 850 - Multilingual Latin 1 (OEM)
-/ 858 - Multilingual Latin 1 + Euro (OEM)
-/ 852 - Latin 2 (OEM)
-/ 855 - Cyrillic (OEM)
-/ 866 - Russian (OEM)
-/ 857 - Turkish (OEM)
-/ 862 - Hebrew (OEM)
-/ 874 - Thai (OEM, Windows)
-/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
-
-
-#define _USE_LFN 0
-#define _MAX_LFN 128
-/* The _USE_LFN option switches the LFN feature.
-/
-/ 0: Disable LFN feature. _MAX_LFN has no effect.
-/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
-/ 2: Enable LFN with dynamic working buffer on the STACK.
-/ 3: Enable LFN with dynamic working buffer on the HEAP.
-/
-/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
-/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
-/ When use stack for the working buffer, take care on stack overflow. When use heap
-/ memory for the working buffer, memory management functions, ff_memalloc() and
-/ ff_memfree(), must be added to the project. */
-
-
-#define _LFN_UNICODE 0
-/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
-/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
-/ to 1. This option also affects behavior of string I/O functions. */
-
-
-#define _STRF_ENCODE 3
-/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
-/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
-/
-/ 0: ANSI/OEM
-/ 1: UTF-16LE
-/ 2: UTF-16BE
-/ 3: UTF-8
-/
-/ When _LFN_UNICODE is 0, this option has no effect. */
-
-
-#define _FS_RPATH 2
-/* This option configures relative path feature.
-/
-/ 0: Disable relative path feature and remove related functions.
-/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
-/ 2: f_getcwd() function is available in addition to 1.
-/
-/ Note that directory items read via f_readdir() are affected by this option. */
-
-
-/*---------------------------------------------------------------------------/
-/ Drive/Volume Configurations
-/---------------------------------------------------------------------------*/
-
-#define _VOLUMES 2
-/* Number of volumes (logical drives) to be used. */
-
-
-#define _STR_VOLUME_ID 0
-#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* _STR_VOLUME_ID option switches string volume ID feature.
-/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
-/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
-/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
-/ the drive ID strings are: A-Z and 0-9. */
-
-
-#define _MULTI_PARTITION 0
-/* This option switches multi-partition feature. By default (0), each logical drive
-/ number is bound to the same physical drive number and only an FAT volume found on
-/ the physical drive will be mounted. When multi-partition feature is enabled (1),
-/ each logical drive number is bound to arbitrary physical drive and partition
-/ listed in the VolToPart[]. Also f_fdisk() funciton will be enabled. */
-
-
-#define _MIN_SS 512
-#define _MAX_SS 512
-/* These options configure the range of sector size to be supported. (512, 1024,
-/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
-/ harddisk. But a larger value may be required for on-board flash memory and some
-/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
-/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
-/ disk_ioctl() function. */
-
-
-#define _USE_TRIM 0
-/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
-/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
-/ disk_ioctl() function. */
-
-
-#define _FS_NOFSINFO 0
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/ option, and f_getfree() function at first time after volume mount will force
-/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
-/
-/ bit0=0: Use free cluster count in the FSINFO if available.
-/ bit0=1: Do not trust free cluster count in the FSINFO.
-/ bit1=0: Use last allocated cluster number in the FSINFO if available.
-/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
-*/
-
-
-
-/*---------------------------------------------------------------------------/
-/ System Configurations
-/---------------------------------------------------------------------------*/
-
-#define _FS_NORTC 0
-#define _NORTC_MON 11
-#define _NORTC_MDAY 9
-#define _NORTC_YEAR 2014
-/* The _FS_NORTC option switches timestamp feature. If the system does not have
-/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
-/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
-/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
-/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
-/ to be added to the project to read current time form RTC. _NORTC_MON,
-/ _NORTC_MDAY and _NORTC_YEAR have no effect.
-/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
-
-
-#define _FS_LOCK 0
-/* The _FS_LOCK option switches file lock feature to control duplicated file open
-/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
-/ is 1.
-/
-/ 0: Disable file lock feature. To avoid volume corruption, application program
-/ should avoid illegal open, remove and rename to the open objects.
-/ >0: Enable file lock feature. The value defines how many files/sub-directories
-/ can be opened simultaneously under file lock control. Note that the file
-/ lock feature is independent of re-entrancy. */
-
-
-#define _FS_REENTRANT 0
-#define _FS_TIMEOUT 1000
-#define _SYNC_t HANDLE
-/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
-/ module itself. Note that regardless of this option, file access to different
-/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
-/ and f_fdisk() function, are always not re-entrant. Only file/directory access
-/ to the same volume is under control of this feature.
-/
-/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
-/ 1: Enable re-entrancy. Also user provided synchronization handlers,
-/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/ function, must be added to the project. Samples are available in
-/ option/syscall.c.
-/
-/ The _FS_TIMEOUT defines timeout period in unit of time tick.
-/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
-/ SemaphoreHandle_t and etc.. */
-
-
-#define _WORD_ACCESS 1 /* 0 or 1 */
-/* The _WORD_ACCESS option is an only platform dependent option. It defines
-/ which access method is used to the word data on the FAT volume.
-/
-/ 0: Byte-by-byte access. Always compatible with all platforms.
-/ 1: Word access. Do not choose this unless under both the following conditions.
-/
-/ * Address misaligned memory access is always allowed to ALL instructions.
-/ * Byte order on the memory is little-endian.
-/
-/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
-/ Following table shows allowable settings of some processor types.
-/
-/ ARM7TDMI 0 ColdFire 0 V850E 0
-/ Cortex-M3 0 Z80 0/1 V850ES 0/1
-/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
-/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
-/ AVR32 0 RL78 0 R32C 0
-/ PIC18 0/1 SH-2 0 M16C 0/1
-/ PIC24 0 H8S 0 MSP430 0
-/ PIC32 0 H8/300H 0 8051 0/1
-*/
diff --git a/fatfs/src/option/ccsbcs.c b/fatfs/src/option/ccsbcs.c
index b16db30..002b803 100644
--- a/fatfs/src/option/ccsbcs.c
+++ b/fatfs/src/option/ccsbcs.c
@@ -27,11 +27,16 @@
#include "../ff.h"
+#ifdef __FLASH
+#define FLASH __flash
+#else
+#define FLASH
+#endif
#if _CODE_PAGE == 437
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@@ -53,7 +58,7 @@ const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 720
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9,
@@ -75,7 +80,7 @@ const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 737
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9,
@@ -97,7 +102,7 @@ const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 775
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107,
0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A,
@@ -119,7 +124,7 @@ const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 850
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@@ -141,7 +146,7 @@ const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 852
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7,
0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A,
@@ -163,7 +168,7 @@ const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 855
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404,
0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C,
@@ -185,7 +190,7 @@ const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 857
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@@ -207,7 +212,7 @@ const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 858
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@@ -229,7 +234,7 @@ const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 862
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
@@ -251,7 +256,7 @@ const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 866
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
@@ -273,7 +278,7 @@ const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 874
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -295,7 +300,7 @@ const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1250
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -317,7 +322,7 @@ const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1251
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -339,7 +344,7 @@ const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1252
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -361,7 +366,7 @@ const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1253
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -383,7 +388,7 @@ const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1254
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -405,7 +410,7 @@ const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1255
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -427,7 +432,7 @@ const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1256
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -449,7 +454,7 @@ const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1257
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -471,7 +476,7 @@ const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1258
#define _TBLDEF 1
static
-const WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */
+const FLASH WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -529,8 +534,8 @@ WCHAR ff_wtoupper ( /* Upper converted character */
WCHAR chr /* Input character */
)
{
- static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
- static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
+ static const FLASH WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
+ static const FLASH WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
int i;
diff --git a/include/avr/ffconf.h b/include/avr/ffconf.h
index 88c53d1..fadbe3d 100644
--- a/include/avr/ffconf.h
+++ b/include/avr/ffconf.h
@@ -1,7 +1,251 @@
+/*---------------------------------------------------------------------------/
+/ FatFs - FAT file system module configuration file R0.10c (C)ChaN, 2014
+/---------------------------------------------------------------------------*/
-#undef _WORD_ACCESS
+#define _FFCONF 80376 /* Revision ID */
-#define _WORD_ACCESS 0 /* 0 or 1 */
+/*---------------------------------------------------------------------------/
+/ Functions and Buffer Configurations
+/---------------------------------------------------------------------------*/
+
+#define _FS_TINY 1
+/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
+/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
+/ bytes. Instead of private sector buffer eliminated from the file object,
+/ common sector buffer in the file system object (FATFS) is used for the file
+/ data transfer. */
+
+
+#define _FS_READONLY 0
+/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
+/ Read-only configuration removes basic writing API functions, f_write(),
+/ f_sync(), f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(),
+/ f_getfree() and optional writing functions as well. */
+
+
+#define _FS_MINIMIZE 0
+/* This option defines minimization level to remove some API functions.
+/
+/ 0: All basic functions are enabled.
+/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
+/ f_truncate() and f_rename() function are removed.
+/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
+/ 3: f_lseek() function is removed in addition to 2. */
+
+
+#define _USE_STRFUNC 0
+/* This option switches string functions, f_gets(), f_putc(), f_puts() and
+/ f_printf().
+/
+/ 0: Disable string functions.
+/ 1: Enable without LF-CRLF conversion.
+/ 2: Enable with LF-CRLF conversion. */
+
+
+#define _USE_MKFS 0
+/* This option switches f_mkfs() function. (0:Disable or 1:Enable)
+/ To enable it, also _FS_READONLY need to be set to 0. */
+
+
+#define _USE_FASTSEEK 0
+/* This option switches fast seek feature. (0:Disable or 1:Enable) */
+
+
+#define _USE_LABEL 1
+/* This option switches volume label functions, f_getlabel() and f_setlabel().
+/ (0:Disable or 1:Enable) */
+
+
+#define _USE_FORWARD 0
+/* This option switches f_forward() function. (0:Disable or 1:Enable) */
+/* To enable it, also _FS_TINY need to be set to 1. */
+
+
+/*---------------------------------------------------------------------------/
+/ Locale and Namespace Configurations
+/---------------------------------------------------------------------------*/
+
+#define _CODE_PAGE 858
+/* This option specifies the OEM code page to be used on the target system.
+/ Incorrect setting of the code page can cause a file open failure.
+/
+/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
+/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
+/ 949 - Korean (DBCS, OEM, Windows)
+/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
+/ 1250 - Central Europe (Windows)
+/ 1251 - Cyrillic (Windows)
+/ 1252 - Latin 1 (Windows)
+/ 1253 - Greek (Windows)
+/ 1254 - Turkish (Windows)
+/ 1255 - Hebrew (Windows)
+/ 1256 - Arabic (Windows)
+/ 1257 - Baltic (Windows)
+/ 1258 - Vietnam (OEM, Windows)
+/ 437 - U.S. (OEM)
+/ 720 - Arabic (OEM)
+/ 737 - Greek (OEM)
+/ 775 - Baltic (OEM)
+/ 850 - Multilingual Latin 1 (OEM)
+/ 858 - Multilingual Latin 1 + Euro (OEM)
+/ 852 - Latin 2 (OEM)
+/ 855 - Cyrillic (OEM)
+/ 866 - Russian (OEM)
+/ 857 - Turkish (OEM)
+/ 862 - Hebrew (OEM)
+/ 874 - Thai (OEM, Windows)
+/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
+
+
+#define _USE_LFN 1
+#define _MAX_LFN 128
+/* The _USE_LFN option switches the LFN feature.
+/
+/ 0: Disable LFN feature. _MAX_LFN has no effect.
+/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
+/ 2: Enable LFN with dynamic working buffer on the STACK.
+/ 3: Enable LFN with dynamic working buffer on the HEAP.
+/
+/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
+/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
+/ When use stack for the working buffer, take care on stack overflow. When use heap
+/ memory for the working buffer, memory management functions, ff_memalloc() and
+/ ff_memfree(), must be added to the project. */
+
+
+#define _LFN_UNICODE 0
+/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
+/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
+/ to 1. This option also affects behavior of string I/O functions. */
+
+
+#define _STRF_ENCODE 3
+/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
+/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
+/
+/ 0: ANSI/OEM
+/ 1: UTF-16LE
+/ 2: UTF-16BE
+/ 3: UTF-8
+/
+/ When _LFN_UNICODE is 0, this option has no effect. */
+
+
+#define _FS_RPATH 2
+/* This option configures relative path feature.
+/
+/ 0: Disable relative path feature and remove related functions.
+/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
+/ 2: f_getcwd() function is available in addition to 1.
+/
+/ Note that directory items read via f_readdir() are affected by this option. */
+
+
+/*---------------------------------------------------------------------------/
+/ Drive/Volume Configurations
+/---------------------------------------------------------------------------*/
+
+#define _VOLUMES 2
+/* Number of volumes (logical drives) to be used. */
+
+
+#define _STR_VOLUME_ID 0
+#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
+/* _STR_VOLUME_ID option switches string volume ID feature.
+/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
+/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
+/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
+/ the drive ID strings are: A-Z and 0-9. */
+
+
+#define _MULTI_PARTITION 0
+/* This option switches multi-partition feature. By default (0), each logical drive
+/ number is bound to the same physical drive number and only an FAT volume found on
+/ the physical drive will be mounted. When multi-partition feature is enabled (1),
+/ each logical drive number is bound to arbitrary physical drive and partition
+/ listed in the VolToPart[]. Also f_fdisk() funciton will be enabled. */
+
+
+#define _MIN_SS 512
+#define _MAX_SS 512
+/* These options configure the range of sector size to be supported. (512, 1024,
+/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
+/ harddisk. But a larger value may be required for on-board flash memory and some
+/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
+/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
+/ disk_ioctl() function. */
+
+
+#define _USE_TRIM 0
+/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
+/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
+/ disk_ioctl() function. */
+
+
+#define _FS_NOFSINFO 0
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
+/ option, and f_getfree() function at first time after volume mount will force
+/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
+/
+/ bit0=0: Use free cluster count in the FSINFO if available.
+/ bit0=1: Do not trust free cluster count in the FSINFO.
+/ bit1=0: Use last allocated cluster number in the FSINFO if available.
+/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
+*/
+
+
+
+/*---------------------------------------------------------------------------/
+/ System Configurations
+/---------------------------------------------------------------------------*/
+
+#define _FS_NORTC 0
+#define _NORTC_MON 11
+#define _NORTC_MDAY 9
+#define _NORTC_YEAR 2014
+/* The _FS_NORTC option switches timestamp feature. If the system does not have
+/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
+/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
+/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
+/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
+/ to be added to the project to read current time form RTC. _NORTC_MON,
+/ _NORTC_MDAY and _NORTC_YEAR have no effect.
+/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
+
+
+#define _FS_LOCK 0
+/* The _FS_LOCK option switches file lock feature to control duplicated file open
+/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
+/ is 1.
+/
+/ 0: Disable file lock feature. To avoid volume corruption, application program
+/ should avoid illegal open, remove and rename to the open objects.
+/ >0: Enable file lock feature. The value defines how many files/sub-directories
+/ can be opened simultaneously under file lock control. Note that the file
+/ lock feature is independent of re-entrancy. */
+
+
+#define _FS_REENTRANT 0
+#define _FS_TIMEOUT 1000
+#define _SYNC_t HANDLE
+/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
+/ module itself. Note that regardless of this option, file access to different
+/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
+/ and f_fdisk() function, are always not re-entrant. Only file/directory access
+/ to the same volume is under control of this feature.
+/
+/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
+/ 1: Enable re-entrancy. Also user provided synchronization handlers,
+/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
+/ function, must be added to the project. Samples are available in
+/ option/syscall.c.
+/
+/ The _FS_TIMEOUT defines timeout period in unit of time tick.
+/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
+/ SemaphoreHandle_t and etc.. */
+
+
+#define _WORD_ACCESS 1 /* 0 or 1 */
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
diff --git a/include/background.h b/include/background.h
index 8a430b3..87e95e5 100644
--- a/include/background.h
+++ b/include/background.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef BACKGROUND_H
#define BACKGROUND_H
@@ -9,4 +15,3 @@ int bg_getstat(int handle);
void bg_shed(void);
#endif /* BACKGROUND_H */
-
diff --git a/include/bcd.h b/include/bcd.h
new file mode 100644
index 0000000..efbebcc
--- /dev/null
+++ b/include/bcd.h
@@ -0,0 +1,13 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef BCD_H
+#define BCD_H
+
+uint_fast8_t bcd2bin(uint8_t val);
+uint8_t bin2bcd (uint_fast8_t val);
+
+#endif /* BCD_H */
diff --git a/include/cli.h b/include/cli.h
index 67ff63b..4920cc4 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -1,4 +1,13 @@
-#ifndef CLI_H
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2014 Google, Inc
+ * Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef CLI_H
#define CLI_H
/**
@@ -57,8 +66,16 @@ void cli_loop(void);
*/
//int cli_simple_parse_line(char *line, char *argv[]);
+/*
+ * Run a command.
+ *
+ * @param cmd Command to run
+ * @param flag Execution flags (CMD_FLAG_...)
+ * @return 0 on success, or != 0 on error.
+ */
+int run_command(const char *cmd, int flag);
+
int run_command_list(const char *cmd, int len);
#endif /* CLI_H */
-
diff --git a/include/cli_readline.h b/include/cli_readline.h
index 5b25762..b7dc938 100644
--- a/include/cli_readline.h
+++ b/include/cli_readline.h
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* (C) Copyright 2014 Google, Inc
* Simon Glass <sjg@chromium.org>
*
@@ -47,4 +49,3 @@ int cli_readline(const FLASH char *const prompt);
#endif /* CLI_READLINE_H */
-
diff --git a/include/cmd_mem.h b/include/cmd_mem.h
index 1802338..782c10a 100644
--- a/include/cmd_mem.h
+++ b/include/cmd_mem.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef CMD_MEM_H
#define CMD_MEM_H
@@ -13,16 +19,12 @@ extern command_ret_t do_mem_cp(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_mem_cmp(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_mem_base(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_mem_loop(cmd_tbl_t *, int, int, char * const []);
-#ifdef CONFIG_LOOPW
extern command_ret_t do_mem_loopw(cmd_tbl_t *, int, int, char * const []);
-#endif
#ifdef CONFIG_CMD_MEMTEST
extern command_ret_t do_mem_mtest(cmd_tbl_t *, int, int, char * const []);
#endif
#ifdef CONFIG_MX_CYCLIC
extern command_ret_t do_mem_mdc(cmd_tbl_t *, int, int, char * const []);
-extern command_ret_t do_mem_mwc(cmd_tbl_t *, int, int, char * const []);
#endif /* CONFIG_MX_CYCLIC */
#endif /* CMD_MEM_H */
-
diff --git a/include/command.h b/include/command.h
index d0933a0..5582fa5 100644
--- a/include/command.h
+++ b/include/command.h
@@ -1,3 +1,11 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
/*
* Definitions for Command Processor
@@ -37,11 +45,11 @@ typedef enum {
struct cmd_tbl_s {
const FLASH char *name; /* Command Name */
- int maxargs; /* maximum number of arguments */
- int repeatable; /* autorepeat allowed? */
- /* Implementation function */
+ int maxargs; /* maximum number of arguments */
+ int repeatable; /* autorepeat allowed? */
+ /* Implementation function */
command_ret_t (*cmd)(const FLASH struct cmd_tbl_s *, int, int, char * const []);
- const FLASH char *usage; /* Usage message (short) */
+ const FLASH char *usage; /* Usage message (short) */
#ifdef CONFIG_SYS_LONGHELP
const FLASH char *help; /* Help message (long) */
#endif
diff --git a/include/common.h b/include/common.h
index b0dd038..10c4417 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef COMMON_H
#define COMMON_H
@@ -46,6 +52,12 @@ struct bits {
#define FSTR(X) ((const FLASH char[]) { X } )
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define MIN(a,b) ({ typeof (a) _a = (a); \
+ typeof (b) _b = (b); \
+ _a < _b ? _a : _b; })
+#define MAX(a,b) ({ typeof (a) _a = (a); \
+ typeof (b) _b = (b); \
+ _a > _b ? _a : _b; })
#ifdef __AVR__
#define Stat GPIOR0
@@ -53,7 +65,7 @@ struct bits {
extern volatile uint_least8_t Stat;
#endif /* __AVR__ */
-#define S_10MS_TO (1<<0)
+#define S_10MS_TO (1<<0)
#define S_MSG_PENDING (1<<1)
#define S_CON_PENDING (1<<2)
diff --git a/include/con-utils.h b/include/con-utils.h
index 15a3ce8..86c0df0 100644
--- a/include/con-utils.h
+++ b/include/con-utils.h
@@ -1,4 +1,14 @@
-#ifndef CON_UTILS_H
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * Console utilities
+ */
+
+#ifndef CON_UTILS_H
#define CON_UTILS_H
uint_fast8_t tstc(void);
@@ -18,5 +28,3 @@ uint_fast8_t had_ctrlc (void);
void clear_ctrlc(void);
#endif /* CON_UTILS_H */
-
-
diff --git a/include/config.h b/include/config.h
index d192559..e4e6096 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef CONFIG_H
#define CONFIG_H
@@ -6,7 +12,14 @@
#define ENV_BAUDRATE "baudrate"
#define ENV_BOOTDELAY "bootdelay"
#define ENV_BOOTCMD "bootcmd"
+
+#define ENV_CPM3_SYSFILE "cpm3_file"
+#define ENV_CPM3_COMMON_BASE "cpm3_commonbase"
+#define ENV_CPM3_BANKED_BASE "cpm3_bankedbase"
+
#define ENV_PINALIAS "pin_alias"
+#define ENV_STARTADDRESS "startaddress"
+#define ENV_ESC_CHAR "esc_char"
#define CONFIG_ENV_SIZE 1600
#define CONFIG_ENV_OFFSET 0
@@ -17,12 +30,22 @@
#define CONFIG_BOOTDELAY 4
//#define CONFIG_ZERO_BOOTDELAY_CHECK 1
-//#define CONFIG_LOOPW
-//#define CONFIG_CMD_MEMTEST
-//#define CONFIG_MX_CYCLIC
+#define CONFIG_CPM3_SYSFILE "1:/cpm3.sys"
+#define CONFIG_CPM3_COMMON_BASE 0xC000
+#define CONFIG_CPM3_BANKED_BASE 0x0
+#define CONFIG_CPM3_COMMON_BASE_STR "C000"
+#define CONFIG_CPM3_BANKED_BASE_STR "0"
+
+#define CONFIG_CMD_MEMTEST
+#define CONFIG_MX_CYCLIC
+#define CONFIG_SYS_RAMSIZE_MAX (1l<<19) /* max. addressable memory */
#define CONFIG_CMD_DATE 1
+
+//#define CONFIG_CMD_LOADB
+
+
#define CONFIG_SYS_I2C_RTC_ADDR 0x50
#define CONFIG_SYS_I2C_BUFSIZE 64
#define CONFIG_SYS_I2C_CLOCK 100000L /* SCL clock frequency in Hz */
@@ -34,6 +57,7 @@
#define CONFIG_SYS_PROMPT "=> "
#define CONFIG_ESC_CHAR ('^'-0x40)
+#define CONFIG_SYS_FBOOTSIG "Peda"
#define CONFIG_CMDLINE_EDITING 1
/* TODO: */
diff --git a/include/crc.h b/include/crc.h
index 927b5ff..89cde1f 100644
--- a/include/crc.h
+++ b/include/crc.h
@@ -1,14 +1,21 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef CRC_H
#define CRC_H
#ifdef __AVR__
#include <util/crc16.h>
static inline
-uint16_t crc16(uint16_t crc, uint8_t data)
+uint16_t crc16(uint16_t crc, uint8_t data)
{
return _crc_ccitt_update(crc, data);
}
#else /* !__AVR__ */
+ /* TODO */
#endif /* __AVR__ */
#endif /* CRC_H */
diff --git a/include/debug.h b/include/debug.h
index da8e9a0..39c15b0 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -1,3 +1,12 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef DEBUG_H_
#define DEBUG_H_
@@ -10,6 +19,11 @@
#define _DEBUG 0
#endif
+/*
+ * Output a debug text when condition "cond" is met. The "cond" should be
+ * computed by a preprocessor in the best case, allowing for the best
+ * optimization.
+ */
#define debug_cond(cond, fmt, args...) \
do { \
if (cond) \
diff --git a/include/diskio.h b/include/diskio.h
index f5ba3e0..fee87a5 100644
--- a/include/diskio.h
+++ b/include/diskio.h
@@ -45,6 +45,8 @@ void disk_timerproc (void);
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
+#define STA_FAST 0x08 /* Fast SPI clock */
+#define STAT_MASK (STA_NOINIT | STA_NODISK | STA_PROTECT)
/* Command code for disk_ioctrl() */
diff --git a/include/env.h b/include/env.h
index 7c4fee9..da38c54 100644
--- a/include/env.h
+++ b/include/env.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef ENV_H
#define ENV_H
@@ -8,9 +14,8 @@ unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long defaul
int setenv_ulong(const MEMX char *varname, unsigned long value);
int setenv_hex(const MEMX char *varname, unsigned long value);
-#if defined(CONFIG_AUTO_COMPLETE)
+#if defined(CONFIG_AUTO_COMPLETE)
int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
#endif
#endif /* ENV_H */
-
diff --git a/include/ff.h b/include/ff.h
index c19b7b5..7fb6cb1 100644..120000
--- a/include/ff.h
+++ b/include/ff.h
@@ -1,2 +1 @@
-#include "../fatfs/src/ff.h"
-#include "avr/ffconf.h"
+../fatfs/src/ff.h \ No newline at end of file
diff --git a/include/ffconf.h b/include/ffconf.h
new file mode 100644
index 0000000..9841d5b
--- /dev/null
+++ b/include/ffconf.h
@@ -0,0 +1,5 @@
+#ifdef __AVR__
+#include "avr/ffconf.h"
+#else
+ /* TODO */
+#endif
diff --git a/include/getopt-min.h b/include/getopt-min.h
index 9f7729e..6495ebf 100644
--- a/include/getopt-min.h
+++ b/include/getopt-min.h
@@ -1,12 +1,11 @@
#ifndef GETOPT_MIN_H
#define GETOPT_MIN_H
-int getopt( /* returns letter, '?', EOF */
- int argc, /* argument count from main */
- char *const argv[], /* argument vector from main */
+int getopt( /* returns letter, '?', EOF */
+ int argc, /* argument count from main */
+ char *const argv[], /* argument vector from main */
const FLASH char * optstring ); /* allowed args, e.g. "ab:c" */
extern int optind;
#endif /* GETOPT_MIN_H */
-
diff --git a/include/gpio.h b/include/gpio.h
index ac48045..1e0346d 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef GPIO_H
#define GPIO_H
@@ -14,4 +20,3 @@ int gpio_clockdiv_set(int pin, unsigned long divider);
long gpio_clockdiv_get(int pin);
#endif /* GPIO_H */
-
diff --git a/include/i2c.h b/include/i2c.h
index 50b1fd0..f39fa1d 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -1,4 +1,6 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
* Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net>
* Copyright (C) 2009 - 2013 Heiko Schocher <hs@denx.de>
* Changes for multibus/multiadapter I2C support.
diff --git a/include/print-utils.h b/include/print-utils.h
index 5604d3b..7d48287 100644
--- a/include/print-utils.h
+++ b/include/print-utils.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef PRINT_UTILS_H
#define PRINT_UTILS_H
@@ -13,5 +19,6 @@ void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title);
void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
#endif /* PRINT_UTILS_H */
diff --git a/include/ring.h b/include/ring.h
index d57f9aa..b64f462 100644
--- a/include/ring.h
+++ b/include/ring.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef RING_H
#define RING_H
@@ -71,4 +77,3 @@ int_fast8_t ring_is_empty(struct ring *ring)
}
#endif /* RING_H */
-
diff --git a/include/rtc.h b/include/rtc.h
index 51ee424..ca4c068 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -1,48 +1,13 @@
/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
-/*
- * Generic RTC interface.
- */
#ifndef _RTC_H_
#define _RTC_H_
-
-/*
- * The struct used to pass data from the generic interface code to
- * the hardware dependend low-level code ande vice versa. Identical
- * to struct rtc_time used by the Linux kernel.
- *
- * Note that there are small but significant differences to the
- * common "struct time":
- *
- * struct time: struct rtc_time:
- * tm_mon 0 ... 11 1 ... 12
- * tm_year years since 1900 years since 0
- */
-
-struct rtc_time {
- int tm_sec;
- int tm_min;
- int tm_hour;
- int tm_mday;
- int tm_mon;
- int tm_year;
- int tm_wday;
- int tm_yday;
- int tm_isdst;
-};
-
-int rtc_get (struct rtc_time *);
-int rtc_set (struct rtc_time *);
-
-void GregorianDay (struct rtc_time *);
-void to_tm (unsigned long, struct rtc_time *);
-unsigned long mktime (unsigned int, unsigned int, unsigned int,
- unsigned int, unsigned int, unsigned int);
+int rtc_get (struct tm *);
+int rtc_set (struct tm *);
#endif /* _RTC_H_ */
diff --git a/include/serial.h b/include/serial.h
index 40ac815..54c7211 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef SERIAL_H
#define SERIAL_H
diff --git a/include/spi.h b/include/spi.h
index 04ea726..1052569 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -1,8 +1,7 @@
/*
- * spi.h
+ * (C) Copyright 2009,2014 Leo C. <erbl259-lmu@yahoo.de>
*
- * Created on: 17.04.2009
- * Author: leo
+ * SPDX-License-Identifier: GPL-2.0+
*/
#ifndef SPI_H_
@@ -27,10 +26,11 @@
#define SPI_SET_SPEED_F_128 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0)
/** switch to fast SPI Clock */
-#define SPISetFastClock() SPI_SET_SPEED_F_2
-#define SPISetSlowClock() SPI_SET_SPEED_F_8
-#define SPISetMMCInitClock() SPI_SET_SPEED_F_64
+#define SPISetFastClock() SPI_SET_SPEED_F_2
+#define SPISetSlowClock() SPI_SET_SPEED_F_8
+#define SPISetMMCInitClock() SPI_SET_SPEED_F_64
+#define SPI_OFF() do { SPCR = 0; } while(0)
static inline void spi_wait() {
loop_until_bit_is_set(SPSR,SPIF);
diff --git a/include/time.h b/include/time.h
new file mode 120000
index 0000000..b9ae22c
--- /dev/null
+++ b/include/time.h
@@ -0,0 +1 @@
+../time/time.h \ No newline at end of file
diff --git a/include/timer.h b/include/timer.h
index bed3eb0..c6d6053 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -1,7 +1,12 @@
-#ifndef TIMER_H
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef TIMER_H
#define TIMER_H
uint32_t get_timer(uint32_t);
#endif /* TIMER_H */
-
diff --git a/include/z180-serv.h b/include/z180-serv.h
index af4b1c0..424318f 100644
--- a/include/z180-serv.h
+++ b/include/z180-serv.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef Z180_SERV_H
#define Z180_SERV_H
diff --git a/include/z80-if.h b/include/z80-if.h
index d4ee57b..676d37d 100644
--- a/include/z80-if.h
+++ b/include/z80-if.h
@@ -1,3 +1,8 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
#define ZST_ACQUIRED 0x01
#define ZST_RUNNING 0x02
@@ -38,7 +43,7 @@ void z80_read_block (uint8_t *dest, uint32_t src, size_t length);
typedef enum fifo_t {
fifo_msgin, fifo_msgout,
- fifo_conout, fifo_conin,
+ fifo_conin, fifo_conout,
NUM_FIFOS
} fifo_t;
diff --git a/stm32/debug.h b/stm32/debug.h
index d542317..692c879 100644
--- a/stm32/debug.h
+++ b/stm32/debug.h
@@ -1,3 +1,8 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
#ifndef DEBUG_H_
#define DEBUG_H_
diff --git a/stm32/serial.c b/stm32/serial.c
index 9193005..d2f1a93 100644
--- a/stm32/serial.c
+++ b/stm32/serial.c
@@ -1,8 +1,7 @@
/*
- * serial.c
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
*
- * Created on: 04.05.2014
- * Author: leo
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include <errno.h>
diff --git a/stm32/serial.h b/stm32/serial.h
index 1a0f510..62d95e2 100644
--- a/stm32/serial.h
+++ b/stm32/serial.h
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#ifndef SERIAL_H
#define SERIAL_H
diff --git a/stm32/z180-stamp-stm32.c b/stm32/z180-stamp-stm32.c
index 15d732d..7000c53 100644
--- a/stm32/z180-stamp-stm32.c
+++ b/stm32/z180-stamp-stm32.c
@@ -1,4 +1,7 @@
/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include <stdio.h>
@@ -86,26 +89,26 @@ static void clock_setup(void)
/* Enable clocks for:
GPIO port A (for GPIO_USART1_TX and Button)
- GPIO port C (LEDs)
+ GPIO port C (LEDs)
USART1
- TIM16 (RST-Pin)
+ TIM16 (RST-Pin)
TIM1 (IOCS1)
*/
- rcc_peripheral_enable_clock(&RCC_APB2ENR,
- RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN
- | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN
+ rcc_peripheral_enable_clock(&RCC_APB2ENR,
+ RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN
+ | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN
| RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN
| RCC_APB2ENR_TIM1EN | RCC_APB2ENR_TIM16EN);
/* Enable clocks for:
TIM3
*/
- rcc_peripheral_enable_clock(&RCC_APB1ENR,
+ rcc_peripheral_enable_clock(&RCC_APB1ENR,
RCC_APB1ENR_TIM3EN);
/* Enable clocks for:
DMA1
*/
- rcc_peripheral_enable_clock(&RCC_AHBENR,
+ rcc_peripheral_enable_clock(&RCC_AHBENR,
RCC_AHBENR_DMA1EN);
}
@@ -129,19 +132,19 @@ static void nvic_setup(void)
static void tim3_setup(void)
{
TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP;
-
+
TIM3_CCMR2 = 0
- | TIM_CCMR2_OC4M_FORCE_LOW
+ | TIM_CCMR2_OC4M_FORCE_LOW
/* | TIM_CCMR2_OC4M_FORCE_HIGH */
/* | TIM_CCMR2_OC4M_PWM2 */
-
+
/* | TIM_CCMR2_OC4PE */
/* | TIM_CCMR2_OC4FE */
| TIM_CCMR2_CC4S_OUT;
-
+
TIM3_CCER = TIM_CCER_CC4E
| TIM_CCER_CC4P;
-
+
TIM3_ARR = 48; /* default */
TIM3_CCR4 = 1; /* */
}
@@ -154,7 +157,7 @@ static void gpio_setup(void)
Remap TIM3 (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9)
Port D0/Port D1 mapping on OSC_IN/OSC_OUT
*/
- gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON,
+ gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON,
AFIO_MAPR_SPI1_REMAP
| AFIO_MAPR_TIM3_REMAP_FULL_REMAP
| AFIO_MAPR_PD01_REMAP);
@@ -174,7 +177,7 @@ static void gpio_setup(void)
void delay_systicks(int ticks)
{
int start, stop, now;
-
+
start = STK_CVR;
stop = start - ticks;
if (stop < 0) {
@@ -298,13 +301,13 @@ static void key_timerproc() {
// key_state = key_state & key_in | (key_state | key_in) & key_in_last;
key_state = c | ((key_in_last | key_in) & key_state);
-
+
// key_state = (key_state&key_in_last) | (key_state&key_in) | (key_in_last&key_in);
key_press |= c;
-
+
key_in_last = key_in;
-
+
if ((key_state & REPEAT_MASK) == 0) // check repeat function
rpt = REPEAT_START;
@@ -330,7 +333,7 @@ void sys_tick_handler(void)
Stat |= S_10MS_TO;
tick_10ms = 0;
-
+
i = led_timer[0];
if (i)
led_timer[0] = i - 1;
@@ -339,11 +342,11 @@ void sys_tick_handler(void)
led_timer[1] = i - 1;
key_timerproc();
-
+
/* Drive timer procedure of low level disk I/O module */
//disk_timerproc();
}
-
+
count_ms++;
if (count_ms == 1000) {
count_ms = 0;
@@ -366,7 +369,7 @@ void rtc_isr(void)
void tim3_set(int mode)
{
uint16_t cc_mode;
-
+
cc_mode = TIM_CCMR2_CC4S_OUT;
TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP /*| TIM_CR1_OPM */ ;
@@ -380,9 +383,9 @@ void tim3_set(int mode)
TIM3_CCR4 = mode/2;
cc_mode |= TIM_CCMR2_OC4M_PWM2;
}
-
+
TIM3_CCMR2 = cc_mode;
-
+
if (mode > 0)
TIM3_CR1 |= TIM_CR1_CEN;
}
@@ -393,17 +396,17 @@ static uint32_t z80_sram_cmp(uint32_t addr, uint32_t length, uint8_t wval, int i
{
uint8_t rval;
int_fast8_t errors = 0;
-
+
DBG_P(1, "SRAM: Check %#.5x byte... ", length);
while (length--) {
if ((rval = z80_read(addr)) != wval) {
- if (errors == 0) {
+ if (errors == 0) {
printf("\nSRAM: Address W R\n" \
" -------------\n");
// 12345 00 11
}
printf(" %.5lx %.2x %.2x\n", addr, wval, rval);
-
+
if (++errors > 16 )
break;
}
@@ -421,7 +424,7 @@ static void z80_sram_fill(uint32_t addr, int length, uint8_t startval, int inc)
printf("SRAM: Write %#.5x byte... ", length); //fflush(stdout);
while (length--) {
z80_write(addr, startval);
- ++addr;
+ ++addr;
startval += inc;
}
printf("Done.\n");
@@ -465,18 +468,18 @@ const char * const qbcat = "Zhe quick brown fox jumps over the lazy cat!";
uint8_t z80_get_byte(uint32_t adr)
{
uint8_t data;
-
+
z80_request_bus();
data = z80_read(adr),
z80_release_bus();
-
+
return data;
}
/*--------------------------------------------------------------------------*/
-static void do_10ms(void)
+static void do_10ms(void)
{
for (uint_fast8_t i = 0; i < 2; i++) {
switch (led_stat[i].mode) {
@@ -696,19 +699,19 @@ int main(void)
z80_reset(HIGH);
z80_request_bus();
DBG_P(1, "got it!\n");
-
+
z80_memset(0, 0x76, 0x80000);
//z80_sram_fill(0, 512 * 1024, 0x76, 0);
z80_sram_cmp(0, (uint32_t)512 * 1024, 0x76, 0);
-
+
z80_load_mem();
z80_reset(LOW);
DBG_P(1, "Bus released!\n");
z80_release_bus();
z80_reset(HIGH);
DBG_P(1, "Reset released!\n");
-
-
+
+
ledset(0, BLINK1, 50);
while (1) {
diff --git a/stm32/z80-if.c b/stm32/z80-if.c
index 171fea9..6c415d1 100644
--- a/stm32/z80-if.c
+++ b/stm32/z80-if.c
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
/**
*
* Pin assignments
@@ -111,8 +117,8 @@ AFIO_MAPR_SPI1_REMAP
AFIO_MAPR2 =
-AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON (frees
-AFIO_MAPR_SPI1_REMAP
+AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON (frees
+AFIO_MAPR_SPI1_REMAP
*/
@@ -220,7 +226,7 @@ AFIO_MAPR_SPI1_REMAP
#define IOFIELD_GET(src, width, shift) \
((src>>shift) & MASK(width))
-
+
#define CNF_MODE_I_F (GPIO_CNF_INPUT_FLOAT<<2 |GPIO_MODE_INPUT)
#define CNF_MODE_O_PP (GPIO_CNF_OUTPUT_PUSHPULL<<2 | GPIO_MODE_OUTPUT_10_MHZ)
@@ -249,16 +255,16 @@ static void tim16_setup(void)
{
RCC_APB2RSTR |= RCC_APB2RSTR_TIM16RST;
RCC_APB2RSTR &= ~RCC_APB2RSTR_TIM16RST;
-
+
TIM16_BDTR = TIM_BDTR_MOE;
-
+
TIM16_CCMR1 = 0
- | TIM_CCMR1_OC1M_FORCE_LOW
+ | TIM_CCMR1_OC1M_FORCE_LOW
| TIM_CCMR1_CC1S_OUT;
-
+
TIM16_CCER = TIM_CCER_CC1NE
| TIM_CCER_CC1NP;
-
+
TIM16_ARR = 48; /* default */
TIM16_CCR1 = 1; /* */
}
@@ -268,7 +274,7 @@ static void tim16_setup(void)
static void tim16_set(int mode)
{
uint16_t cc_mode;
-
+
cc_mode = TIM_CCMR1_CC1S_OUT;
TIM16_CR1 = TIM_CR1_OPM;
@@ -281,9 +287,9 @@ static void tim16_set(int mode)
TIM16_ARR = mode;
cc_mode |= TIM_CCMR1_OC1M_PWM2;
}
-
+
TIM16_CCMR1 = cc_mode;
-
+
if (mode > 0)
TIM16_CR1 |= TIM_CR1_CEN;
}
@@ -292,44 +298,44 @@ static void tim16_set(int mode)
-/*
+/*
* A0..A6, A8..A13 are buffered. No need to disable.
* A7, A14..A18: set to input.
*/
-
+
static void z80_setup_adrbus_tristate(void)
{
#if 0
gpio_set_mode(ADunbuff1_PORT, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_FLOAT, MASK(ADunbuff1_WIDTH) << ADunbuff1_SHIFT);
- gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
+ gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
(MASK(ADunbuff2_WIDTH) << ADunbuff2_SHIFT) | (MASK(ADunbuff3_WIDTH) << ADunbuff3_SHIFT));
#else
- GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0)))
+ GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0)))
| (CNF_MODE_I_F << (4 * 0));
GPIO_CRL(GPIOC) = (GPIO_CRL(GPIOC) & ~((0x0f << (4 * 6)) | (0x0f << (4 * 7))))
| ((CNF_MODE_I_F << (4 * 6)) | (CNF_MODE_I_F << (4 * 7)));
GPIO_CRH(GPIOC) = (GPIO_CRH(GPIOC) & ~((0x0f << (4*2)) | (0x0f << (4*3)) | (0x0f << (4*4))))
| ((CNF_MODE_I_F << (4*2)) | (CNF_MODE_I_F << (4*3)) | (CNF_MODE_I_F << (4*4)));
-#endif
+#endif
}
-
+
static void z80_setup_adrbus_active(void)
{
#if 0
gpio_set_mode(ADunbuff1_PORT, GPIO_MODE_OUTPUT_10_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, MASK(ADunbuff1_WIDTH) << ADunbuff1_SHIFT);
- gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
+ gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
(MASK(ADunbuff2_WIDTH) << ADunbuff2_SHIFT) | (MASK(ADunbuff3_WIDTH) << ADunbuff3_SHIFT));
#else
- GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0)))
+ GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0)))
| (CNF_MODE_O_PP << (4 * 0));
GPIO_CRL(GPIOC) = (GPIO_CRL(GPIOC) & ~((0x0f << (4 * 6)) | (0x0f << (4 * 7))))
| ((CNF_MODE_O_PP << (4 * 6)) | (CNF_MODE_O_PP << (4 * 7)));
GPIO_CRH(GPIOC) = (GPIO_CRH(GPIOC) & ~((0x0f << (4*2)) | (0x0f << (4*3)) | (0x0f << (4*4))))
| ((CNF_MODE_O_PP << (4*2)) | (CNF_MODE_O_PP << (4*3)) | (CNF_MODE_O_PP << (4*4)));
-#endif
+#endif
}
@@ -402,9 +408,9 @@ void z80_release_bus(void)
void z80_reset(level_t level)
{
int x = level ? -1 : 0;
-
+
tim16_set(x);
-
+
// Z80_O_RST = level;
}
@@ -469,7 +475,7 @@ void z80_memset(uint32_t addr, uint8_t data, int length)
void z80_write_block(uint8_t *src, uint32_t dest, uint32_t length)
{
uint8_t data;
-
+
z80_setup_dbus_out();
Z80_O_ME = 0;
while(length--) {
@@ -488,7 +494,7 @@ void z80_write_block(uint8_t *src, uint32_t dest, uint32_t length)
017B' rx.out_idx: ds 1 ;
017C' rx.buf: ds rx.buf_len ;
018B' rx.buf_end equ $-1 ; last byte (start+len-1)
-
+
018C' tx.bs_mask: ds 1 ; (buf_len - 1)
018D' tx.in_idx: ds 1 ;
018E' tx.out_idx: ds 1 ;
@@ -517,7 +523,7 @@ static struct {
idx_in,
mask;
} fifo_dsc[NUM_FIFOS];
-
+
void z80_memfifo_init(const fifo_t f, uint32_t adr)
{
@@ -557,7 +563,7 @@ int z80_memfifo_is_empty(const fifo_t f)
int z80_memfifo_is_full(const fifo_t f)
{
int rc = 1;
-
+
if (fifo_dsc[f].base != 0) {
z80_request_bus();
rc = ((fifo_dsc[f].idx_in + 1) & fifo_dsc[f].mask)
@@ -570,7 +576,7 @@ int z80_memfifo_is_full(const fifo_t f)
uint8_t z80_memfifo_getc(const fifo_t f)
{
uint8_t rc, idx;
-
+
while (z80_memfifo_is_empty(f))
;
@@ -580,7 +586,7 @@ uint8_t z80_memfifo_getc(const fifo_t f)
fifo_dsc[f].idx_out = ++idx & fifo_dsc[f].mask;
z80_write(fifo_dsc[f].base+FIFO_INDEX_OUT, fifo_dsc[f].idx_out);
z80_release_bus();
-
+
return rc;
}
@@ -588,7 +594,7 @@ uint8_t z80_memfifo_getc(const fifo_t f)
void z80_memfifo_putc(fifo_t f, uint8_t val)
{
int idx;
-
+
while (z80_memfifo_is_full(f))
;
@@ -714,7 +720,7 @@ DBG_P(1, "z80_init_msg_fifo: %lx\n", addr);
int z80_msg_fifo_getc(void)
{
int c = -1;
-
+
if (msg_fifo.count != (NELEMS(msg_fifo.buf) - DMA1_CNDTR4)) {
c = msg_fifo.buf[msg_fifo.count];
if (++msg_fifo.count == NELEMS(msg_fifo.buf))
diff --git a/stm32/z80-if.h b/stm32/z80-if.h
index d7c030d..e65f160 100644
--- a/stm32/z80-if.h
+++ b/stm32/z80-if.h
@@ -1,3 +1,8 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
typedef enum {LOW, HIGH} level_t;
diff --git a/time/Files.am b/time/Files.am
new file mode 100644
index 0000000..26bfc62
--- /dev/null
+++ b/time/Files.am
@@ -0,0 +1,77 @@
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+time_a_c_sources = \
+ asc_store.c \
+ asctime.c \
+ asctime_r.c \
+ ctime.c \
+ ctime_r.c \
+ daylight_seconds.c \
+ difftime.c \
+ dst_pointer.c \
+ equation_of_time.c \
+ fatfs_time.c \
+ geo_location.c \
+ gm_sidereal.c \
+ gmtime.c \
+ gmtime_r.c \
+ isLeap.c \
+ isotime.c \
+ iso_week_date.c \
+ iso_week_date_r.c \
+ isotime_r.c \
+ lm_sidereal.c \
+ localtime.c \
+ localtime_r.c \
+ mk_gmtime.c \
+ mktime.c \
+ month_length.c \
+ moon_phase.c \
+ print_lz.c \
+ set_dst.c \
+ set_position.c \
+ set_system_time.c \
+ set_zone.c \
+ solar_declination.c \
+ solar_noon.c \
+ strftime.c \
+ sun_rise.c \
+ sun_set.c \
+ system_time.c \
+ time.c \
+ tm_store.c \
+ utc_offset.c \
+ week_of_month.c \
+ week_of_year.c
+
+time_a_asm_sources = \
+ system_tick.S
+
+time_a_extra_dist = \
+ ephemera_common.h
diff --git a/time/Makefile b/time/Makefile
new file mode 100644
index 0000000..ea8d363
--- /dev/null
+++ b/time/Makefile
@@ -0,0 +1,529 @@
+# Makefile.in generated by automake 1.14 from Makefile.am.
+# libc/time/Makefile. Generated from Makefile.in by configure.
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+
+# ©2012 Michael Duane Rice All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer. Redistributions in binary
+# form must reproduce the above copyright notice, this list of conditions
+# and the following disclaimer in the documentation and/or other materials
+# provided with the distribution. Neither the name of the copyright holders
+# nor the names of contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/avr-libc
+pkgincludedir = $(includedir)/avr-libc
+pkglibdir = $(libdir)/avr-libc
+pkglibexecdir = $(libexecdir)/avr-libc
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = x86_64-unknown-linux-gnu
+host_triplet = avr-unknown-none
+DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \
+ $(srcdir)/Makefile.am
+subdir = libc/time
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_$(V))
+am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY))
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
+am__v_at_1 =
+SOURCES =
+DIST_SOURCES =
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing aclocal-1.14
+AMTAR = $${TAR-tar}
+AM_DEFAULT_VERBOSITY = 1
+AR = avr-ar
+AS = avr-as
+ASDEBUG =
+AUTOCONF = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoconf
+AUTOHEADER = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoheader
+AUTOMAKE = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing automake-1.14
+AVR_LIBC_MAJOR = 1
+AVR_LIBC_MINOR = 8
+AVR_LIBC_RELDATE = 20140811
+AVR_LIBC_REVISION = 1
+AVR_LIBC_USER_MANUAL = avr-libc-user-manual-1.8.1
+AVR_LIBC_VERSION = 1.8.1
+AVR_LIBC_VERSION_NUMERIC = 10801
+AWK = gawk
+CC = avr-gcc
+CCAS = avr-gcc
+CCASDEPMODE = depmode=gcc3
+CCASFLAGS =
+CCDEPMODE = depmode=gcc3
+CDEBUG =
+CFLAGS =
+CPPFLAGS =
+CYGPATH_W = echo
+DEFS = -DHAVE_CONFIG_H
+DEPDIR = .deps
+DOCSDIR =
+DOC_INST_DIR = ${DESTDIR}${datadir}/doc/avr-libc-$(VERSION)
+ECHO_C =
+ECHO_N = -n
+ECHO_T =
+EXEEXT =
+FNO_JUMP_TABLES = -fno-jump-tables
+HAS_DELAY_CYCLES = 1
+INSTALL = /usr/bin/install -c
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALL_DOX_HTML = install-dox-html
+INSTALL_DOX_MAN = install-dox-man
+INSTALL_DOX_PDF = install-dox-pdf
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
+LDFLAGS =
+LIBOBJS =
+LIBS =
+LN_S = ln -s
+LTLIBOBJS =
+MAKEINFO = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing makeinfo
+MKDIR_P = /bin/mkdir -p
+OBJEXT = o
+PACKAGE = avr-libc
+PACKAGE_BUGREPORT = avr-libc-dev@nongnu.org
+PACKAGE_NAME = avr-libc
+PACKAGE_STRING = avr-libc 1.8.1
+PACKAGE_TARNAME = avr-libc
+PACKAGE_URL =
+PACKAGE_VERSION = 1.8.1
+PATH_SEPARATOR = :
+PNGTOPNM = pngtopnm
+PNMTOPNG = pnmtopng
+RANLIB = avr-ranlib
+SET_MAKE =
+SHELL = /bin/bash
+STRIP = avr-strip
+TARGET_DOX_HTML = dox-html
+TARGET_DOX_PDF = dox-pdf
+VERSION = 1.8.1
+abs_builddir = /home/leo/src/avr/avr-libc-1.8.1/libc/time
+abs_srcdir = /home/leo/src/avr/avr-libc-1.8.1/libc/time
+abs_top_builddir = /home/leo/src/avr/avr-libc-1.8.1
+abs_top_srcdir = /home/leo/src/avr/avr-libc-1.8.1
+ac_ct_CC =
+am__include = include
+am__leading_dot = .
+am__quote =
+am__tar = $${TAR-tar} chof - "$$tardir"
+am__untar = $${TAR-tar} xf -
+bindir = ${exec_prefix}/bin
+build = x86_64-unknown-linux-gnu
+build_alias = x86_64-unknown-linux-gnu
+build_cpu = x86_64
+build_os = linux-gnu
+build_vendor = unknown
+builddir = .
+datadir = ${datarootdir}
+datarootdir = ${prefix}/share
+docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}
+dvidir = ${docdir}
+exec_prefix = ${prefix}
+host = avr-unknown-none
+host_alias = avr
+host_cpu = avr
+host_os = none
+host_vendor = unknown
+htmldir = ${docdir}
+includedir = ${prefix}/include
+infodir = ${datarootdir}/info
+install_sh = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/install-sh
+libdir = ${exec_prefix}/lib
+libexecdir = ${exec_prefix}/libexec
+localedir = ${datarootdir}/locale
+localstatedir = ${prefix}/var
+mandir = ${datarootdir}/man
+mkdir_p = $(MKDIR_P)
+oldincludedir = /usr/include
+pdfdir = ${docdir}
+prefix = /usr/local
+program_transform_name = s,x,x,
+psdir = ${docdir}
+sbindir = ${exec_prefix}/sbin
+sharedstatedir = ${prefix}/com
+srcdir = .
+sysconfdir = ${prefix}/etc
+target_alias =
+top_build_prefix = ../../
+top_builddir = ../..
+top_srcdir = ../..
+time_a_c_sources = \
+ asc_store.c \
+ asctime.c \
+ asctime_r.c \
+ ctime.c \
+ ctime_r.c \
+ daylight_seconds.c \
+ difftime.c \
+ dst_pointer.c \
+ equation_of_time.c \
+ fatfs_time.c \
+ geo_location.c \
+ gm_sidereal.c \
+ gmtime.c \
+ gmtime_r.c \
+ isLeap.c \
+ isotime.c \
+ iso_week_date.c \
+ iso_week_date_r.c \
+ isotime_r.c \
+ lm_sidereal.c \
+ localtime.c \
+ localtime_r.c \
+ mk_gmtime.c \
+ mktime.c \
+ month_length.c \
+ moon_phase.c \
+ print_lz.c \
+ set_dst.c \
+ set_position.c \
+ set_system_time.c \
+ set_zone.c \
+ solar_declination.c \
+ solar_noon.c \
+ strftime.c \
+ sun_rise.c \
+ sun_set.c \
+ system_time.c \
+ time.c \
+ tm_store.c \
+ utc_offset.c \
+ week_of_month.c \
+ week_of_year.c
+
+time_a_asm_sources = \
+ system_tick.S
+
+time_a_extra_dist = \
+ ephemera_common.h
+
+EXTRA_DIST = \
+ $(time_a_c_sources) \
+ $(time_a_asm_sources) \
+ $(time_a_extra_dist)
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign libc/time/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+$(top_srcdir)/libc/time/Files.am:
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+tags TAGS:
+
+ctags CTAGS:
+
+cscope cscopelist:
+
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
+ ctags-am distclean distclean-generic distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+ pdf-am ps ps-am tags-am uninstall uninstall-am
+
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/time/Makefile.am b/time/Makefile.am
new file mode 100644
index 0000000..c8a121f
--- /dev/null
+++ b/time/Makefile.am
@@ -0,0 +1,35 @@
+# ©2012 Michael Duane Rice All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer. Redistributions in binary
+# form must reproduce the above copyright notice, this list of conditions
+# and the following disclaimer in the documentation and/or other materials
+# provided with the distribution. Neither the name of the copyright holders
+# nor the names of contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+
+include $(top_srcdir)/libc/time/Files.am
+
+EXTRA_DIST = \
+ $(time_a_c_sources) \
+ $(time_a_asm_sources) \
+ $(time_a_extra_dist)
diff --git a/time/Makefile.in b/time/Makefile.in
new file mode 100644
index 0000000..868aa89
--- /dev/null
+++ b/time/Makefile.in
@@ -0,0 +1,529 @@
+# Makefile.in generated by automake 1.14 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# ©2012 Michael Duane Rice All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer. Redistributions in binary
+# form must reproduce the above copyright notice, this list of conditions
+# and the following disclaimer in the documentation and/or other materials
+# provided with the distribution. Neither the name of the copyright holders
+# nor the names of contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \
+ $(srcdir)/Makefile.am
+subdir = libc/time
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+SOURCES =
+DIST_SOURCES =
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AS = @AS@
+ASDEBUG = @ASDEBUG@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AVR_LIBC_MAJOR = @AVR_LIBC_MAJOR@
+AVR_LIBC_MINOR = @AVR_LIBC_MINOR@
+AVR_LIBC_RELDATE = @AVR_LIBC_RELDATE@
+AVR_LIBC_REVISION = @AVR_LIBC_REVISION@
+AVR_LIBC_USER_MANUAL = @AVR_LIBC_USER_MANUAL@
+AVR_LIBC_VERSION = @AVR_LIBC_VERSION@
+AVR_LIBC_VERSION_NUMERIC = @AVR_LIBC_VERSION_NUMERIC@
+AWK = @AWK@
+CC = @CC@
+CCAS = @CCAS@
+CCASDEPMODE = @CCASDEPMODE@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CDEBUG = @CDEBUG@
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOCSDIR = @DOCSDIR@
+DOC_INST_DIR = @DOC_INST_DIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EXEEXT = @EXEEXT@
+FNO_JUMP_TABLES = @FNO_JUMP_TABLES@
+HAS_DELAY_CYCLES = @HAS_DELAY_CYCLES@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_DOX_HTML = @INSTALL_DOX_HTML@
+INSTALL_DOX_MAN = @INSTALL_DOX_MAN@
+INSTALL_DOX_PDF = @INSTALL_DOX_PDF@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PNGTOPNM = @PNGTOPNM@
+PNMTOPNG = @PNMTOPNG@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+TARGET_DOX_HTML = @TARGET_DOX_HTML@
+TARGET_DOX_PDF = @TARGET_DOX_PDF@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+time_a_c_sources = \
+ asc_store.c \
+ asctime.c \
+ asctime_r.c \
+ ctime.c \
+ ctime_r.c \
+ daylight_seconds.c \
+ difftime.c \
+ dst_pointer.c \
+ equation_of_time.c \
+ fatfs_time.c \
+ geo_location.c \
+ gm_sidereal.c \
+ gmtime.c \
+ gmtime_r.c \
+ isLeap.c \
+ isotime.c \
+ iso_week_date.c \
+ iso_week_date_r.c \
+ isotime_r.c \
+ lm_sidereal.c \
+ localtime.c \
+ localtime_r.c \
+ mk_gmtime.c \
+ mktime.c \
+ month_length.c \
+ moon_phase.c \
+ print_lz.c \
+ set_dst.c \
+ set_position.c \
+ set_system_time.c \
+ set_zone.c \
+ solar_declination.c \
+ solar_noon.c \
+ strftime.c \
+ sun_rise.c \
+ sun_set.c \
+ system_time.c \
+ time.c \
+ tm_store.c \
+ utc_offset.c \
+ week_of_month.c \
+ week_of_year.c
+
+time_a_asm_sources = \
+ system_tick.S
+
+time_a_extra_dist = \
+ ephemera_common.h
+
+EXTRA_DIST = \
+ $(time_a_c_sources) \
+ $(time_a_asm_sources) \
+ $(time_a_extra_dist)
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign libc/time/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+$(top_srcdir)/libc/time/Files.am:
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+tags TAGS:
+
+ctags CTAGS:
+
+cscope cscopelist:
+
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
+ ctags-am distclean distclean-generic distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+ pdf-am ps ps-am tags-am uninstall uninstall-am
+
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/time/Rules.am b/time/Rules.am
new file mode 100644
index 0000000..a2c0929
--- /dev/null
+++ b/time/Rules.am
@@ -0,0 +1,30 @@
+# ©2012 Michael Duane Rice All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer. Redistributions in binary
+# form must reproduce the above copyright notice, this list of conditions
+# and the following disclaimer in the documentation and/or other materials
+# provided with the distribution. Neither the name of the copyright holders
+# nor the names of contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# $Id: Rules.am 2321 2013-04-02 00:12:48Z swfltek $
+
+include $(top_srcdir)/libc/time/Files.am
diff --git a/time/asc_store.c b/time/asc_store.c
new file mode 100644
index 0000000..1839ec6
--- /dev/null
+++ b/time/asc_store.c
@@ -0,0 +1,39 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asc_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+/*
+ Private allocation, shared between asctime() and isotime()
+*/
+
+#include <time.h>
+
+char __store[26];
+
+char *__asc_store = __store;
diff --git a/time/asctime.c b/time/asctime.c
new file mode 100644
index 0000000..38c6ea9
--- /dev/null
+++ b/time/asctime.c
@@ -0,0 +1,44 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asctime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard asctime(), we simply punt to the re-entrant version.
+*/
+
+#include <time.h>
+
+extern char *__asc_store;
+
+char *
+asctime(const struct tm * timeptr)
+{
+ asctime_r(timeptr, __asc_store);
+ return __asc_store;
+}
diff --git a/time/asctime_r.c b/time/asctime_r.c
new file mode 100644
index 0000000..f85336d
--- /dev/null
+++ b/time/asctime_r.c
@@ -0,0 +1,82 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asctime_r.c 2357 2013-04-21 16:25:30Z swfltek $ */
+
+/*
+ Re-entrant version of asctime().
+
+*/
+#include <time.h>
+#include <stdlib.h>
+
+#ifdef __MEMX
+const __memx char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const __memx char ascdays[] = "SunMonTueWedThuFriSat";
+#else
+const char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const char ascdays[] = "SunMonTueWedThuFriSat";
+#endif
+
+extern void __print_lz(int , char *, char );
+
+void
+asctime_r(const struct tm * timeptr, char *buffer)
+{
+ unsigned char i, m, d;
+ div_t result;
+
+ d = timeptr->tm_wday * 3;
+ m = timeptr->tm_mon * 3;
+ for (i = 0; i < 3; i++) {
+ buffer[i] = ascdays[d++];
+ buffer[i+4] = ascmonths[m++];
+ }
+ buffer[3]=buffer[7]=' ';
+ buffer += 8;
+
+ __print_lz(timeptr->tm_mday,buffer,' ');
+ buffer += 3;
+
+ __print_lz(timeptr->tm_hour,buffer,':');
+ buffer += 3;
+
+ __print_lz(timeptr->tm_min,buffer,':');
+ buffer += 3;
+
+ __print_lz(timeptr->tm_sec,buffer,' ');
+ buffer += 3;
+
+ result = div(timeptr->tm_year + 1900 , 100);
+
+ __print_lz(result.quot,buffer,' ');
+ buffer += 2;
+
+ __print_lz(result.rem,buffer,0);
+
+}
diff --git a/time/ctime.c b/time/ctime.c
new file mode 100644
index 0000000..f17b873
--- /dev/null
+++ b/time/ctime.c
@@ -0,0 +1,47 @@
+/*
+ * ©2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: ctime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard ctime(). We have to break down the time stamp, print it into our
+ private buffer, and return the buffer.
+*/
+#include <time.h>
+
+extern char *__asc_store;
+
+char *
+ctime(const time_t * timeptr)
+{
+ struct tm calendar;
+
+ localtime_r(timeptr, &calendar);
+ asctime_r(&calendar, __asc_store);
+ return __asc_store;
+}
diff --git a/time/ctime_r.c b/time/ctime_r.c
new file mode 100644
index 0000000..4bb3633
--- /dev/null
+++ b/time/ctime_r.c
@@ -0,0 +1,43 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: ctime_r.c 2315 2013-03-29 21:24:31Z joerg_wunsch $ */
+
+/*
+ Re entrant version of ctime()
+*/
+#include <time.h>
+
+void
+ctime_r(const time_t * timeptr, char *buffer)
+{
+ struct tm calendar;
+
+ localtime_r(timeptr, &calendar);
+ asctime_r(&calendar, buffer);
+}
diff --git a/time/daylight_seconds.c b/time/daylight_seconds.c
new file mode 100644
index 0000000..97df585
--- /dev/null
+++ b/time/daylight_seconds.c
@@ -0,0 +1,72 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: daylight_seconds.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+ Determine the amount of time the sun is above the horizon. At high latitudes, around the
+ solstices, this can be zero or greater than ONE_DAY.
+
+*/
+
+#include <time.h>
+#include <math.h>
+
+extern long __latitude;
+
+long
+daylight_seconds(const time_t * timer)
+{
+ double l, d;
+ long n;
+
+ /* convert latitude to radians */
+ l = __latitude / 206264.806;
+
+ d = -solar_declination(timer);
+
+ /* partial 'Sunrise Equation' */
+ d = tan(l) * tan(d);
+
+ /* magnitude of d may exceed 1.0 at near solstices */
+ if (d > 1.0)
+ d = 1.0;
+
+ if (d < -1.0)
+ d = -1.0;
+
+ /* derive hour angle */
+ d = acos(d);
+
+ /* but for atmospheric refraction, this would be d /= M_PI */
+ d /= 3.112505;
+
+ n = ONE_DAY * d;
+
+ return n;
+}
diff --git a/time/difftime.c b/time/difftime.c
new file mode 100644
index 0000000..95b24e9
--- /dev/null
+++ b/time/difftime.c
@@ -0,0 +1,41 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: difftime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ The C90 standard specifies this returns a 'double. Since we do not have a true double,
+ we return a work alike type.
+*/
+#include <time.h>
+
+int32_t
+difftime(time_t t1, time_t t2)
+{
+ return t1 - t2;
+}
diff --git a/time/dst_pointer.c b/time/dst_pointer.c
new file mode 100644
index 0000000..5eda185
--- /dev/null
+++ b/time/dst_pointer.c
@@ -0,0 +1,34 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: dst_pointer.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+#include <inttypes.h>
+#include <time.h>
+
+int (*__dst_ptr) (const time_t *, int32_t *);
diff --git a/time/ephemera_common.h b/time/ephemera_common.h
new file mode 100644
index 0000000..9583f89
--- /dev/null
+++ b/time/ephemera_common.h
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: ephemera_common.h 2345 2013-04-11 23:58:48Z swfltek $ */
+
+#ifndef EPHEMERA_PRIVATE_H
+#define EPHEMERA_PRIVATE_H
+
+#define TROP_YEAR 31556925
+#define ANOM_YEAR 31558433
+#define INCLINATION 0.409105176667471 /* Earths axial tilt at the epoch */
+#define PERIHELION 31316400 /* perihelion of 1999, 03 jan 13:00 UTC */
+#define SOLSTICE 836160 /* winter solstice of 1999, 22 Dec 07:44 UTC */
+#define TWO_PI 6.283185307179586
+#define TROP_CYCLE 5022440.6025
+#define ANOM_CYCLE 5022680.6082
+#define DELTA_V 0.03342044 /* 2x orbital eccentricity */
+
+#endif
diff --git a/time/equation_of_time.c b/time/equation_of_time.c
new file mode 100644
index 0000000..a527c83
--- /dev/null
+++ b/time/equation_of_time.c
@@ -0,0 +1,86 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: equation_of_time.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+ The so called Equation of Time.
+
+ The eccentricity of Earths orbit contributes about 7.7 minutes of variation to the result. It
+ has a period of 1 anomalous year, with zeroes at perihelion and aphelion.
+
+ The tilt of Earths rotational axis (obliquity) contributes about 9.9 minutes of variation. It
+ has a period of 1/2 tropical year, with zeroes at solstices and equinoxes. The time of Earths
+ arrival at these events is influenced by the eccentricity, which causes it to progress along its
+ orbital path faster as it approaches perihelion, imposing a 'modulation' on the tropical phase.
+
+ The algorithm employed computes the orbital position with respect to perihelion, deriving
+ from that a 'velocity correction factor'. The orbital position with respect to the winter solstice
+ is then computed, as modulated by that factor. The individual contributions of the obliquity and the
+ eccentricity components are then summed, and returned as an integer value in seconds.
+
+*/
+
+#include <time.h>
+#include <math.h>
+#include "ephemera_common.h"
+
+int
+equation_of_time(const time_t * timer)
+{
+ int32_t s, p;
+ double pf, sf, dV;
+
+ /* compute orbital position relative to perihelion */
+ p = *timer % ANOM_YEAR;
+ p += PERIHELION;
+ pf = p;
+ pf /= ANOM_CYCLE;
+ pf = sin(pf);
+
+ /* Derive a velocity correction factor from the perihelion angle */
+ dV = pf * DELTA_V;
+
+ /* compute approximate position relative to solstice */
+ s = *timer % TROP_YEAR;
+ s += SOLSTICE;
+ s *= 2;
+ sf = s;
+ sf /= TROP_CYCLE;
+
+ /* modulate to derive actual position */
+ sf += dV;
+ sf = sin(sf);
+
+ /* compute contributions */
+ sf *= 592.2;
+ pf *= 459.6;
+ s = pf + sf;
+ return -s;
+
+}
diff --git a/time/fatfs_time.c b/time/fatfs_time.c
new file mode 100644
index 0000000..e38decb
--- /dev/null
+++ b/time/fatfs_time.c
@@ -0,0 +1,66 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: fatfs_time.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Return a value suitable for use as a file system time stamp.
+*/
+
+#include <time.h>
+
+uint32_t
+fatfs_time(const struct tm * timeptr)
+{
+ uint32_t ret;
+ uint32_t n;
+
+ n = timeptr->tm_year - 80;
+ n <<= 25;
+ ret = n;
+
+ n = timeptr->tm_mon + 1;
+ n <<= 21;
+ ret |= n;
+
+ n = timeptr->tm_mday;
+ n <<= 16;
+ ret |= n;
+
+ n = timeptr->tm_hour;
+ n <<= 11;
+ ret |= n;
+
+ n = timeptr->tm_min;
+ n <<= 5;
+ ret |= n;
+
+ ret |= (timeptr->tm_sec / 2);
+
+ return ret;
+}
diff --git a/time/geo_location.c b/time/geo_location.c
new file mode 100644
index 0000000..84bd7a8
--- /dev/null
+++ b/time/geo_location.c
@@ -0,0 +1,32 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: geo_location.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+long __latitude;
+long __longitude;
diff --git a/time/gm_sidereal.c b/time/gm_sidereal.c
new file mode 100644
index 0000000..b0984aa
--- /dev/null
+++ b/time/gm_sidereal.c
@@ -0,0 +1,60 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gm_sidereal.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+ Greenwich Mean Sidereal Time. A sidereal second is somewhat shorter than a standard second,
+ about 1.002737909350795 sidereal seconds per standard second.
+
+ We resort to fixed point math due to the insufficient resolution of a 'double', using...
+
+ timestamp * ( 1.002737909350795 << 31 )
+ --------------------------------------- + Te
+ 1 << 31
+
+ Where Te is the sidereal time at the epoch.
+
+*/
+
+#include <time.h>
+#include <stdint.h>
+
+unsigned long
+gm_sidereal(const time_t * timer)
+{
+ uint64_t tmp;
+
+ tmp = *timer;
+ tmp *= 0x8059B740;
+ tmp /= 0x80000000;
+ tmp += (uint64_t) 23991;
+
+ tmp %= ONE_DAY;
+ return tmp;
+}
diff --git a/time/gmtime.c b/time/gmtime.c
new file mode 100644
index 0000000..f3d0b2e
--- /dev/null
+++ b/time/gmtime.c
@@ -0,0 +1,45 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gmtime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard gmtime(). We convert binary time into calendar time in our private struct tm object,
+ returning that object.
+*/
+
+#include <time.h>
+
+extern struct tm __tm_store;
+
+struct tm *
+gmtime(const time_t * timeptr)
+{
+ gmtime_r(timeptr, &__tm_store);
+ return &__tm_store;
+}
diff --git a/time/gmtime_r.c b/time/gmtime_r.c
new file mode 100644
index 0000000..22658ea
--- /dev/null
+++ b/time/gmtime_r.c
@@ -0,0 +1,144 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gmtime_r.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/* Re entrant version of gmtime(). */
+
+#include <time.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+void
+gmtime_r(const time_t * timer, struct tm * timeptr)
+{
+ int32_t fract;
+ ldiv_t lresult;
+ div_t result;
+ uint16_t days, n, leapyear, years;
+
+ /* break down timer into whole and fractional parts of 1 day */
+ days = *timer / 86400UL;
+ fract = *timer % 86400UL;
+
+ /*
+ Extract hour, minute, and second from the fractional day
+ */
+ lresult = ldiv(fract, 60L);
+ timeptr->tm_sec = lresult.rem;
+ result = div(lresult.quot, 60);
+ timeptr->tm_min = result.rem;
+ timeptr->tm_hour = result.quot;
+
+ /* Determine day of week ( the epoch was a Saturday ) */
+ n = days + SATURDAY;
+ n %= 7;
+ timeptr->tm_wday = n;
+
+ /*
+ * Our epoch year has the property of being at the conjunction of all three 'leap cycles',
+ * 4, 100, and 400 years ( though we can ignore the 400 year cycle in this library).
+ *
+ * Using this property, we can easily 'map' the time stamp into the leap cycles, quickly
+ * deriving the year and day of year, along with the fact of whether it is a leap year.
+ */
+
+ /* map into a 100 year cycle */
+ lresult = ldiv((long) days, 36525L);
+ years = 100 * lresult.quot;
+
+ /* map into a 4 year cycle */
+ lresult = ldiv(lresult.rem, 1461L);
+ years += 4 * lresult.quot;
+ days = lresult.rem;
+ if (years > 100)
+ days++;
+
+ /*
+ * 'years' is now at the first year of a 4 year leap cycle, which will always be a leap year,
+ * unless it is 100. 'days' is now an index into that cycle.
+ */
+ leapyear = 1;
+ if (years == 100)
+ leapyear = 0;
+
+ /* compute length, in days, of first year of this cycle */
+ n = 364 + leapyear;
+
+ /*
+ * if the number of days remaining is greater than the length of the
+ * first year, we make one more division.
+ */
+ if (days > n) {
+ days -= leapyear;
+ leapyear = 0;
+ result = div(days, 365);
+ years += result.quot;
+ days = result.rem;
+ }
+ timeptr->tm_year = 100 + years;
+ timeptr->tm_yday = days;
+
+ /*
+ Given the year, day of year, and leap year indicator, we can break down the
+ month and day of month. If the day of year is less than 59 (or 60 if a leap year), then
+ we handle the Jan/Feb month pair as an exception.
+ */
+ n = 59 + leapyear;
+ if (days < n) {
+ /* special case: Jan/Feb month pair */
+ result = div(days, 31);
+ timeptr->tm_mon = result.quot;
+ timeptr->tm_mday = result.rem;
+ } else {
+ /*
+ The remaining 10 months form a regular pattern of 31 day months alternating with 30 day
+ months, with a 'phase change' between July and August (153 days after March 1).
+ We proceed by mapping our position into either March-July or August-December.
+ */
+ days -= n;
+ result = div(days, 153);
+ timeptr->tm_mon = 2 + result.quot * 5;
+
+ /* map into a 61 day pair of months */
+ result = div(result.rem, 61);
+ timeptr->tm_mon += result.quot * 2;
+
+ /* map into a month */
+ result = div(result.rem, 31);
+ timeptr->tm_mon += result.quot;
+ timeptr->tm_mday = result.rem;
+ }
+
+ /*
+ Cleanup and return
+ */
+ timeptr->tm_isdst = 0; /* gmt is never in DST */
+ timeptr->tm_mday++; /* tm_mday is 1 based */
+
+}
diff --git a/time/isLeap.c b/time/isLeap.c
new file mode 100644
index 0000000..3c846aa
--- /dev/null
+++ b/time/isLeap.c
@@ -0,0 +1,56 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isLeap.c 2325 2013-04-02 21:22:16Z swfltek $ */
+
+/*
+ Return 1 if 'year' is a leap year, else 0.
+*/
+
+#include <stdlib.h>
+
+unsigned char
+is_leap_year(int year)
+{
+ div_t d;
+
+ /* year must be divisible by 4 to be a leap year */
+ if (year & 3)
+ return 0;
+
+ /* If theres a remainder after division by 100, year is not divisible by 100 or 400 */
+ d = div(year, 100);
+ if (d.rem)
+ return 1;
+
+ /* If the quotient is divisible by 4, then year is divisible by 400 */
+ if ((d.quot & 3) == 0)
+ return 1;
+
+ return 0;
+}
diff --git a/time/iso_week_date.c b/time/iso_week_date.c
new file mode 100644
index 0000000..efbf841
--- /dev/null
+++ b/time/iso_week_date.c
@@ -0,0 +1,51 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: iso_week_date.c 2394 2013-05-04 10:26:24Z swfltek $ */
+
+/*
+ Compute the ISO 8601 week date corresponding to the given year and day of year.
+ See http://en.wikipedia.org/wiki/ISO_week_date for a full description.
+
+ See iso_week_date_r.c for implementation details.
+
+*/
+
+#include <time.h>
+
+extern char *__asc_store;
+
+struct week_date *
+iso_week_date(int y, int yday)
+{
+ struct week_date *iso;
+
+ iso = (struct week_date *) __asc_store;
+ iso_week_date_r(y, yday, iso);
+ return iso;
+}
diff --git a/time/iso_week_date_r.c b/time/iso_week_date_r.c
new file mode 100644
index 0000000..ac1feb4
--- /dev/null
+++ b/time/iso_week_date_r.c
@@ -0,0 +1,114 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: iso_week_date_r.c 2394 2013-05-04 10:26:24Z swfltek $ */
+
+/*
+ Compute the ISO 8601 week date corresponding to the given year and day of year.
+ See http://en.wikipedia.org/wiki/ISO_week_date for a full description. To summarize:
+
+ Weeks are numbered from 1 to 53.
+ Week days are numbered 1 to 7, beginning with Monday as day 1.
+
+ The first week of the year contains the first Thursday in that year.
+ Dates prior to week 1 belong to the final week of the previous year.
+
+ The final week of the year contains the last Thursday in that year.
+ Dates after the final week belong to week 1 of the following year.
+
+*/
+
+#include <time.h>
+
+void
+iso_week_date_r(int y, int yday, struct week_date * iso)
+{
+ uint16_t years, n, wday;
+ int weeknum;
+ int isLeap;
+
+ iso->year = y;
+
+ isLeap = is_leap_year(y);
+
+ /* compute days elapsed since epoch */
+ years = y - 2000;
+ n = 365 * years + yday;
+ if (years) {
+ n++; /* epoch was a leap year */
+ n += years / 4;
+ n -= isLeap;
+ if (years > 100)
+ n--;
+ }
+
+ /* compute ISO8601 day of week (1 ... 7, Monday = 1) */
+ wday = n + 6; /* epoch was a Saturday */
+ wday %= 7;
+ if (wday == 0)
+ wday = 7;
+
+ iso->day = wday;
+
+ /* compute tentative week number */
+ weeknum = yday + 11 - wday;
+ weeknum /= 7;
+
+ /* if 53, it could be week 1 of the following year */
+ if (weeknum == 53) {
+ /*
+ The final week must include its Thursday in the year. We determine the yday of this
+ weeks Thursday, and test whether it exceeds this years length.
+ */
+
+ /* determine final yday of this year, 364 or 365 */
+ n = 364 + isLeap;
+
+ /* compute yday of this weeks Thursday */
+ wday--; /* convert to zero based week, Monday = 0 */
+ yday -= wday; /* yday of this weeks Monday */
+ yday += 3; /* yday of this weeks Thursday */
+
+ /* Is this weeks Thursday included in the year? */
+ if (yday > (int) n) {
+ iso->year++;
+ weeknum = 1;
+ }
+ }
+ iso->week = weeknum;
+
+ /*
+ If zero, it is the final week of the previous year.
+ We determine that by asking for the week number of Dec 31.
+ */
+ if (weeknum == 0) {
+ y = y - 1;
+ iso_week_date_r(y, 364 + is_leap_year(y), iso);
+ iso->day = wday;
+ }
+}
diff --git a/time/isotime.c b/time/isotime.c
new file mode 100644
index 0000000..a257815
--- /dev/null
+++ b/time/isotime.c
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isotime.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ This function returns ISO8601 formatted time, in our private buffer.
+*/
+
+#include <time.h>
+
+extern char *__asc_store;
+
+char *
+isotime(const struct tm * tmptr)
+{
+ isotime_r(tmptr, __asc_store);
+ return __asc_store;
+}
diff --git a/time/isotime_r.c b/time/isotime_r.c
new file mode 100644
index 0000000..5636a7f
--- /dev/null
+++ b/time/isotime_r.c
@@ -0,0 +1,70 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isotime_r.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Re entrant version of isotime(), which prints the date and time in ISO 8601 format.
+*/
+
+#include <stdlib.h>
+#include <time.h>
+
+extern void __print_lz(int , char *, char );
+
+void
+isotime_r(const struct tm * tmptr, char *buffer)
+{
+ int i;
+
+ i = tmptr->tm_year + 1900;
+ __print_lz(i/100, buffer, '-');
+ buffer+=2;
+ __print_lz(i%100, buffer,'-');
+ buffer+=3;
+
+ i = tmptr->tm_mon + 1;
+ __print_lz(i, buffer,'-');
+ buffer+=3;
+
+ i = tmptr->tm_mday;
+ __print_lz(i, buffer,' ');
+ buffer+=3;
+
+ i = tmptr->tm_hour;
+ __print_lz(i, buffer,':');
+ buffer+=3;
+
+ i = tmptr->tm_min;
+ __print_lz(i, buffer,':');
+ buffer+=3;
+
+ i = tmptr->tm_sec;
+ __print_lz(i, buffer,0);
+
+}
diff --git a/time/lm_sidereal.c b/time/lm_sidereal.c
new file mode 100644
index 0000000..ad34fac
--- /dev/null
+++ b/time/lm_sidereal.c
@@ -0,0 +1,47 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: lm_sidereal.c 2326 2013-04-02 21:23:41Z swfltek $ */
+
+/*
+ Local Mean Sidereal Time. See gm_sidereal() for info.
+*/
+#include <time.h>
+
+extern long __longitude;
+
+unsigned long
+lm_sidereal(const time_t * timer)
+{
+ long n;
+
+ n = gm_sidereal(timer) + __longitude / 15L;
+ n += ONE_DAY;
+ n %= ONE_DAY;
+ return n;
+}
diff --git a/time/localtime.c b/time/localtime.c
new file mode 100644
index 0000000..0e18967
--- /dev/null
+++ b/time/localtime.c
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: localtime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard localtime() function.
+*/
+
+#include <time.h>
+
+extern struct tm __tm_store;
+
+struct tm *
+localtime(const time_t * timer)
+{
+ localtime_r(timer, &__tm_store);
+ return &__tm_store;
+}
diff --git a/time/localtime_r.c b/time/localtime_r.c
new file mode 100644
index 0000000..0bd1a02
--- /dev/null
+++ b/time/localtime_r.c
@@ -0,0 +1,60 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: localtime_r.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Re entrant version of localtime(). Given a binary UTC time stamp, add the time
+ zone and Daylight savings offset, then break it down into calendar time.
+*/
+
+#include <time.h>
+
+extern long __utc_offset;
+
+extern int (*__dst_ptr) (const time_t *, int32_t *);
+
+void
+localtime_r(const time_t * timer, struct tm * timeptr)
+{
+ time_t lt;
+ int16_t dst;
+
+ dst = -1;
+
+ if (__dst_ptr)
+ dst = __dst_ptr(timer, &__utc_offset);
+
+ lt = *timer + __utc_offset;
+
+ if (dst > 0)
+ lt += dst;
+
+ gmtime_r(&lt, timeptr);
+ timeptr->tm_isdst = dst;
+}
diff --git a/time/mk_gmtime.c b/time/mk_gmtime.c
new file mode 100644
index 0000000..7f2b9b9
--- /dev/null
+++ b/time/mk_gmtime.c
@@ -0,0 +1,113 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: mk_gmtime.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+ 'Break down' a y2k time stamp into the elements of struct tm.
+ Unlike mktime(), this function does not 'normalize' the elements of timeptr.
+
+*/
+
+#include <time.h>
+
+time_t
+mk_gmtime(const struct tm * timeptr)
+{
+
+ time_t ret;
+ uint32_t tmp;
+ int n, m, d, leaps;
+
+ /*
+ Determine elapsed whole days since the epoch to the beginning of this year. Since our epoch is
+ at a conjunction of the leap cycles, we can do this rather quickly.
+ */
+ n = timeptr->tm_year - 100;
+ leaps = 0;
+ if (n) {
+ m = n - 1;
+ leaps = m / 4;
+ leaps -= m / 100;
+ leaps++;
+ }
+ tmp = 365UL * n + leaps;
+
+ /*
+ Derive the day of year from month and day of month. We use the pattern of 31 day months
+ followed by 30 day months to our advantage, but we must 'special case' Jan/Feb, and
+ account for a 'phase change' between July and August (153 days after March 1).
+ */
+ d = timeptr->tm_mday - 1; /* tm_mday is one based */
+
+ /* handle Jan/Feb as a special case */
+ if (timeptr->tm_mon < 2) {
+ if (timeptr->tm_mon)
+ d += 31;
+
+ } else {
+ n = 59 + is_leap_year(timeptr->tm_year + 1900);
+ d += n;
+ n = timeptr->tm_mon - MARCH;
+
+ /* account for phase change */
+ if (n > (JULY - MARCH))
+ d += 153;
+ n %= 5;
+
+ /*
+ * n is now an index into a group of alternating 31 and 30
+ * day months... 61 day pairs.
+ */
+ m = n / 2;
+ m *= 61;
+ d += m;
+
+ /*
+ * if n is odd, we are in the second half of the
+ * month pair
+ */
+ if (n & 1)
+ d += 31;
+ }
+
+ /* Add day of year to elapsed days, and convert to seconds */
+ tmp += d;
+ tmp *= ONE_DAY;
+ ret = tmp;
+
+ /* compute 'fractional' day */
+ tmp = timeptr->tm_hour;
+ tmp *= ONE_HOUR;
+ tmp += timeptr->tm_min * 60UL;
+ tmp += timeptr->tm_sec;
+
+ ret += tmp;
+
+ return ret;
+}
diff --git a/time/mktime.c b/time/mktime.c
new file mode 100644
index 0000000..1600202
--- /dev/null
+++ b/time/mktime.c
@@ -0,0 +1,61 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: mktime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard mktime(). The provided broken down Local 'calendar' time is converted into
+ a binary time stamp. The process is then reversed to 'normalize' timeptr.
+*/
+
+#include <time.h>
+
+extern long __utc_offset;
+
+extern int (*__dst_ptr) (const time_t *, int32_t *);
+
+time_t
+mktime(struct tm * timeptr)
+{
+ time_t ret;
+
+ ret = mk_gmtime(timeptr);
+
+ if (timeptr->tm_isdst < 0) {
+ if (__dst_ptr)
+ timeptr->tm_isdst = __dst_ptr(&ret, &__utc_offset);
+ }
+ if (timeptr->tm_isdst > 0)
+ ret -= timeptr->tm_isdst;
+
+ ret -= __utc_offset;
+
+ localtime_r(&ret, timeptr);
+
+ return ret;
+}
diff --git a/time/month_length.c b/time/month_length.c
new file mode 100644
index 0000000..0f2f091
--- /dev/null
+++ b/time/month_length.c
@@ -0,0 +1,48 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: month_length.c 2358 2013-04-23 22:30:20Z swfltek $ */
+
+/*
+ Return the length of a month in days, given the year and month in question.
+ The month parameter must be '1 based', ranging from 1 to 12.
+*/
+
+#include <time.h>
+
+uint8_t
+month_length(int year, uint8_t month)
+{
+ if (month == 2)
+ return 28 + is_leap_year(year);
+
+ /* 'knuckles' algorithm */
+ if (month > 7)
+ month++;
+ return 30 + (month & 1);
+}
diff --git a/time/moon_phase.c b/time/moon_phase.c
new file mode 100644
index 0000000..5fb5826
--- /dev/null
+++ b/time/moon_phase.c
@@ -0,0 +1,65 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: moon_phase.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Return an approximation to the phase of the moon. Since no attempt is made to account for
+ Sol, Jupiter or Venus, it will often be off by several hours.
+*/
+
+#include <time.h>
+#include <math.h>
+
+int8_t
+moon_phase(const time_t * timestamp)
+{
+ uint32_t t;
+ int32_t n;
+ double mc;
+
+ /* refer to first new moon of the epoch */
+ t = *timestamp - 1744800UL;
+
+ /* constrain to 1 lunar cycle */
+ n = t % 2551443UL;
+
+ /* offset by 1/2 lunar cycle */
+ n -= 1275721L;
+ mc = n;
+ mc /= 1275721.0;
+ mc *= M_PI;
+ mc = cos(mc) * sin(mc);
+ mc *= 12.5;
+
+ /* scale to range - 100...+ 100 */
+ n /= 12757L;
+ n -= mc;
+
+ return n;
+}
diff --git a/time/print_lz.c b/time/print_lz.c
new file mode 100644
index 0000000..95c81bd
--- /dev/null
+++ b/time/print_lz.c
@@ -0,0 +1,45 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: print_lz.c 2357 2013-04-21 16:25:30Z swfltek $ */
+
+/* print 2 digit integer with leading zero: auxillary function for isotime and asctime */
+
+#include <stdlib.h>
+
+void
+__print_lz(int i, char *buffer, char s)
+{
+ div_t result;
+
+ result = div(i, 10);
+
+ *buffer++ = result.quot + '0';
+ *buffer++ = result.rem + '0';
+ *buffer = s;
+}
diff --git a/time/set_dst.c b/time/set_dst.c
new file mode 100644
index 0000000..9ba0964
--- /dev/null
+++ b/time/set_dst.c
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_dst.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Set the dst function pointer.
+*/
+
+#include <inttypes.h>
+#include <time.h>
+
+extern int (*__dst_ptr) (const time_t *, int32_t *);
+
+void
+set_dst(int (*d) (const time_t *, int32_t *))
+{
+ __dst_ptr = d;
+}
diff --git a/time/set_position.c b/time/set_position.c
new file mode 100644
index 0000000..e268316
--- /dev/null
+++ b/time/set_position.c
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_position.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Set the geographic position of the observer. Both parameters are in seconds, with
+ North latitude and East longitude being positive values.
+*/
+
+extern long __latitude;
+extern long __longitude;
+
+void
+set_position(long lat, long lon)
+{
+ __latitude = lat;
+ __longitude = lon;
+}
diff --git a/time/set_system_time.c b/time/set_system_time.c
new file mode 100644
index 0000000..334790e
--- /dev/null
+++ b/time/set_system_time.c
@@ -0,0 +1,55 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_system_time.c 2356 2013-04-21 16:20:01Z swfltek $ */
+
+/*
+ * Set the system time. The values passed are assumed to represent local
+ * standard time, such as would be obtained from the typical Real Time Clock
+ * integrated circuit. It is necessary for this to be atomic, as the value may be
+ * incremented at interrupt time.
+ */
+
+#include <time.h>
+extern volatile time_t __system_time;
+
+void
+set_system_time(time_t timestamp)
+{
+
+ asm volatile(
+ "in __tmp_reg__, __SREG__" "\n\t"
+ "cli" "\n\t"
+ ::
+ );
+ __system_time = timestamp;
+ asm volatile(
+ "out __SREG__, __tmp_reg__" "\n\t"
+ ::
+ );
+}
diff --git a/time/set_zone.c b/time/set_zone.c
new file mode 100644
index 0000000..eb0f11b
--- /dev/null
+++ b/time/set_zone.c
@@ -0,0 +1,41 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_zone.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Set the system time zone. The parameter is seconds offset from UTC.
+*/
+
+extern long __utc_offset;
+
+void
+set_zone(long z)
+{
+ __utc_offset = z;
+}
diff --git a/time/solar_declination.c b/time/solar_declination.c
new file mode 100644
index 0000000..dd89028
--- /dev/null
+++ b/time/solar_declination.c
@@ -0,0 +1,77 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: solar_declination.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+ Were it not for the eccentricity of Earths orbit, this would be a trivial function.
+
+ We compute the Earths orbital position with respect to perihelion, from which we derive a
+ 'velocity correction factor'. We then compute the orbital angle with respect to the
+ December solstice, as 'modulated' by that correction factor.
+
+ Due to the accumulation of rounding errors, the computed December solstice of 2135 will lag
+ the actual solstice by many hours. A fudge factor, 'LAG', distributes the error across
+ the 136 year range of this library.
+*/
+
+#include <time.h>
+#include <math.h>
+#include "ephemera_common.h"
+
+#define LAG 38520
+
+double
+solar_declination(const time_t * timer)
+{
+
+ uint32_t fT, oV;
+ double dV, dT;
+
+ /* Determine orbital angle relative to perihelion of January 1999 */
+ oV = *timer % ANOM_YEAR;
+ oV += PERIHELION;
+ dV = oV;
+ dV /= ANOM_CYCLE;
+
+ /* Derive velocity correction factor from the perihelion angle */
+ dV = sin(dV);
+ dV *= DELTA_V;
+
+ /* Determine orbital angle relative to solstice of December 1999 */
+ fT = *timer % TROP_YEAR;
+ fT += SOLSTICE + LAG;
+ dT = fT;
+ dT /= TROP_CYCLE;
+ dT += dV;
+
+ /* Finally having the solstice angle, we can compute the declination */
+ dT = cos(dT) * INCLINATION;
+
+ return -dT;
+}
diff --git a/time/solar_noon.c b/time/solar_noon.c
new file mode 100644
index 0000000..65bafcc
--- /dev/null
+++ b/time/solar_noon.c
@@ -0,0 +1,57 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: solar_noon.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Return the time of solar noon at the observers position
+*/
+
+#include <time.h>
+
+extern long __longitude;
+
+time_t
+solar_noon(const time_t * timer)
+{
+ time_t t;
+ long n;
+
+ /* determine time of solar noon at the prime meridian */
+ t = *timer % ONE_DAY;
+ t = *timer - t;
+ t += 43200L;
+ t -= equation_of_time(timer);
+
+ /* rotate to observers longitude */
+ n = __longitude / 15L;
+ t -= n;
+
+ return t;
+
+}
diff --git a/time/strftime.c b/time/strftime.c
new file mode 100644
index 0000000..4dcfd30
--- /dev/null
+++ b/time/strftime.c
@@ -0,0 +1,322 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: strftime.c 2391 2013-05-03 20:53:06Z swfltek $ */
+
+/*
+ Standard strftime(). This is a memory hungry monster.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+extern long __utc_offset;
+
+#ifdef __MEMX
+
+const __memx char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday ";
+const __memx char strfmonths[] = "January February March April May June July August September October November December ";
+
+#else
+
+const char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday ";
+const char strfmonths[] = "January February March April May June July August September October November December ";
+
+#endif
+
+#ifdef __MEMX
+
+unsigned char
+pgm_copystring(const char __memx * p, unsigned char i, char *b, unsigned char l)
+{
+
+#else
+
+unsigned char
+pgm_copystring(const char *p, unsigned char i, char *b, unsigned char l)
+{
+
+#endif
+
+ unsigned char ret, c;
+
+ ret = 0;
+ while (i) {
+ c = *p++;
+ if (c == ' ')
+ i--;
+ }
+
+ c = *p++;
+ while (c != ' ' && l--) {
+ *b++ = c;
+ ret++;
+ c = *p++;
+ }
+ *b = 0;
+ return ret;
+}
+
+size_t
+strftime(char *buffer, size_t limit, const char *pattern, const struct tm * timeptr)
+{
+ unsigned int count, length;
+ int d, w;
+ char c;
+ char _store[26];
+ struct week_date wd;
+
+ count = length = 0;
+ while (count < limit) {
+ c = *pattern++;
+ if (c == '%') {
+ c = *pattern++;
+ if (c == 'E' || c == 'O')
+ c = *pattern++;
+ switch (c) {
+ case ('%'):
+ _store[0] = c;
+ length = 1;
+ break;
+
+ case ('a'):
+ length = pgm_copystring(strfwkdays, timeptr->tm_wday, _store, 3);
+ break;
+
+ case ('A'):
+ length = pgm_copystring(strfwkdays, timeptr->tm_wday, _store, 255);
+ break;
+
+ case ('b'):
+ case ('h'):
+ length = pgm_copystring(strfmonths, timeptr->tm_mon, _store, 3);
+ break;
+
+ case ('B'):
+ length = pgm_copystring(strfmonths, timeptr->tm_mon, _store, 255);
+ break;
+
+ case ('c'):
+ asctime_r(timeptr, _store);
+ length = 0;
+ while (_store[length])
+ length++;
+ break;
+
+ case ('C'):
+ d = timeptr->tm_year + 1900;
+ d /= 100;
+ length = sprintf(_store, "%.2d", d);
+ break;
+
+ case ('d'):
+ length = sprintf(_store, "%.2u", timeptr->tm_mday);
+ break;
+
+ case ('D'):
+ length = sprintf(_store, "%.2u/%.2u/%.2u", \
+ timeptr->tm_mon + 1, \
+ timeptr->tm_mday, \
+ timeptr->tm_year % 100 \
+ );
+ break;
+
+ case ('e'):
+ length = sprintf(_store, "%2d", timeptr->tm_mday);
+ break;
+
+ case ('F'):
+ length = sprintf(_store, "%d-%.2d-%.2d", \
+ timeptr->tm_year + 1900, \
+ timeptr->tm_mon + 1, \
+ timeptr->tm_mday \
+ );
+ break;
+
+ case ('g'):
+ case ('G'):
+ iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd);
+ if (c == 'g') {
+ length = sprintf(_store, "%.2d", wd.year % 100);
+ } else {
+ length = sprintf(_store, "%.4d", wd.year);
+ }
+
+ break;
+
+ case ('H'):
+ length = sprintf(_store, "%.2u", timeptr->tm_hour);
+ break;
+
+ case ('I'):
+ d = timeptr->tm_hour % 12;
+ if (d == 0)
+ d = 12;
+ length = sprintf(_store, "%.2u", d);
+ break;
+
+ case ('j'):
+ length = sprintf(_store, "%.3u", timeptr->tm_yday + 1);
+ break;
+
+ case ('m'):
+ length = sprintf(_store, "%.2u", timeptr->tm_mon + 1);
+ break;
+
+ case ('M'):
+ length = sprintf(_store, "%.2u", timeptr->tm_min);
+ break;
+
+ case ('n'):
+ _store[0] = 10;
+ length = 1;
+ break;
+
+ case ('p'):
+ length = 2;
+ _store[0] = 'A';
+ if (timeptr->tm_hour > 11)
+ _store[0] = 'P';
+ _store[1] = 'M';
+ _store[2] = 0;
+ break;
+
+ case ('r'):
+ d = timeptr->tm_hour % 12;
+ if (d == 0)
+ d = 12;
+ length = sprintf(_store, "%2d:%.2d:%.2d AM", \
+ d, \
+ timeptr->tm_min, \
+ timeptr->tm_sec \
+ );
+ if (timeptr->tm_hour > 11)
+ _store[10] = 'P';
+ break;
+
+ case ('R'):
+ length = sprintf(_store, "%.2d:%.2d", timeptr->tm_hour, timeptr->tm_min);
+ break;
+
+ case ('S'):
+ length = sprintf(_store, "%.2u", timeptr->tm_sec);
+ break;
+
+ case ('t'):
+ length = sprintf(_store, "\t");
+ break;
+
+ case ('T'):
+ length = sprintf(_store, "%.2d:%.2d:%.2d", \
+ timeptr->tm_hour, \
+ timeptr->tm_min, \
+ timeptr->tm_sec \
+ );
+ break;
+
+ case ('u'):
+ w = timeptr->tm_wday;
+ if (w == 0)
+ w = 7;
+ length = sprintf(_store, "%d", w);
+ break;
+
+ case ('U'):
+ length = sprintf(_store, "%.2u", week_of_year(timeptr, 0));
+ break;
+
+ case ('V'):
+ iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd);
+ length = sprintf(_store, "%.2u", wd.week);
+ break;
+
+ case ('w'):
+ length = sprintf(_store, "%u", timeptr->tm_wday);
+ break;
+
+ case ('W'):
+ w = week_of_year(timeptr, 1);
+ length = sprintf(_store, "%.2u", w);
+ break;
+
+ case ('x'):
+ length = sprintf(_store, "%.2u/%.2u/%.2u", timeptr->tm_mon + 1, timeptr->tm_mday, timeptr->tm_year % 100);
+ break;
+
+ case ('X'):
+ length = sprintf(_store, "%.2u:%.2u:%.2u", timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
+ break;
+
+ case ('y'):
+ length = sprintf(_store, "%.2u", timeptr->tm_year % 100);
+ break;
+
+ case ('Y'):
+ length = sprintf(_store, "%u", timeptr->tm_year + 1900);
+ break;
+
+ case ('z'):
+ d = __utc_offset / 60;
+ w = timeptr->tm_isdst / 60;
+ if (w > 0)
+ d += w;
+ w = abs(d % 60);
+ d = d / 60;
+ length = sprintf(_store, "%+.2d%.2d", d, w);
+ break;
+
+ default:
+ length = 1;
+ _store[0] = '?';
+ _store[1] = 0;
+ break;
+ }
+
+ if ((length + count) < limit) {
+ count += length;
+ for (d = 0; d < (int) length; d++) {
+ *buffer++ = _store[d];
+ }
+ } else {
+ *buffer = 0;
+ return count;
+ }
+
+ } else { /* copy a literal */
+ *buffer = c;
+ buffer++;
+ count++;
+ if (c == 0)
+ return count;
+ }
+ }
+
+ *buffer = 0;
+ return count;
+}
diff --git a/time/sun_rise.c b/time/sun_rise.c
new file mode 100644
index 0000000..b2ff62c
--- /dev/null
+++ b/time/sun_rise.c
@@ -0,0 +1,49 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: sun_rise.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Return the approximate time of sun rise.
+*/
+
+#include <time.h>
+
+time_t
+sun_rise(const time_t * timer)
+{
+ long n;
+ time_t t;
+
+ /* sunrise is 1/2 'day' before solar noon */
+ t = solar_noon(timer);
+ n = daylight_seconds(timer) / 2L;
+ t -= n;
+
+ return t;
+}
diff --git a/time/sun_set.c b/time/sun_set.c
new file mode 100644
index 0000000..338e35f
--- /dev/null
+++ b/time/sun_set.c
@@ -0,0 +1,50 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: sun_set.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+ Return the approximate time of sun set.
+*/
+
+#include <time.h>
+
+time_t
+sun_set(const time_t * timer)
+{
+ long n;
+ time_t t;
+
+ /* sunset is 1/2 'day' after solar noon */
+ t = solar_noon(timer);
+ n = daylight_seconds(timer) / 2L;
+ t += n;
+
+ return t;
+
+}
diff --git a/time/system_tick.S b/time/system_tick.S
new file mode 100644
index 0000000..c1f90fd
--- /dev/null
+++ b/time/system_tick.S
@@ -0,0 +1,60 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: system_tick.S 2348 2013-04-16 23:42:05Z swfltek $ */
+
+/*
+ Impoved system_tick Credit to Wouter van Gulik.
+*/
+
+#include <avr/common.h>
+
+ .global system_tick
+ .type system_tick, @function
+system_tick:
+ push r24
+ in r24,_SFR_IO_ADDR(SREG)
+ push r24
+ cli
+ lds r24,__system_time+0
+ subi r24, (-1)
+ sts __system_time+0,r24
+ lds r24,__system_time+1
+ sbci r24, (-1)
+ sts __system_time+1,r24
+ lds r24,__system_time+2
+ sbci r24, (-1)
+ sts __system_time+2,r24
+ lds r24,__system_time+3
+ sbci r24, (-1)
+ sts __system_time+3,r24
+ pop r24
+ out _SFR_IO_ADDR(SREG),r24
+ pop r24
+ ret
+ .size system_tick, .-system_tick
diff --git a/time/system_time.c b/time/system_time.c
new file mode 100644
index 0000000..64bdac7
--- /dev/null
+++ b/time/system_time.c
@@ -0,0 +1,36 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: system_time.c 2321 2013-04-02 00:12:48Z swfltek $ */
+
+/*
+ The system time stamp.
+*/
+#include <time.h>
+
+volatile time_t __system_time;
diff --git a/time/time.c b/time/time.c
new file mode 100644
index 0000000..e794322
--- /dev/null
+++ b/time/time.c
@@ -0,0 +1,58 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: time.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+ Standard time() function. Copying from __system_time must be atomic, since it
+ may be incremented at interrupt time.
+*/
+#include <time.h>
+#include <inttypes.h>
+
+extern volatile time_t __system_time;
+
+time_t
+time(time_t * timer)
+{
+ time_t ret;
+
+ asm volatile(
+ "in __tmp_reg__, __SREG__" "\n\t"
+ "cli" "\n\t"
+ ::
+ );
+ ret = __system_time;
+ asm volatile(
+ "out __SREG__, __tmp_reg__" "\n\t"
+ ::
+ );
+ if (timer)
+ *timer = ret;
+ return ret;
+}
diff --git a/time/time.h b/time/time.h
new file mode 100644
index 0000000..21d86e9
--- /dev/null
+++ b/time/time.h
@@ -0,0 +1,523 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: time.h 2427 2014-05-01 14:06:03Z amylaar $ */
+
+/** \file */
+
+/** \defgroup avr_time <time.h>: Time
+ \code #include <time.h> \endcode
+ <h3>Introduction to the Time functions</h3>
+ This file declares the time functions implemented in \c avr-libc.
+
+ The implementation aspires to conform with ISO/IEC 9899 (C90). However, due to limitations of the
+ target processor and the nature of its development environment, a practical implementation must
+ of necessity deviate from the standard.
+
+
+
+ Section 7.23.2.1 clock()
+ The type clock_t, the macro CLOCKS_PER_SEC, and the function clock() are not implemented. We
+ consider these items belong to operating system code, or to application code when no operating
+ system is present.
+
+ Section 7.23.2.3 mktime()
+ The standard specifies that mktime() should return (time_t) -1, if the time cannot be represented.
+ This implementation always returns a 'best effort' representation.
+
+ Section 7.23.2.4 time()
+ The standard specifies that time() should return (time_t) -1, if the time is not available.
+ Since the application must initialize the time system, this functionality is not implemented.
+
+ Section 7.23.2.2, difftime()
+ Due to the lack of a 64 bit double, the function difftime() returns a long integer. In most cases
+ this change will be invisible to the user, handled automatically by the compiler.
+
+ Section 7.23.1.4 struct tm
+ Per the standard, struct tm->tm_isdst is greater than zero when Daylight Saving time is in effect.
+ This implementation further specifies that, when positive, the value of tm_isdst represents
+ the amount time is advanced during Daylight Saving time.
+
+ Section 7.23.3.5 strftime()
+ Only the 'C' locale is supported, therefore the modifiers 'E' and 'O' are ignored.
+ The 'Z' conversion is also ignored, due to the lack of time zone name.
+
+ In addition to the above departures from the standard, there are some behaviors which are different
+ from what is often expected, though allowed under the standard.
+
+ There is no 'platform standard' method to obtain the current time, time zone, or
+ daylight savings 'rules' in the AVR environment. Therefore the application must initialize
+ the time system with this information. The functions set_zone(), set_dst(), and
+ set_system_time() are provided for initialization. Once initialized, system time is maintained by
+ calling the function system_tick() at one second intervals.
+
+ Though not specified in the standard, it is often expected that time_t is a signed integer
+ representing an offset in seconds from Midnight Jan 1 1970... i.e. 'Unix time'. This implementation
+ uses an unsigned 32 bit integer offset from Midnight Jan 1 2000. The use of this 'epoch' helps to
+ simplify the conversion functions, while the 32 bit value allows time to be properly represented
+ until Tue Feb 7 06:28:15 2136 UTC. The macros UNIX_OFFSET and NTP_OFFSET are defined to assist in
+ converting to and from Unix and NTP time stamps.
+
+ Unlike desktop counterparts, it is impractical to implement or maintain the 'zoneinfo' database.
+ Therefore no attempt is made to account for time zone, daylight saving, or leap seconds in past dates.
+ All calculations are made according to the currently configured time zone and daylight saving 'rule'.
+
+ In addition to C standard functions, re-entrant versions of ctime(), asctime(), gmtime() and
+ localtime() are provided which, in addition to being re-entrant, have the property of claiming
+ less permanent storage in RAM. An additional time conversion, isotime() and its re-entrant version,
+ uses far less storage than either ctime() or asctime().
+
+ Along with the usual smattering of utility functions, such as is_leap_year(), this library includes
+ a set of functions related the sun and moon, as well as sidereal time functions.
+*/
+
+#ifndef TIME_H
+#define TIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+#include <stdlib.h>
+
+ /** \ingroup avr_time */
+ /* @{ */
+
+ /**
+ time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the Y2K 'epoch').
+ Its range allows this implementation to represent time up to Tue Feb 7 06:28:15 2136 UTC.
+ */
+ typedef uint32_t time_t;
+
+ /**
+ The time function returns the systems current time stamp.
+ If timer is not a null pointer, the return value is also assigned to the object it points to.
+ */
+ time_t time(time_t *timer);
+
+ /**
+ The difftime function returns the difference between two binary time stamps,
+ time1 - time0.
+ */
+ int32_t difftime(time_t time1, time_t time0);
+
+
+ /**
+ The tm structure contains a representation of time 'broken down' into components of the
+ Gregorian calendar.
+
+ The normal ranges of the elements are..
+
+ \code
+ tm_sec seconds after the minute - [ 0 to 59 ]
+ tm_min minutes after the hour - [ 0 to 59 ]
+ tm_hour hours since midnight - [ 0 to 23 ]
+ tm_mday day of the month - [ 1 to 31 ]
+ tm_wday days since Sunday - [ 0 to 6 ]
+ tm_mon months since January - [ 0 to 11 ]
+ tm_year years since 1900
+ tm_yday days since January 1 - [ 0 to 365 ]
+ tm_isdst Daylight Saving Time flag *
+
+ \endcode
+
+ *The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if
+ the information is not available.
+
+ When Daylight Saving Time is in effect, the value represents the number of
+ seconds the clock is advanced.
+
+ See the set_dst() function for more information about Daylight Saving.
+
+ */
+ struct tm {
+ int8_t tm_sec;
+ int8_t tm_min;
+ int8_t tm_hour;
+ int8_t tm_mday;
+ int8_t tm_wday;
+ int8_t tm_mon;
+ int16_t tm_year;
+ int16_t tm_yday;
+ int16_t tm_isdst;
+ };
+
+
+ /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can
+ be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_
+ so that the user can provide the value on the link line, which should
+ result in little or no run-time overhead compared with a constant. */
+ typedef unsigned long clock_t;
+ extern char *_CLOCKS_PER_SEC_;
+#define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_)
+ extern clock_t clock(void);
+
+ /**
+ This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
+ The elements of timeptr are interpreted as representing Local Time.
+
+ The original values of the tm_wday and tm_yday elements of the structure are ignored,
+ and the original values of the other elements are not restricted to the ranges stated for struct tm.
+
+ On successful completion, the values of all elements of timeptr are set to the appropriate range.
+ */
+ time_t mktime(struct tm * timeptr);
+
+ /**
+ This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
+ The elements of timeptr are interpreted as representing UTC.
+
+ The original values of the tm_wday and tm_yday elements of the structure are ignored,
+ and the original values of the other elements are not restricted to the ranges stated for struct tm.
+
+ Unlike mktime(), this function DOES NOT modify the elements of timeptr.
+ */
+ time_t mk_gmtime(const struct tm * timeptr);
+
+ /**
+ The gmtime function converts the time stamp pointed to by timer into broken-down time,
+ expressed as UTC.
+ */
+ struct tm *gmtime(const time_t * timer);
+
+ /**
+ Re entrant version of gmtime().
+ */
+ void gmtime_r(const time_t * timer, struct tm * timeptr);
+
+ /**
+ The localtime function converts the time stamp pointed to by timer into broken-down time,
+ expressed as Local time.
+ */
+ struct tm *localtime(const time_t * timer);
+
+ /**
+ Re entrant version of localtime().
+ */
+ void localtime_r(const time_t * timer, struct tm * timeptr);
+
+ /**
+ The asctime function converts the broken-down time of timeptr, into an ascii string in the form
+
+ Sun Mar 23 01:03:52 2013
+ */
+ char *asctime(const struct tm * timeptr);
+
+ /**
+ Re entrant version of asctime().
+ */
+ void asctime_r(const struct tm * timeptr, char *buf);
+
+ /**
+ The ctime function is equivalent to asctime(localtime(timer))
+ */
+ char *ctime(const time_t * timer);
+
+ /**
+ Re entrant version of ctime().
+ */
+ void ctime_r(const time_t * timer, char *buf);
+
+ /**
+ The isotime function constructs an ascii string in the form
+ \code2013-03-23 01:03:52\endcode
+ */
+ char *isotime(const struct tm * tmptr);
+
+ /**
+ Re entrant version of isotime()
+ */
+ void isotime_r(const struct tm *, char *);
+
+ /**
+ A complete description of strftime() is beyond the pale of this document.
+ Refer to ISO/IEC document 9899 for details.
+
+ All conversions are made using the 'C Locale', ignoring the E or O modifiers. Due to the lack of
+ a time zone 'name', the 'Z' conversion is also ignored.
+ */
+ size_t strftime(char *s, size_t maxsize, const char *format, const struct tm * timeptr);
+
+ /**
+ Specify the Daylight Saving function.
+
+ The Daylight Saving function should examine its parameters to determine whether
+ Daylight Saving is in effect, and return a value appropriate for tm_isdst.
+
+ Working examples for the USA and the EU are available..
+
+ \code #include <util/eu_dst.h>\endcode
+ for the European Union, and
+ \code #include <util/usa_dst.h>\endcode
+ for the United States
+
+ If a Daylight Saving function is not specified, the system will ignore Daylight Saving.
+ */
+ void set_dst(int (*) (const time_t *, int32_t *));
+
+ /**
+ Set the 'time zone'. The parameter is given in seconds East of the Prime Meridian.
+ Example for New York City:
+ \code set_zone(-5 * ONE_HOUR);\endcode
+
+ If the time zone is not set, the time system will operate in UTC only.
+ */
+ void set_zone(int32_t);
+
+ /**
+ Initialize the system time. Examples are...
+
+ From a Clock / Calendar type RTC:
+ \code
+ struct tm rtc_time;
+
+ read_rtc(&rtc_time);
+ rtc_time.tm_isdst = 0;
+ set_system_time( mktime(&rtc_time) );
+ \endcode
+
+ From a Network Time Protocol time stamp:
+ \code
+ set_system_time(ntp_timestamp - NTP_OFFSET);
+ \endcode
+
+ From a UNIX time stamp:
+ \code
+ set_system_time(unix_timestamp - UNIX_OFFSET);
+ \endcode
+
+ */
+ void set_system_time(time_t timestamp);
+
+ /**
+ Maintain the system time by calling this function at a rate of 1 Hertz.
+
+ It is anticipated that this function will typically be called from within an
+ Interrupt Service Routine, (though that is not required). It therefore includes code which
+ makes it simple to use from within a 'Naked' ISR, avoiding the cost of saving and restoring
+ all the cpu registers.
+
+ Such an ISR may resemble the following example...
+ \code
+ ISR(RTC_OVF_vect, ISR_NAKED)
+ {
+ system_tick();
+ reti();
+ }
+ \endcode
+ */
+ void system_tick(void);
+
+ /**
+ Enumerated labels for the days of the week.
+ */
+ enum _WEEK_DAYS_ {
+ SUNDAY,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY
+ };
+
+ /**
+ Enumerated labels for the months.
+ */
+ enum _MONTHS_ {
+ JANUARY,
+ FEBRUARY,
+ MARCH,
+ APRIL,
+ MAY,
+ JUNE,
+ JULY,
+ AUGUST,
+ SEPTEMBER,
+ OCTOBER,
+ NOVEMBER,
+ DECEMBER
+ };
+
+ /**
+ Return 1 if year is a leap year, zero if it is not.
+ */
+ uint8_t is_leap_year(int16_t year);
+
+ /**
+ Return the length of month, given the year and month, where month is in the range 1 to 12.
+ */
+ uint8_t month_length(int16_t year, uint8_t month);
+
+ /**
+ Return the calendar week of year, where week 1 is considered to begin on the
+ day of week specified by 'start'. The returned value may range from zero to 52.
+ */
+ uint8_t week_of_year(const struct tm * timeptr, uint8_t start);
+
+ /**
+ Return the calendar week of month, where the first week is considered to begin on the
+ day of week specified by 'start'. The returned value may range from zero to 5.
+ */
+ uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
+
+ /**
+ Structure which represents a date as a year, week number of that year, and day of week.
+ See http://en.wikipedia.org/wiki/ISO_week_date for more information.
+ */
+ struct week_date{
+ int year;
+ int week;
+ int day;
+ };
+
+ /**
+ Return a week_date structure with the ISO_8601 week based date corresponding to the given
+ year and day of year. See http://en.wikipedia.org/wiki/ISO_week_date for more
+ information.
+ */
+ struct week_date * iso_week_date( int year, int yday);
+
+ /**
+ Re-entrant version of iso-week_date.
+ */
+ void iso_week_date_r( int year, int yday, struct week_date *);
+
+ /**
+ Convert a Y2K time stamp into a FAT file system time stamp.
+ */
+ uint32_t fatfs_time(const struct tm * timeptr);
+
+ /** One hour, expressed in seconds */
+#define ONE_HOUR 3600
+
+ /** Angular degree, expressed in arc seconds */
+#define ONE_DEGREE 3600
+
+ /** One day, expressed in seconds */
+#define ONE_DAY 86400
+
+ /** Difference between the Y2K and the UNIX epochs, in seconds. To convert a Y2K
+ timestamp to UNIX...
+ \code
+ long unix;
+ time_t y2k;
+
+ y2k = time(NULL);
+ unix = y2k + UNIX_OFFSET;
+ \endcode
+ */
+#define UNIX_OFFSET 946684800
+
+ /** Difference between the Y2K and the NTP epochs, in seconds. To convert a Y2K
+ timestamp to NTP...
+ \code
+ unsigned long ntp;
+ time_t y2k;
+
+ y2k = time(NULL);
+ ntp = y2k + NTP_OFFSET;
+ \endcode
+ */
+#define NTP_OFFSET 3155673600
+
+ /*
+ * ===================================================================
+ * Ephemera
+ */
+
+ /**
+ Set the geographic coordinates of the 'observer', for use with several of the
+ following functions. Parameters are passed as seconds of North Latitude, and seconds
+ of East Longitude.
+
+ For New York City...
+ \code set_position( 40.7142 * ONE_DEGREE, -74.0064 * ONE_DEGREE); \endcode
+ */
+ void set_position(int32_t latitude, int32_t longitude);
+
+ /**
+ Computes the difference between apparent solar time and mean solar time.
+ The returned value is in seconds.
+ */
+ int16_t equation_of_time(const time_t * timer);
+
+ /**
+ Computes the amount of time the sun is above the horizon, at the location of the observer.
+
+ NOTE: At observer locations inside a polar circle, this value can be zero during the winter,
+ and can exceed ONE_DAY during the summer.
+
+ The returned value is in seconds.
+ */
+ int32_t daylight_seconds(const time_t * timer);
+
+ /**
+ Computes the time of solar noon, at the location of the observer.
+ */
+ time_t solar_noon(const time_t * timer);
+
+ /**
+ Return the time of sunrise, at the location of the observer. See the note about daylight_seconds().
+ */
+ time_t sun_rise(const time_t * timer);
+
+ /**
+ Return the time of sunset, at the location of the observer. See the note about daylight_seconds().
+ */
+ time_t sun_set(const time_t * timer);
+
+ /** Returns the declination of the sun in radians. */
+ double solar_declination(const time_t * timer);
+
+ /**
+ Returns an approximation to the phase of the moon.
+ The sign of the returned value indicates a waning or waxing phase.
+ The magnitude of the returned value indicates the percentage illumination.
+ */
+ int8_t moon_phase(const time_t * timer);
+
+ /**
+ Returns Greenwich Mean Sidereal Time, as seconds into the sidereal day.
+ The returned value will range from 0 through 86399 seconds.
+ */
+ unsigned long gm_sidereal(const time_t * timer);
+
+ /**
+ Returns Local Mean Sidereal Time, as seconds into the sidereal day.
+ The returned value will range from 0 through 86399 seconds.
+ */
+ unsigned long lm_sidereal(const time_t * timer);
+
+ /* @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TIME_H */
diff --git a/time/tm_store.c b/time/tm_store.c
new file mode 100644
index 0000000..af8229b
--- /dev/null
+++ b/time/tm_store.c
@@ -0,0 +1,37 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: tm_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+/*
+ Private allocation, used by gmtime() and localtime()
+*/
+
+#include <time.h>
+
+struct tm __tm_store;
diff --git a/time/utc_offset.c b/time/utc_offset.c
new file mode 100644
index 0000000..14c8180
--- /dev/null
+++ b/time/utc_offset.c
@@ -0,0 +1,35 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: utc_offset.c 2321 2013-04-02 00:12:48Z swfltek $ */
+
+/*
+ UTC offset in seconds East
+*/
+
+long __utc_offset;
diff --git a/time/week_of_month.c b/time/week_of_month.c
new file mode 100644
index 0000000..6eca94f
--- /dev/null
+++ b/time/week_of_month.c
@@ -0,0 +1,62 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: week_of_month.c 2362 2013-04-26 22:22:46Z swfltek $ */
+
+/*
+ Return the week of month, where 'base' represents the starting day.
+ In the USA, the week is generally considered to start on Sunday (base = 0),
+ while in Europe it is generally considered to be Monday (base = 1).
+
+ Return value ranges from 0 to 5.
+*/
+
+#include <time.h>
+
+uint8_t
+week_of_month(const struct tm * timestruct, uint8_t base)
+{
+ int first, n;
+
+ /* zero base the day of month */
+ n = timestruct->tm_mday - 1;
+
+ /* find the first base day of the month (start of week 1) */
+ first = 7 + n - timestruct->tm_wday + base;
+ first %= 7;
+
+ /* find days since the first week began */
+ n = n - first;
+
+ /* if negative, we are in week 0 */
+ if (n < 0)
+ return 0;
+
+ return n / 7 + 1;
+
+}
diff --git a/time/week_of_year.c b/time/week_of_year.c
new file mode 100644
index 0000000..ad06f62
--- /dev/null
+++ b/time/week_of_year.c
@@ -0,0 +1,58 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: week_of_year.c 2362 2013-04-26 22:22:46Z swfltek $ */
+
+/*
+ Return the week of year, where 'base' represents the first day of the week.
+ In the USA, the week is generally considered to start on Sunday (base = 0),
+ while in Europe it is generally considered to be Monday (base = 1).
+
+ Return value ranges from 0 to 52.
+*/
+
+#include <time.h>
+
+uint8_t
+week_of_year(const struct tm * timestruct, uint8_t base)
+{
+ int first, n;
+
+ /* find the first base day of the year (start of week 1) */
+ first = 7 + timestruct->tm_yday - timestruct->tm_wday + base;
+ first %= 7;
+
+ /* find days since that first base day*/
+ n = timestruct->tm_yday - first;
+
+ /* if negative, we are in week 0 */
+ if (n < 0)
+ return 0;
+
+ return n / 7 + 1;
+}
diff --git a/z180/Makefile b/z180/Makefile
index f676826..c6727b9 100644
--- a/z180/Makefile
+++ b/z180/Makefile
@@ -1,7 +1,9 @@
-SRC := r3init.180 ddtz.180
-SRC += fifoio.180 msgbuf.180 ser1-i.180 console.180
+SRC := init.180 ddtz.180
+SRC += console.180
+SRC += msgbuf-a.180 conbuf-a.180
+SRC += asci1-p.180
SRC += romend.180
INC := config.inc z180reg.inc z180.lib
@@ -11,7 +13,7 @@ OBJ := $(SRC:.180=.rel)
#CP/M emulator
CPMEMU = zxcc
-#Location of CP/M binaries
+#Location of CP/M binaries
CPMBIN = /usr/local/lib/cpm/bin80
#AS = $(CPMEMU) $(CPMBIN)/m80.com
@@ -24,7 +26,7 @@ AS_OPT := MFS
AS_QUIET = 1
LN_QUIET = 1
-#LNKCMD =
+#LNKCMD =
LN_VERB = /V
LN_PROG = 0
LN_DATA = C000
@@ -70,7 +72,7 @@ define cpm-link =
endef
#Use: MAKESYM Filename[.ext][/PXXXX][/DXXXX][/CXXXX]
-#egrep '^[[:xdigit:]]{4}[[:space:]]+[[:xdigit:]]{4}[[:space:]]+D.*r3init\.rel' hdrom.map
+#egrep '^[[:xdigit:]]{4}[[:space:]]+[[:xdigit:]]{4}[[:space:]]+D.*init\.rel' hdrom.map
define cpm-mksym =
COMMAND="$(CPMEMU) makesym -$^ -/P -D"; \
OUTPUT=$$(mktemp); echo $${COMMAND}; \
@@ -80,7 +82,7 @@ if [ "$${ERROR}" != "0" ]; then cat $${OUTPUT}; rm -f $@; fi ; \
exit $${ERROR}
endef
-hdrom.c: hdrom.hex
+hdrom.c: hdrom.hex
srec_cat -o $@ -c_array $(basename $<) -C_COMpressed -include $< -Intel
hdrom.hex : $(OBJ)
@@ -92,7 +94,7 @@ hdrom.hex : $(OBJ)
hdrom.map: hdrom.hex
-%.sym: hdrom.map %.lst
+%.sym: hdrom.map %.lst
@$(cpm-mksym)
.phony: clean realclean
@@ -123,4 +125,3 @@ realclean: clean
if [ "$${ERROR}" != "0" ]; then cat $${OUTPUT}; fi ; \
rm $${OUTPUT}; \
exit $${ERROR}
-
diff --git a/z180/Tupfile b/z180/Tupfile
index bb88946..50ede98 100644
--- a/z180/Tupfile
+++ b/z180/Tupfile
@@ -2,12 +2,12 @@ include_rules
PROG = hdrom
-SRC = r3init.180
+SRC = init.180
SRC += ddtz.180
-#SRC += fifoio.180 msgbuf.180 ser1-i.180 console.180
-SRC += msgbuf-a.180 conbuf-a.180 ser1-i.180 bioscio.180 chario.180
-# serial (asci1) console only:
-#SRC += ser1-i.180 console.180
+SRC += msgbuf-a.180 conbuf-a.180
+#SRC += bioscio.180 chario.180
+SRC += console.180
+SRC += asci-p.180
SRC += romend.180
@@ -28,7 +28,7 @@ AS = $(CPMEMU) slr180.com
###############################################################################
-!AS-plain = |> $(AS) -%B/$(AS_OPT) |> %B.rel | %B.lst
+!AS-plain = |> $(AS) -%B/$(AS_OPT) |> %B.rel | %B.lst
!AS = |> ^ $(AS) -%B/$(AS_OPT)^ set +e; OUTPUT=\$(mktemp);\
$(AS) -%B/$(AS_OPT) > ${OUTPUT};\
@@ -36,9 +36,10 @@ grep -q '^ 0 Error(s) Detected' ${OUTPUT}; ERROR=$?;\
[ "${ERROR}" != "0" ] && cat ${OUTPUT};\
[ "${ERROR}" != "0" ] && rm -f %B.rel;\
rm -f ${OUTPUT}; exit ${ERROR} \
-|> %B.rel | %B.lst
+|> %B.rel | %B.lst
-!LINK = |> ld80 -o %o -ms %O.map -P $(LN_PROG) -D $(LN_DATA) %f |> | %O.map
+#!LINK = |> ld80 -o %o -ms %O.map -P $(LN_PROG) -D $(LN_DATA) %f |> | %O.map
+!LINK = |> ld80 -o %o -ms %O.map -P $(LN_PROG) %f |> | %O.map
#ifndef DEBUG
@@ -51,4 +52,3 @@ rm -f ${OUTPUT}; exit ${ERROR} \
#endif
-
diff --git a/z180/asci-p.180 b/z180/asci-p.180
new file mode 100644
index 0000000..956faf1
--- /dev/null
+++ b/z180/asci-p.180
@@ -0,0 +1,133 @@
+ page 200
+
+ extrn ioiniml
+
+ global as0init
+ global as0ista,as0inp
+ global as0osta,as0out
+ global as1init
+ global as1ista,as1inp
+ global as1osta,as1out
+
+ include config.inc
+ include z180reg.inc
+
+
+;-----------------------------------------------------
+;
+;
+; TC = (f PHI /(2*baudrate*Clock_mode)) - 2
+;
+; TC = (f PHI / (32 * baudrate)) - 2
+;
+
+ cseg
+;
+; Init Serial I/O for console input and output (ASCI1)
+;
+
+
+
+as0init:
+ ld hl,initab0
+ jp ioiniml
+
+as1init:
+ ld hl,initab1
+ jp ioiniml
+
+
+ ld a,M_MPBT
+ out0 (cntlb1),a
+ ld a,M_RE + M_TE + M_MOD2 ;Rx/Tx enable
+ out0 (cntla1),a
+ ld a,M_RIE
+ out0 (stat1),a ;Enable rx interrupts
+
+ ret ;
+
+
+initab0:
+ db 1,stat0,0 ;Disable rx/tx interrupts
+ ;Enable baud rate generator
+ db 1,asext0,M_BRGMOD+M_DCD0DIS+M_CTS0DIS
+ db 2,astc0l,low 28, high 28
+ db 1,cntlb0,M_MPBT ;No MP Mode, X16
+ db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
+ db 0
+
+initab1:
+ db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
+ db 1,asext1,M_BRGMOD ;Enable baud rate generator
+ db 2,astc1l,low 3, high 3
+ db 1,cntlb1,M_MPBT ;No MP Mode, X16
+ db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
+ db 0
+
+
+
+as0ista:
+ in0 a,(stat0)
+ and M_RDRF
+ ret z
+ or 0ffh
+ ret
+
+as1ista:
+ in0 a,(stat1)
+ and M_RDRF
+ ret z
+ or 0ffh
+ ret
+
+
+as0inp:
+ in0 a,(stat0)
+ rlca
+ jr nc,as0inp
+ in0 a,rdr0
+ ret
+
+as1inp:
+ in0 a,(stat1)
+ rlca
+ jr nc,as1inp
+ in0 a,rdr1
+ ret
+
+
+
+as0osta:
+ in0 a,(stat0)
+ and M_TDRE
+ ret z
+ or 0ffh
+ ret
+
+as1osta:
+ in0 a,(stat1)
+ and M_TDRE
+ ret z
+ or 0ffh
+ ret
+
+
+as0out:
+ in0 a,(stat0)
+ and M_TDRE
+ jr z,as0out
+ out0 (tdr0),c
+ ld a,c
+ ret
+
+as1out:
+ in0 a,(stat1)
+ and M_TDRE
+ jr z,as1out
+ out0 (tdr1),c
+ ld a,c
+ ret
+
+ end
+
+
diff --git a/z180/ser1-i.180 b/z180/asci1-i.180
index 2410e38..15e121a 100644
--- a/z180/ser1-i.180
+++ b/z180/asci1-i.180
@@ -4,12 +4,12 @@
extrn buf.init
extrn isv_sw
-
+
global ser.init
global ser.ist,ser.in
global ser.ost,ser.out
-;TODO: define a trampoline area somewhere in top ram.
+;TODO: define a trampoline area somewhere in top ram.
rtxisvjmp equ 0FF60h ;momentan frei...
include config.inc
@@ -19,10 +19,10 @@ rtxisvjmp equ 0FF60h ;momentan frei...
;-----------------------------------------------------
dseg
-
+
buf_start:
- mkbuf ser1.inbuf,s1.rx_len
- mkbuf ser1.outbuf,s1.tx_len
+ mkbuf s1.rx_id, ser1.inbuf, s1.rx_len
+ mkbuf s1.tx_id, ser1.outbuf, s1.tx_len
buf_end:
@@ -33,7 +33,7 @@ buf_end:
;
; Init Serial I/O for console input and output (ASCI1)
;
-
+
ser.init:
; ld a,i
@@ -42,10 +42,10 @@ ser.init:
xor a ;
out0 (stat1),a ;Disable rx/tx interrupts
-
+
ld hl,rxtx_src ;move rx and tx isv to common ram
ld de,rxtx_dst ;
- ld bc,rxtx_src_e-rxtx_src ;
+ ld bc,rxtx_src_e-rxtx_src ;
ldir ;
ld hl,rtxisvjmp ;rx/tx int vector
@@ -59,7 +59,7 @@ ser.init:
; ASCI1: 8N1, highest baudrate (56700), CTS disabled
- ld a,M_MPBT
+ ld a,M_MPBT
out0 (cntlb1),a
ld a,M_RE + M_TE + M_MOD2
out0 (cntla1),a
@@ -89,21 +89,21 @@ buf.empty:
ret z
or 0ffh
ret
-
+
ser.in:
- push hl ;11
+ push hl ;11
push de ;11
- ld hl,ser1.inbuf-1 ; 9 hl = &rx.out_idx
+ ld hl,ser1.inbuf-1 ; 9 hl = &rx.out_idx
ld a,(hl) ; 6 a = rx.out_idx
dec hl ; 4 hl = &rx.in_idx
jr bg.w1
bg.wait:
halt
bg.w1:
- cp (hl) ; 6 while (out_idx==in_idx)
+ cp (hl) ; 6 while (out_idx==in_idx)
jr z,bg.wait ; 6 (/8) ;
- ld e,a ; 4
+ ld e,a ; 4
ld d,0 ; 6
inc de
inc de
@@ -111,20 +111,20 @@ bg.w1:
ex de,hl ; 3
add hl,de ;10
ld l,(hl) ; 6
- ex de,hl ; 3
+ ex de,hl ; 3
inc a ; 4
dec hl ; 4
- and (hl) ; 6
+ and (hl) ; 6
inc hl ; 4
inc hl ; 4
ld (hl),a ; 7
-
+
ld a,e ; 4
pop de ; 9
pop hl ; 9
ret ; 9
- ; 153
+ ; 153
ser.ost:
push ix
@@ -191,7 +191,7 @@ rxtxisv:
in0 d,(rdr1) ;todo: break detection
bit FE,a ;framing error?
jr nz,??ri_1
-
+
push ix
ld ix,ser1.inbuf ;
ld hl,ser1.inbuf ;
@@ -233,7 +233,7 @@ txisv:
??ti_1:
ld l,(hl)
out0 (tdr1),l ;071b
-
+
ld a,(ix+o.out_idx) ;
inc a
and (ix+o.mask)
@@ -254,5 +254,3 @@ rxtx_src_e:
end
-
-
diff --git a/z180/bioscio.180 b/z180/bioscio.180
index 5ec55c6..2d8e5e0 100644
--- a/z180/bioscio.180
+++ b/z180/bioscio.180
@@ -65,7 +65,8 @@ c$init$loop:
dec c
jp p,c$init$loop
- ld hl,1000000000000000b ; assign console to HOST
+; ld hl,1000000000000000b ; assign console to HOST
+ ld hl,0010000000000000b ; assign console to ASCI1
ld (@civec),hl
ld (@covec),hl
ld hl,0000000000000000b ; assign auxiliary to nothing
diff --git a/z180/chario.180 b/z180/chario.180
index 6632690..4d37b89 100644
--- a/z180/chario.180
+++ b/z180/chario.180
@@ -2,20 +2,21 @@
.z80
-; CP/M 3 compatible character i/o
+; CP/M 3 compatible character i/o
public ?cinit,?ci,?co,?cist,?cost
public @ctbl
extrn ff.init,ff.i.st,ff.in,ff.o.st,ff.out
- extrn ser.init,ser.ist,ser.in,ser.ost,ser.out
-
+ extrn as0init,as0ista,as0inp,as0osta,as0out
+ extrn as1init,as1ista,as1inp,as1osta,as1out
+
include config.inc
include z180reg.inc
include modebaud.inc ; define mode bits and baud eqautes
-max$device equ 2
+max$device equ 3
cseg
@@ -25,7 +26,8 @@ max$device equ 2
ld b,c
call vector$io
dw ff.init
- dw ser.init
+ dw as0init
+ dw as1init
dw rret
; b = device, c = output char, a = input char
@@ -33,25 +35,29 @@ max$device equ 2
?ci: ; character input
call vector$io
dw ff.in
- dw ser.in
+ dw as0inp
+ dw as1inp
dw null$input
?cist: ; character input status
call vector$io
dw ff.i.st
- dw ser.ist
+ dw as0ista
+ dw as1ista
dw null$status
?co: ; character output
call vector$io
dw ff.out
- dw ser.out
+ dw as0out
+ dw as1out
dw rret
?cost: ; character output status
call vector$io
dw ff.o.st
- dw ser.ost
+ dw as0osta
+ dw as1osta
dw ret$true
vector$io:
@@ -89,10 +95,15 @@ null$status:
@ctbl:
db 'HOST ' ; device 0
- db mb$output
+ db mb$in$out
db baud$none
- db 'ASCI1 ' ; device 0
+ db 'ASCI0 ' ; device 1
+ db mb$in$out+mb$serial+mb$soft$baud
+ser0$baud:
+ db baud$19200
+
+ db 'ASCI1 ' ; device 2
db mb$in$out+mb$serial+mb$soft$baud
ser1$baud:
db baud$19200
@@ -100,4 +111,3 @@ ser1$baud:
db 0 ; table terminator
end
-
diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180
index 8534f73..f69b86d 100644
--- a/z180/conbuf-a.180
+++ b/z180/conbuf-a.180
@@ -1,24 +1,26 @@
page 255
.z80
-
+
;
; FIFO channels for communication with avr
;
global ff.init,ff.in,ff.out,ff.i.st,ff.o.st
- extrn buf.init
+ extrn bufinit
include config.inc
+ if CPU_Z180
include z180reg.inc
+ endif
;--------------------------------------------------------------
dseg
-
- mkbuf co.fifo,co.fifo_len
- mkbuf ci.fifo,ci.fifo_len
+
+ mkbuf ci.fifo_id, ci.fifo, ci.fifo_len
+ mkbuf co.fifo_id, co.fifo, co.fifo_len
;--------------------------------------------------------------
@@ -30,11 +32,9 @@
ff.init:
ld ix,ci.fifo
- ld a,ci.fifo.mask
- call buf.init
+ call bufinit
ld ix,co.fifo
- ld a,co.fifo.mask
- jp buf.init
+ jp bufinit
ff.i.st:
@@ -48,7 +48,7 @@ buf.empty:
ret z
or 0ffh
ret
-
+
ff.in:
push ix
@@ -69,12 +69,12 @@ bg.wait:
inc h
bg.nc:
ld l,(hl)
-
+
ld a,(ix+o.out_idx) ;
inc a
and (ix+o.mask)
ld (ix+o.out_idx),a
-
+
ld a,l
pop hl
pop ix
@@ -96,36 +96,68 @@ buf.full:
ret
+ if 1
ff.out:
- push ix
- ld ix,co.fifo ;
+ push ix ;15
+ ld ix,co.fifo ;14
buf.put:
- push hl ;
- push bc
- push ix
- pop hl
- ld a,c
- ld c,(ix+o.in_idx) ;
- ld b,0
- add hl,bc
- ld b,a
+ push hl ;11
+ push bc ;11
+ push ix ;15
+ pop hl ;10
+ ld a,c ;4
+ ld c,(ix+o.in_idx) ;19
+ ld b,0 ;7
+ add hl,bc ;11
+ ld (hl),a ;7
+ ld b,a ;4
+
+ ld a,c ;4
+ inc a ;4
+ and (ix+o.mask) ;19
+bp.wait:
+ cp (ix+o.out_idx) ;19
+ jr z,bp.wait ;12/7
+ ld (ix+o.in_idx),a ;19
- ld a,c ;
- inc a
- and (ix+o.mask)
+ out (AVRINT6),a ;11
+ ld a,b ;4
+ pop bc ;10
+ pop hl ;10
+ pop ix ;14
+ ret ;10
+
+ else
+
+ff.out:
+ push ix ;15
+ ld ix,co.fifo ;14
+
+buf.put:
+ push hl ;11
+ push ix ;15
+ pop hl ;10
+ ld a,(ix+o.in_idx) ;19
+ add a,l ;4
+ ld l,a ;4
+ jr nc,bp.1 ;12/7
+ inc l ;4
+ ld (hl),c ;7
+ ld a,(ix+o.in_idx) ;19
+ inc a ;4
+ and (ix+o.mask) ;19
bp.wait:
- cp (ix+o.out_idx) ;
- jr z,bp.wait
- ld (hl),b
- ld (ix+o.in_idx),a
-
- out (AVRINT6),a
- ld a,b
- pop bc
- pop hl
- pop ix
- ret
+ cp (ix+o.out_idx) ;19
+ jr z,bp.wait ;12/7
+ ld (ix+o.in_idx),a ;19
- end
+ out (AVRINT6),a ;11
+ ld a,c ;4
+ pop hl ;10
+ pop ix ;14
+ ret ;10 |
+
+ endif
+ end
diff --git a/z180/config.inc b/z180/config.inc
index 9cef051..1d0709d 100644
--- a/z180/config.inc
+++ b/z180/config.inc
@@ -1,64 +1,164 @@
+FALSE equ 0
+TRUE equ NOT FALSE
-FOSC equ 9216 ;Oscillator frequency [KHz]
-PHI equ FOSC*2 ;CPU frequency
+
+DEBUG equ true
+
+banked equ true
;-----------------------------------------------------
-; Programmable Reload Timer (PRT)
+; CPU and BANKING types
-PRT_PRE equ 20 ;PRT prescaler
-; Reload value for 10 ms Int. (0.1KHz):
-; tc10ms = phi/prescale/0.1KHz = phi / (prescale/10)
+CPU_Z180 equ TRUE
+CPU_Z80 equ FALSE
-PRT_TC10MS equ PHI / (PRT_PRE/10)
+ROMSYS equ FALSE
+
+AVRCLK equ 18432 ;[KHz]
+
+ if CPU_Z180
;-----------------------------------------------------
-; MMU
+;FOSC equ AVRCLK/2 ;Oscillator frequency [KHz]
+;PHI equ FOSC*2 ;CPU frequency (clock doubler enabled)
+
+;----------------------------------------------------------------------
+; Baudrate Generator for x16 clock mode:
+; TC = (f PHI / (32 * baudrate)) - 2
+;
+; PHI [MHz]: 9.216 18.432
+; baudrate TC TC
+; ----------------------
+; 115200 - 3
+; 57600 3 8
+; 38400 - 13
+; 19200 13 28
+; 9600 28 58
-SYS$CBAR equ 0C8h
-USR$CBAR equ 0F0h
+;-----------------------------------------------------
+; Programmable Reload Timer (PRT)
-BANKS equ 18 ;max nr. of banks
+PRT_PRE equ 20 ;PRT prescaler
;-----------------------------------------------------
+; MMU
-CREFSH equ 0 ;Refresh rate register (disable refresh)
-CWAITIO equ 3 shl IWI0 ;Max I/O Wait States, 0 Memory Wait States
+COMMON_SIZE equ 16*1024 ;Common Area size in bytes
+ ;must be multiple of 4K
+if (COMMON_SIZE mod 1000h)
+ .printx COMMON_SIZE not multiple of 4K!
+ end ;stop assembly
+endif
+CMN_SIZE equ COMMON_SIZE/1000h ;4K units
+BNK_SIZE equ 64/4 - CMN_SIZE ;bank size (4K units)
+BANKS equ (512/4 - CMN_SIZE)/BNK_SIZE ;max nr. of banks
+
+; Logical address space, CBAR values
+CA equ 10h - CMN_SIZE ;common area start (64K - common size)
+BA equ 0 ;banked area start
-ROMSYS equ 0
+ if 0
- if ROMSYS
+SYS$CBR equ 0
+SYS$CBAR equ CA*16 + CA ;CBAR in system mode
+USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M)
+
+ endif
+ if 1
+
+SYS$CBR equ BNK_SIZE
+SYS$CBAR equ CA*16 + CA ;CBAR in system mode
+USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M)
+
+ endif
+
+
+;-----------------------------------------------------
+
+CREFSH equ 0 ;Refresh rate register (disable refresh)
+CWAITIO equ 3 shl IWI0 ;Max I/O Wait States, 0 Memory Wait States
+PHI_X2 equ 0 ;set to M_X2CM to enable the clock doubler
+
+ endif ;CPU_Z180
+ if CPU_Z80
+
+PHI equ AVRCLK/5 ;CPU frequency [KHz]
+BAUDCLCK equ AVRCLK/10 ;Baudrate clock [KHz]
+;BDCLK16 equ
+
+SIOAD EQU 0bch
+SIOAC EQU 0bdh
+SIOBD EQU 0beh
+SIOBC EQU 0bfh
+
+CTC0 EQU 0f4h
+CTC1 EQU 0f5h
+CTC2 EQU 0f6h
+CTC3 EQU 0f7h
+
+;
+; Init Serial I/O for console input and output (SIO-A)
+;
+; Baudrate clock: 1843200 Hz (Bus connector pin A17)
+;
+; Baudrate Divider SIO CTC
+; ---------------------------------
+; 115200 16 16 1
+; 57600 32 16 2
+; 38400 48 16 3
+; 19200 96 16 6
+; 9600 192 16 12
+; 4800 384 16 24
+; 2400 768 16 48
+; 1200 1536 16 96
+; 600 3072 16 192
+; 300 6144 64 92
+
+ endif ; CPU_Z80
+
+ if ROMSYS
c$rom equ 0a5h
ROM_EN equ 0C0h
ROM_DIS equ ROMEN+1
+ if CPU_Z180
CWAITROM equ 2 shl MWI0
- endif
+ endif
+ endif
-DRSTNUM equ 30h ;DDTZ Restart vector (breakpoints)
+DDTZRSTVEC equ 030h ;DDTZ Restart vector (breakpoints)
+INIDONE equ 03Fh ;CP/M skip hw init, if this address
+INIDONEVAL equ 080h ; is set to this value.
-mrx.fifo_len equ 256
-mtx.fifo_len equ 256
+mtx.fifo_len equ 64 ;Message transfer fifos
+mtx.fifo_id equ 0 ; This *must* have #0
+mrx.fifo_len equ 64
+mrx.fifo_id equ 1
-ci.fifo_len equ 128
-co.fifo_len equ 256
+ci.fifo_len equ 32 ;AVRCON Character I/O via AVR
+ci.fifo_id equ 2
+co.fifo_len equ 32
+co.fifo_id equ 3
-s1.rx_len equ 256 ;Serial 1 (ASCI1) buffers
-s1.tx_len equ 256 ;
+s1.rx_len equ 128 ;Serial 1 (ASCI1) buffers
+s1.rx_id equ 4 ;
+s1.tx_len equ 128 ;
+s1.tx_id equ 5 ;
-AVRINT5 equ 40h
-AVRINT6 equ 50h
+AVRINT5 equ 4Fh
+AVRINT6 equ 5Fh
;PMSG equ 80h
;-----------------------------------------------------
-; Definition of (locical) top 2 memory pages
+; Definition of (logical) top 2 memory pages
sysram_start equ 0FE00h
-stacksize equ 80
+bs$stack$size equ 80
isvsw_loc equ 0FEE0h
@@ -69,24 +169,27 @@ iv2tab equ ivtab + 2*9
;-----------------------------------------------------
-
+o.id equ -4
o.mask equ -3
o.in_idx equ -2
o.out_idx equ -1
.lall
-mkbuf macro name,size
- if ((size & (size-1)) ne 0) or (size gt 256)
+mkbuf macro id,name,size
+ if ((size AND (size-1)) NE 0) OR (size GT 256)
.printx Error: buffer ^size must be power of 2 and in range 0..256!
name&.mask equ ;wrong size error
else
- ds 3
+ db id
+ db size-1
+ ds 2
name:: ds size
name&.mask equ low (size-1)
if size ne 0
name&.end equ $-1
name&.len equ size
+ name&.id equ id
endif
endif
endm
@@ -104,3 +207,9 @@ inidate macro
ds ??ps.len
endm
+;-----------------------------------------------------
+
+b0call macro address
+ call _b0call
+ dw address
+ endm
diff --git a/z180/console.180 b/z180/console.180
index d4f4130..1241d5a 100644
--- a/z180/console.180
+++ b/z180/console.180
@@ -2,47 +2,136 @@
.z80
- global $coninit
- global $cists,$ci
- global $co
+; iobyte:
+; 0 = console on AVR-System
+; 1 = console on SIO/ASCI
- extrn ser.init,ser.ist,ser.in,ser.ost,ser.out
+ extrn iobyte
extrn ff.init,ff.i.st,ff.in
extrn ff.o.st,ff.out
+ if CPU_Z180
+ extrn as0init,as0ista,as0inp,as0osta,as0out
+ extrn as1init,as1ista,as1inp,as1osta,as1out
+ else
+ extrn ser.init,ser.ist,ser.in,ser.ost,ser.out
+ endif
+ public charini
+ public ?const,?conin
+ public ?conos,?cono
include config.inc
+ if CPU_Z180
include z180reg.inc
+ endif
cseg
-;
-;
-$coninit:
+ if CPU_Z180
+charini:
+ call ff.init
+ call as0init
+ jp as1init
+
+?const:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.i.st
+ dec a
+ jp z,as0ista
+ dec a
+ jp z,as1ista
+ jr nullstatus
+
+?conin:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.in
+ dec a
+ jp z,as0inp
+ dec a
+ jp z,as1inp
+ jr nullinput
+
+?conos:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.o.st
+ dec a
+ jp z,as0osta
+ dec a
+ jp z,as1osta
+ jr rettrue
+
+?cono:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.out
+ dec a
+ jp z,as0out
+ dec a
+ jp z,as1out
+ jr nulloutput
+
+ else
+
+charini:
call ff.init
+ ld c,0
call ser.init
+ ld c,1
+ jp ser.init
+
+?const:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.i.st
+ dec a
+ ld b,a
+ jp ser.ist
+
+?conin:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.in
+ dec a
+ ld b,a
+ jp ser.in
+
+?conos:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.o.st
+ dec a
+ ld b,a
+ jp ser.ost
+
+?cono:
+ ld a,(iobyte)
+ and 03h
+ jp z,ff.out
+ dec a
+ ld b,a
+ jp ser.out
+ endif
+
+
+nullinput:
+ ld a,1Ah
ret
-
-$cists:
- call ff.i.st
- ret nz
- call ser.ist
+
+nulloutput:
+ ld a,c
ret
-
-$ci:
- call ff.i.st
- jp nz,ff.in
- call ser.ist
- jp nz,ser.in
- jr $ci
-
-;$costs:
-; jp f.o.st
-
-$co:
- call ff.out
- jp ser.out
-
+
+rettrue:
+ or 0FFh
+ ret
+
+nullstatus:
+ xor a
+ ret
+
end
diff --git a/z180/ddtz.180 b/z180/ddtz.180
index 10fecf8..d5b921b 100644
--- a/z180/ddtz.180
+++ b/z180/ddtz.180
@@ -2,14 +2,18 @@
.z80
extrn ?const,?conin,?cono
+ extrn getiff
+ extrn selbnk,@cbnk
global ddtz,bpent
global $stack
include config.inc
+ if CPU_Z180
include z180reg.inc
include z180.lib
+ endif
BS equ 08h
TAB equ 09h
@@ -51,10 +55,6 @@ comend macro
endif
endm
-; repeat execution of last common code snippet
-comrep macro
- call ?exclst
- endm
@@ -97,7 +97,7 @@ ddtz:
ld sp,$stack
ld a,(wstrtflg) ;check warm start flag
or a
- jr nz,ddtz_w
+;;; jr nz,ddtz_w
exx
ld hl,sysramc
@@ -105,97 +105,95 @@ ddtz:
ld bc,topcodend-topcodbeg
ldir
- ld hl,vartab
- ld de,ddtram
- ld bc,vartabe-vartab
- ldir
exx
+ if CPU_Z180
ld a,e
ld (ubbr),a
+ endif
ddtz_w:
- ld hl,MSG ;073c
- call PSTR ;073f
- call ddtei ;0742
+ ld hl,MSG
+ call PSTR
+ call ddtei
; DDTZ main loop
DDTZML:
- ld sp,$stack ;0761
- ld hl,l07eah ;0764
- ld (CMD_ERR),hl ;0767
- ld hl,(REG.PC) ;076a
- ld (OFFS.pc),hl ;076d
- call sub_0e68h ;0770
- ld hl,(CMD_RPT) ;0773
- ld de,DDTZML ;0776
- call CP.HL.DE ;0779
- ld a,'>' ;077c
- call OUTCHAR ;077e
- call nz,OUTCHAR ;0781
- call z,OUTBL ;0784
- call INLINE ;0787
- call SKIPBL ;078a
- jr z,exe_hl ;078d
- ld hl,DDTZML ;078f
- ld (CMD_RPT),hl ;0792
- inc de ;0795
- sub '?' ;0796
- jr c,ERROR ;0798
- cp 'Z'+1-'?' ;079a
- jr nc,ERROR ;079c
- add a,a ;079e
- ld hl,CMDTAB ;079f
- call ADD_HL_A ;07a2
- ld a,(hl) ;07a5
- inc hl ;07a6
- ld h,(hl) ;07a7
- ld l,a ;07a8
- jr exe_hl ;07a9
+ ld sp,$stack
+ ld hl,l07eah
+ ld (CMD_ERR),hl
+ ld hl,(REG.PC)
+ ld (OFFS.pc),hl
+ call sub_0e68h
+ ld hl,(CMD_RPT)
+ ld de,DDTZML
+ call CP.HL.DE
+ ld a,'>'
+ call OUTCHAR
+ call nz,OUTCHAR
+ call z,OUTBL
+ call INLINE
+ call SKIPBL
+ jr z,exe_hl
+ ld hl,DDTZML
+ ld (CMD_RPT),hl
+ inc de
+ sub '?'
+ jr c,ERROR
+ cp 'Z'+1-'?'
+ jr nc,ERROR
+ add a,a
+ ld hl,CMDTAB
+ call ADD_HL_A
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+ jr exe_hl
ERROR:
- ld hl,(CMD_ERR) ;07ab
+ ld hl,(CMD_ERR)
exe_hl:
- call CALL.HL ;07ae
- jr DDTZML ;07b1
+ call CALL.HL
+ jr DDTZML
CALL.HL:
- jp (hl) ;07b3
+ jp (hl)
CMDTAB:
- defw CMD.?
- defw CMD.@ ;07b4
- defw CMD.A ;07b6
- defw CMD.B ;07b8
- defw CMD.C ;07ba
- defw CMD.D ;07bc
- defw ERROR ;07be
- defw ERROR ;07c0
- defw CMD.G ;07c2
- defw CMD.H ;07c4
- defw CMD.I ;07c6
- defw ERROR ;07c8
- defw ERROR ;07ca
- defw CMD.L ;07cc
- defw CMD.M ;07ce
- defw ERROR ;07d0
- defw CMD.O ;07d2
- defw ERROR ;07d4
- defw CMD.Q ;07d6
- defw CMD.R ;07d8
- defw CMD.S ;07da
- defw CMD.T ;07dc
- defw ERROR ;07de
- defw CMD.V ;07e0
- defw ERROR ;07e2
- defw CMD.X ;07e4
- defw CMD.Y ;07e6
- defw CMD.Z ;07e8
+ defw CMD.? ;Help
+ defw CMD.@ ;Offset
+ defw CMD.A ;Assemble
+ defw CMD.B ;Breakpoint
+ defw CMD.C ;Call
+ defw CMD.D ;Display
+ defw ERROR ;
+ defw ERROR ;
+ defw CMD.G ;Go
+ defw CMD.H ;Hex Math
+ defw CMD.I ;In Port
+ defw ERROR ;
+ defw ERROR ;
+ defw CMD.L ;List
+ defw CMD.M ;Move
+ defw ERROR ;
+ defw CMD.O ;Out Port
+ defw ERROR ;
+ defw CMD.Q ;Query
+ defw CMD.R ;Read Intel Hex
+ defw CMD.S ;Substitute
+ defw CMD.T ;Trace
+ defw ERROR ;
+ defw CMD.V ;Verify
+ defw ERROR ;
+ defw CMD.X ;eXamine
+ defw CMD.Y ;eXamine Y Registers
+ defw CMD.Z ;Zap (fill) memory
l07eah:
- ld a,'?' ;07ea
- call OUTCHAR ;07ec
- jp CRLF ;07ef
+ ld a,'?'
+ call OUTCHAR
+ jp CRLF
CMD.?:
call assert_eol
@@ -295,7 +293,7 @@ l085ch:
ld (hl),a ;
cp ' ' ;
jr nc,l0869h ;
- ld a,'^' ;Controle characters
+ ld a,'^' ;Controll characters
call $co ;
ld a,(hl) ;
add a,'@' ;
@@ -427,74 +425,74 @@ l0911h:
sub_0917h:
- dec b ;0917
- push de ;0918
- ld de,10 ;0919
- call DIV_HL_DE ;091c
- ld a,h ;091f
- or l ;0920
- call nz,sub_0917h ;0921
- ld a,e ;0924
- pop de ;0925
- jr out.digit ;0926
+ dec b
+ push de
+ ld de,10
+ call DIV_HL_DE
+ ld a,h
+ or l
+ call nz,sub_0917h
+ ld a,e
+ pop de
+ jr out.digit
sub_0928h:
- push hl ;0928
- call sub_08f7h ;0929
- call out.hl ;092c
- pop hl ;092f
- ret ;0930
+ push hl
+ call sub_08f7h
+ call out.hl
+ pop hl
+ ret
out.hl:
- ld a,h ;0931
- call out.hex ;0932
- ld a,l ;0935
+ ld a,h
+ call out.hex
+ ld a,l
out.hex:
- push af ;0936
- rra ;0937
- rra ;0938
- rra ;0939
- rra ;093a
- call out.digit ;093b
- pop af ;093e
+ push af
+ rra
+ rra
+ rra
+ rra
+ call out.digit
+ pop af
out.digit:
- and 00fh ;093f
- cp 10 ;0941
- jr c,l0947h ;0943
- add a,007h ;0945
+ and 00fh
+ cp 10
+ jr c,l0947h
+ add a,007h
l0947h:
- add a,'0' ;0947
- jr OUTCHAR ;0949
+ add a,'0'
+ jr OUTCHAR
l094bh:
- ld a,'-' ;094b
- call OUTCHAR ;094d
- ld a,040h ;0950
+ ld a,'-'
+ call OUTCHAR
+ ld a,040h
out.ascii:
- ex af,af' ;0952
- call outquote ;0953
- ex af,af' ;0956
- push af ;0957
- res 7,a ;0958
- cp ' ' ;095a
- jr nc,l0960h ;095c
- sub 0c0h ;095e
+ ex af,af'
+ call outquote
+ ex af,af'
+ push af
+ res 7,a
+ cp ' '
+ jr nc,l0960h
+ sub 0c0h
l0960h:
- call OUTCHAR ;0960
- push af ;0963
- cp '''' ;0964
- call z,OUTCHAR ;0966
- pop af ;0969
- ex af,af' ;096a
- call outquote ;096b
- pop af ;096e
- or a ;096f
- ld a,'.' ;0970
- call m,OUTCHAR ;0972
- ex af,af' ;0975
- jr c,l094bh ;0976
- ret ;0978
+ call OUTCHAR
+ push af
+ cp ''''
+ call z,OUTCHAR
+ pop af
+ ex af,af'
+ call outquote
+ pop af
+ or a
+ ld a,'.'
+ call m,OUTCHAR
+ ex af,af'
+ jr c,l094bh
+ ret
outquote:
- ld a,'''' ;0979
+ ld a,''''
OUTCHAR:
push hl
push de
@@ -509,7 +507,7 @@ OUTCHAR:
pop bc
pop de
pop hl
- ret ;0988
+ ret
inchar:
push hl
@@ -519,406 +517,407 @@ inchar:
and a
jr z,inch1
call ?conin
- scf ;0991
+ scf
inch1:
pop bc
pop de
pop hl
- ret ;0992
+ ret
PSTR:
- ld c,000h ;0993
+ ld c,000h
l0995h:
- ld a,(hl) ;0995
- and a ;0996
- ret z ;0997
- call OUTCHAR ;0998
- inc c ;099b
- inc hl ;099c
- and a ;099d
- ret m ;099e
- jr l0995h ;099f
+ ld a,(hl)
+ and a
+ ret z
+ call OUTCHAR
+ inc c
+ inc hl
+ and a
+ ret m
+ jr l0995h
outbl6:
- call outbl2 ;09a1
+ call outbl2
outbl4:
- call outbl2 ;09a4
+ call outbl2
outbl2:
- call OUTBL ;09a7
+ call OUTBL
OUTBL:
- ld a,' ' ;09aa
- jr OUTCHAR ;09ac
+ ld a,' '
+ jr OUTCHAR
CRLF:
- call inchar ;09ae
- ld a,CR ;09b1
- call OUTCHAR ;09b3
- ld a,LF ;09b6
- call OUTCHAR ;09b8
- ld a,000h ;09bb
- ld (CON.COL),a ;09bd
- jp c,DDTZML ;09c0
- ret ;09c3
+ call inchar
+ ld a,CR
+ call OUTCHAR
+ ld a,LF
+ call OUTCHAR
+ ld a,000h
+ ld (CON.COL),a
+ jp c,DDTZML
+ ret
ADD_HL_A:
- add a,l ;09c4
- ld l,a ;09c5
- ret nc ;09c6
- inc h ;09c7
- ret ;09c8
+ add a,l
+ ld l,a
+ ret nc
+ inc h
+ ret
SKIPBL0:
- inc de ;09c9
+ inc de
SKIPBL:
- ld a,(de) ;09ca
- cp ' ' ;09cb
- jr z,SKIPBL0 ;09cd
- cp 009h ;09cf
- jr z,SKIPBL0 ;09d1
- or a ;09d3
- ret ;09d4
+ ld a,(de)
+ cp ' '
+ jr z,SKIPBL0
+ cp 009h
+ jr z,SKIPBL0
+ or a
+ ret
skip_to_nextarg:
- call SKIPBL ;09d5
- cp ',' ;09d8
- ret nz ;09da
- inc de ;09db
- call SKIPBL ;09dc
- cp a ;09df
- ret ;09e0
+ call SKIPBL
+ cp ','
+ ret nz
+ inc de
+ call SKIPBL
+ cp a
+ ret
assert_eol:
- call SKIPBL ;09e1
- ret z ;09e4
+ call SKIPBL
+ ret z
l09e5h:
- jp ERROR ;09e5
+ jp ERROR
chk.sp:
- push hl ;09e8
- push de ;09e9
- ld hl,0 ;09ea
- add hl,sp ;09ed
- ld de,$stack-50 ;09ee
- call CP.HL.DE ;09f1
- pop de ;09f4
- pop hl ;09f5
- jr c,l09e5h ;09f6
- ret ;09f8
+ push hl
+ push de
+ ld hl,0
+ add hl,sp
+ ld de,$stack-50
+ call CP.HL.DE
+ pop de
+ pop hl
+ jr c,l09e5h
+ ret
CP.HL.DE:
- and a ;09f9
- sbc hl,de ;09fa
- add hl,de ;09fc
- ret ;09fd
+ and a
+ sbc hl,de
+ add hl,de
+ ret
lookupch:
- ld b,000h ;09fe
+ ld b,000h
l0a00h:
- ld a,(hl) ;0a00
- and a ;0a01
- ret z ;0a02
- ld a,(de) ;0a03
- cp (hl) ;0a04
- jr z,l0a0bh ;0a05
- inc hl ;0a07
- inc b ;0a08
- jr l0a00h ;0a09
+ ld a,(hl)
+ and a
+ ret z
+ ld a,(de)
+ cp (hl)
+ jr z,l0a0bh
+ inc hl
+ inc b
+ jr l0a00h
l0a0bh:
- scf ;0a0b
- inc de ;0a0c
- ret ;0a0d
+ scf
+ inc de
+ ret
sub_0a0eh:
- ld hl,b_0x132A_start ;0a0e
- ld b,07fh ;0a11
- jr l0a17h ;0a13
+ ld hl,b_0x132A_start
+ ld b,07fh
+ jr l0a17h
sub_0a15h:
- ld b,0ffh ;0a15
+ ld b,0ffh
l0a17h:
- inc b ;0a17
- ld a,(hl) ;0a18
- and a ;0a19
- ret z ;0a1a
- call l0a27 ;0a1b
- jr nc,l0a17h ;0a1e
- res 7,b ;0a20
- ret ;0a22
+ inc b
+ ld a,(hl)
+ and a
+ ret z
+ call l0a27
+ jr nc,l0a17h
+ res 7,b
+ ret
sub_0a23h:
- push bc ;0a23
- res 7,b ;0a24
+ push bc
+ res 7,b
db 3eh ;0a26 ld a,0c5h
l0a27:
- push bc ;0a27
- push de ;0a28
+ push bc
+ push de
l0a29h:
- ld a,(de) ;0a29
- xor (hl) ;0a2a
- and 07fh ;0a2b
- jr nz,l0a41h ;0a2d
- bit 7,(hl) ;0a2f
- inc hl ;0a31
- inc de ;0a32
- jr z,l0a29h ;0a33
- scf ;0a35
- bit 7,b ;0a36
- call z,sub_0d20h ;0a38
- jr nc,l0a44h ;0a3b
- pop af ;0a3d
- scf ;0a3e
- pop bc ;0a3f
- ret ;0a40
+ ld a,(de)
+ xor (hl)
+ and 07fh
+ jr nz,l0a41h
+ bit 7,(hl)
+ inc hl
+ inc de
+ jr z,l0a29h
+ scf
+ bit 7,b
+ call z,sub_0d20h
+ jr nc,l0a44h
+ pop af
+ scf
+ pop bc
+ ret
l0a41h:
- call sub_0a50h ;0a41
+ call sub_0a50h
l0a44h:
- pop de ;0a44
- and a ;0a45
- pop bc ;0a46
- ret ;0a47
+ pop de
+ and a
+ pop bc
+ ret
sub_0a48h:
- inc b ;0a48
+ inc b
l0a49h:
- dec b ;0a49
- ret z ;0a4a
- call sub_0a50h ;0a4b
- jr l0a49h ;0a4e
+ dec b
+ ret z
+ call sub_0a50h
+ jr l0a49h
sub_0a50h:
- ld a,(hl) ;0a50
- and a ;0a51
- ret z ;0a52
+ ld a,(hl)
+ and a
+ ret z
l0a53h:
- ld a,(hl) ;0a53
- inc hl ;0a54
- and a ;0a55
- ret m ;0a56
- jr l0a53h ;0a57
+ ld a,(hl)
+ inc hl
+ and a
+ ret m
+ jr l0a53h
get_arg3:
- call get_arg_range ;0a59
- push hl ;0a5c
- push bc ;0a5d
- call skip_to_nextarg ;0a5e
- call get_arg ;0a61
- ex de,hl ;0a64
- pop bc ;0a65
- pop hl ;0a66
- ret ;0a67
+ call get_arg_range
+ push hl
+ push bc
+ call skip_to_nextarg
+ call get_arg
+ ex de,hl
+ pop bc
+ pop hl
+ ret
sub_0a68h:
- call EXPR ;0a68
- jr c,error0 ;0a6b
- ret ;0a6d
+ call EXPR
+ jr c,error0
+ ret
get_arg:
- call sub_0a68h ;0a6e
+ call sub_0a68h
l0a71h:
- jp assert_eol ;0a71
+ jp assert_eol
get_lastarg_def:
- call get_arg_def ;0a74
- jr l0a71h ;0a77
+ call get_arg_def
+ jr l0a71h
get_arg_def:
- push hl ;0a79
- call EXPR ;0a7a
- jr c,l0a80h ;0a7d
- ex (sp),hl ;0a7f
+ push hl
+ call EXPR
+ jr c,l0a80h
+ ex (sp),hl
l0a80h:
- pop hl ;0a80
- ret ;0a81
+ pop hl
+ ret
sub_0a82h:
- call sub_0a87h ;0a82
- jr l0a71h ;0a85
+ call sub_0a87h
+ jr l0a71h
sub_0a87h:
db 0e6h ;0a87 and 037h (clear carry)
get_arg_range:
scf
- ex af,af' ;0a89
- push bc ;0a8a
- push hl ;0a8b
- call EXPR ;0a8c
- jr nc,l0a97h ;0a8f
- ex af,af' ;0a91
- jr c,error0 ;0a92
- ex af,af' ;0a94
- pop hl ;0a95
-
- defb 03eh ;0a96
+ ex af,af'
+ push bc
+ push hl
+ call EXPR
+ jr nc,l0a97h
+ ex af,af'
+ jr c,error0
+ ex af,af'
+ pop hl
+
+ defb 03eh
l0a97h:
- pop af ;0a97
- call sub_0aa5h ;0a98
- jr nc,l0aa3h ;0a9b
- ex af,af' ;0a9d
- pop bc ;0a9e
- ret nc ;0a9f
+ pop af
+ call sub_0aa5h
+ jr nc,l0aa3h
+ ex af,af'
+ pop bc
+ ret nc
error0:
- jp ERROR ;0aa0
+ jp ERROR
l0aa3h:
- pop af ;0aa3
- ret ;0aa4
+ pop af
+ ret
sub_0aa5h:
- call skip_to_nextarg ;0aa5
- cp 'S' ;0aa8
- jr nz,l0aadh ;0aaa
- inc de ;0aac
+ call skip_to_nextarg
+ cp 'S'
+ jr nz,l0aadh
+ inc de
l0aadh:
- push hl ;0aad
- push af ;0aae
- call EXPR ;0aaf
- jr c,l0ac3h ;0ab2
- ld b,h ;0ab4
- ld c,l ;0ab5
- pop af ;0ab6
- pop hl ;0ab7
- jr z,l0ac1h ;0ab8
- ld a,c ;0aba
- sub l ;0abb
- ld c,a ;0abc
- ld a,b ;0abd
- sbc a,h ;0abe
- ld b,a ;0abf
- inc bc ;0ac0
+ push hl
+ push af
+ call EXPR
+ jr c,l0ac3h
+ ld b,h
+ ld c,l
+ pop af
+ pop hl
+ jr z,l0ac1h
+ ld a,c
+ sub l
+ ld c,a
+ ld a,b
+ sbc a,h
+ ld b,a
+ inc bc
l0ac1h:
- and a ;0ac1
- ret ;0ac2
+ and a
+ ret
l0ac3h:
- pop af ;0ac3
- pop hl ;0ac4
- jr z,error0 ;0ac5
- scf ;0ac7
- ret ;0ac8
+ pop af
+ pop hl
+ jr z,error0
+ scf
+ ret
EXPR:
- call SKIPBL ;0ac9
+ call SKIPBL
EXPR1:
- call do_subexpr ;0acc
- ret c ;0acf
- call do_rel_op ;0ad0
- ret nc ;0ad3
- push bc ;0ad4
- push hl ;0ad5
- call do_subexpr ;0ad6
- jr c,error0 ;0ad9
- ex de,hl ;0adb
- ex (sp),hl ;0adc
- and a ;0add
- sbc hl,de ;0ade
- ld hl,0ffffh ;0ae0
- pop de ;0ae3
- ret ;0ae4
+ call do_subexpr
+ ret c
+ call do_rel_op
+ ret nc
+ push bc
+ push hl
+ call do_subexpr
+ jr c,error0
+ ex de,hl
+ ex (sp),hl
+ and a
+ sbc hl,de
+ ld hl,0ffffh
+ pop de
+ ret
do_op_eq:
- jr z,l0af8h ;0ae5
- jr l0af7h ;0ae7
+ jr z,l0af8h
+ jr l0af7h
do_op_ne:
- jr nz,l0af8h ;0ae9
- jr l0af7h ;0aeb
+ jr nz,l0af8h
+ jr l0af7h
do_op_le:
- jr z,l0af8h ;0aed
+ jr z,l0af8h
do_op_lt:
- jr c,l0af8h ;0aef
- jr l0af7h ;0af1
+ jr c,l0af8h
+ jr l0af7h
do_op_gt:
- jr z,l0af7h ;0af3
+ jr z,l0af7h
do_op_ge:
- jr nc,l0af8h ;0af5
+ jr nc,l0af8h
l0af7h:
- inc hl ;0af7
+ inc hl
l0af8h:
- and a ;0af8
- ret ;0af9
+ and a
+ ret
do_rel_op:
- push hl ;0afa
- ld hl,tab_eq_le_ge ;0afb
- call lookupch ;0afe
- jr nc,l0b28h ;0b01
- ld a,b ;0b03
- or a ;0b04
- jr z,l0b1ch ;0b05
- ld a,(de) ;0b07
- cp '=' ;0b08
- jr nz,l0b11h ;0b0a
- inc de ;0b0c
- inc b ;0b0d
- inc b ;0b0e
- jr l0b1ch ;0b0f
+ push hl
+ ld hl,tab_eq_le_ge
+ call lookupch
+ jr nc,l0b28h
+ ld a,b
+ or a
+ jr z,l0b1ch
+ ld a,(de)
+ cp '='
+ jr nz,l0b11h
+ inc de
+ inc b
+ inc b
+ jr l0b1ch
l0b11h:
- bit 0,b ;0b11
- jr z,l0b1ch ;0b13
- cp '>' ;0b15
- jr nz,l0b1ch ;0b17
- inc de ;0b19
- ld b,005h ;0b1a
+ bit 0,b
+ jr z,l0b1ch
+ cp '>'
+ jr nz,l0b1ch
+ inc de
+ ld b,005h
l0b1ch:
- ld hl,tab_func_eqlege ;0b1c
- ld a,b ;0b1f
- add a,a ;0b20
- call ADD_HL_A ;0b21
- ld c,(hl) ;0b24
- inc hl ;0b25
- ld b,(hl) ;0b26
- scf ;0b27
+ ld hl,tab_func_eqlege
+ ld a,b
+ add a,a
+ call ADD_HL_A
+ ld c,(hl)
+ inc hl
+ ld b,(hl)
+ scf
l0b28h:
- pop hl ;0b28
- ret ;0b29
+ pop hl
+ ret
tab_eq_le_ge:
db '=<>',0
tab_func_eqlege:
- defw do_op_eq ;0b2e
- defw do_op_lt ;0b30
- defw do_op_gt ;0b32
- defw do_op_le ;0b34
- defw do_op_ge ;0b36
- defw do_op_ne ;0b38
+ defw do_op_eq
+ defw do_op_lt
+ defw do_op_gt
+ defw do_op_le
+ defw do_op_ge
+ defw do_op_ne
do_subexpr:
- call do_factor ;0b3a
- ret c ;0b3d
+ call do_factor
+ ret c
l0b3eh:
- call do_binary_op ;0b3e
- push hl ;0b41
- push bc ;0b42
- call do_factor ;0b43
- pop bc ;0b46
- ex de,hl ;0b47
- ex (sp),hl ;0b48
- jr nc,l0b52h ;0b49
- pop de ;0b4b
- ld a,b ;0b4c
- or c ;0b4d
- ret z ;0b4e
- jp ERROR ;0b4f
+ call do_binary_op
+ push hl
+ push bc
+ call do_factor
+ pop bc
+ ex de,hl
+ ex (sp),hl
+ jr nc,l0b52h
+ pop de
+ ld a,b
+ or c
+ ret z
+ jp ERROR
l0b52h:
- ld a,b ;0b52
- or c ;0b53
- push bc ;0b54
- ret nz ;0b55
- pop bc ;0b56
+ ld a,b
+ or c
+ push bc
+ ret nz
+ pop bc
do_op_add:
- add hl,de ;0b57
+ add hl,de
l0b58h:
- pop de ;0b58
- jr l0b3eh ;0b59
+ pop de
+ jr l0b3eh
do_op_sub:
- and a ;0b5b
- sbc hl,de ;0b5c
- jr l0b58h ;0b5e
+ and a
+ sbc hl,de
+ jr l0b58h
do_op_mlt:
- push bc ;0b60
+ push bc
+ if CPU_Z180
ld b,h
ld c,e
ld h,e
@@ -930,462 +929,484 @@ do_op_mlt:
add a,c
add a,e
ld h,a
- pop bc ;0b72
- jr l0b58h ;0b73
+ else
+ ld b,h
+ ld c,l
+ ld hl,0
+ ld a,16
+mlt_1:
+ add hl,hl
+ ex de,hl
+ add hl,hl
+ ex de,hl
+ jr nc,mlt_2
+ add hl,bc
+mlt_2:
+ dec a
+ jr nz,mlt_1
+ endif
+ pop bc
+ jr l0b58h
do_op_div:
- call DIV_HL_DE ;0b75
- jr l0b58h ;0b78
+ call DIV_HL_DE
+ jr l0b58h
do_op_mod:
- call DIV_HL_DE ;0b7a
- ex de,hl ;0b7d
- jr l0b58h ;0b7e
+ call DIV_HL_DE
+ ex de,hl
+ jr l0b58h
+
+; divide x/y
+; hl: x
+; de: y
+; return:
+; hl: q (x/y)
+; de: r (x%y)
DIV_HL_DE:
- push bc ;0b80
- ex de,hl ;0b81
- ld b,h ;0b82
- ld c,l ;0b83
- ld hl,0 ;0b84
- ld a,16 ;0b87
+ push bc
+ ex de,hl ;de = x, hl = y
+ ld b,h ;bc = y
+ ld c,l
+ ld hl,0 ;r = 0
+ ld a,16 ;count
+
+; de: x (x shifted out, q shifted in)
+; bc: y
+; hl: r (initially 0)
+
l0b89h:
- push af ;0b89
- add hl,hl ;0b8a
- ex de,hl ;0b8b
- xor a ;0b8c
- add hl,hl ;0b8d
- ex de,hl ;0b8e
- adc a,l ;0b8f
- sub c ;0b90
- ld l,a ;0b91
- ld a,h ;0b92
- sbc a,b ;0b93
- ld h,a ;0b94
- inc de ;0b95
- jr nc,l0b9ah ;0b96
- add hl,bc ;0b98
- dec de ;0b99
-l0b9ah:
- pop af ;0b9a
- dec a ;0b9b
- jr nz,l0b89h ;0b9c
- ex de,hl ;0b9e
- pop bc ;0b9f
- ret ;0ba0
+ ex de,hl ;x
+ add hl,hl ;x <<= 1
+ ex de,hl ;r
+ adc hl,hl ;r <<= 1
+
+ or a
+ sbc hl,bc
+ inc de
+ jr nc,div_no_restore
+ add hl,bc
+ dec de
+div_no_restore:
+ dec a
+ jr nz,l0b89h
+ ex de,hl ;hl: q de: r
+ pop bc
+ ret
do_op_and:
- ld a,h ;0ba1
- and d ;0ba2
- ld h,a ;0ba3
- ld a,l ;0ba4
- and e ;0ba5
- ld l,a ;0ba6
- jr l0b58h ;0ba7
+ ld a,h
+ and d
+ ld h,a
+ ld a,l
+ and e
+ ld l,a
+ jr l0b58h
do_op_or:
- ld a,h ;0ba9
- or d ;0baa
- ld h,a ;0bab
- ld a,l ;0bac
- or e ;0bad
- ld l,a ;0bae
- jr l0b58h ;0baf
+ ld a,h
+ or d
+ ld h,a
+ ld a,l
+ or e
+ ld l,a
+ jr l0b58h
do_op_xor:
- ld a,h ;0bb1
- xor d ;0bb2
- ld h,a ;0bb3
- ld a,l ;0bb4
- xor e ;0bb5
- ld l,a ;0bb6
- jr l0b58h ;0bb7
+ ld a,h
+ xor d
+ ld h,a
+ ld a,l
+ xor e
+ ld l,a
+ jr l0b58h
do_binary_op:
- push hl ;0bb9
- ld hl,tab_op_a ;0bba
- call lookupch ;0bbd
- ld a,b ;0bc0
- ld hl,tab_func_opa ;0bc1
- add a,a ;0bc4
- call ADD_HL_A ;0bc5
- ld c,(hl) ;0bc8
- inc hl ;0bc9
- ld b,(hl) ;0bca
- pop hl ;0bcb
- ret ;0bcc
+ push hl
+ ld hl,tab_op_a
+ call lookupch
+ ld a,b
+ ld hl,tab_func_opa
+ add a,a
+ call ADD_HL_A
+ ld c,(hl)
+ inc hl
+ ld b,(hl)
+ pop hl
+ ret
tab_op_a:
DB '+-*/%&!#',0
tab_func_opa:
- defw do_op_add ;0bd6
- defw do_op_sub ;0bd8
- defw do_op_mlt ;0bda
- defw do_op_div ;0bdc
- defw do_op_mod ;0bde
- defw do_op_and ;0be0
- defw do_op_or ;0be2
- defw do_op_xor ;0be4
- defw 0 ;0be6
+ defw do_op_add
+ defw do_op_sub
+ defw do_op_mlt
+ defw do_op_div
+ defw do_op_mod
+ defw do_op_and
+ defw do_op_or
+ defw do_op_xor
+ defw 0
fact_factor:
- call do_factor ;0be8
- ret nc ;0beb
- jp ERROR ;0bec
+ call do_factor
+ ret nc
+ jp ERROR
do_factor:
- call chk.sp ;0bef
- call get.number ;0bf2
- ret nc ;0bf5
- inc de ;0bf6
- ld hl,TOPRAM ;0bf7
- cp 'T' ;0bfa
- ret z ;0bfc
- ld hl,(HILOD) ;0bfd
- cp 'H' ;0c00
- ret z ;0c02
- ld hl,(MAXLOD) ;0c03
- cp 'M' ;0c06
- ret z ;0c08
- ld hl,TPA ;0c09
- cp 'L' ;0c0c
- ret z ;0c0e
- ld hl,(offs.@) ;0c0f
- cp '@' ;0c12
- ret z ;0c14
- ld hl,(OFFS.pc) ;0c15
- cp '$' ;0c18
- ret z ;0c1a
- cp '-' ;0c1b
- jr z,fact_factneg ;0c1d
- cp '~' ;0c1f
- jr z,fact_factinv ;0c21
- cp '+' ;0c23
- jr z,fact_factor ;0c25
- cp '^' ;0c27
- jr z,fact_reg.CPU ;0c29
- cp 'Y' ;0c2b
- jr z,fact_reg.Y ;0c2d
- cp '(' ;0c2f
- jr z,fact_mem ;0c31
- cp '[' ;0c33
- jp z,EXPR_BRCKT ;0c35 [ expression ]
- cp '''' ;0c38
- jr z,fact_factstring ;0c3a
- dec de ;0c3c
- scf ;0c3d
- ret ;0c3e
+ call chk.sp
+ call get.number
+ ret nc
+ inc de
+ ld hl,TOPRAM
+ cp 'T'
+ ret z
+ ld hl,(HILOD)
+ cp 'H'
+ ret z
+ ld hl,(MAXLOD)
+ cp 'M'
+ ret z
+ ld hl,TPA
+ cp 'L'
+ ret z
+ ld hl,(offs.@)
+ cp '@'
+ ret z
+ ld hl,(OFFS.pc)
+ cp '$'
+ ret z
+ cp '-'
+ jr z,fact_factneg
+ cp '~'
+ jr z,fact_factinv
+ cp '+'
+ jr z,fact_factor
+ cp '^'
+ jr z,fact_reg.CPU
+ cp 'Y'
+ jr z,fact_reg.Y
+ cp '('
+ jr z,fact_mem
+ cp '['
+ jp z,EXPR_BRCKT ;0c35 [ expression ]
+ cp ''''
+ jr z,fact_factstring
+ dec de
+ scf
+ ret
fact_reg.Y:
- call get.decdigit ;0c3f
- jp c,ERROR ;0c42
- inc de ;0c45
- add a,a ;0c46
- ld hl,reg.Y ;0c47
- call ADD_HL_A ;0c4a
- ld a,(hl) ;0c4d
- inc hl ;0c4e
- ld h,(hl) ;0c4f
- ld l,a ;0c50
- and a ;0c51
- ret ;0c52
+ call get.decdigit
+ jp c,ERROR
+ inc de
+ add a,a
+ ld hl,reg.Y
+ call ADD_HL_A
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+ and a
+ ret
fact_factstring:
- ld hl,0 ;0c53
+ ld hl,0
l0c56h:
- ld a,(de) ;0c56
- cp '''' ;0c57
- jr z,l0c62h ;0c59
- and a ;0c5b
- ret z ;0c5c
+ ld a,(de)
+ cp ''''
+ jr z,l0c62h
+ and a
+ ret z
l0c5dh:
- ld h,l ;0c5d
- ld l,a ;0c5e
- inc de ;0c5f
- jr l0c56h ;0c60
+ ld h,l
+ ld l,a
+ inc de
+ jr l0c56h
l0c62h:
- inc de ;0c62
- ld a,(de) ;0c63
- cp '''' ;0c64
- jr z,l0c5dh ;0c66
- sub '.' ;0c68
- or a ;0c6a
- ret nz ;0c6b
- inc de ;0c6c
- set 7,l ;0c6d
- ret ;0c6f
+ inc de
+ ld a,(de)
+ cp ''''
+ jr z,l0c5dh
+ sub '.'
+ or a
+ ret nz
+ inc de
+ set 7,l
+ ret
fact_reg.CPU:
- call sub_1315h ;0c70
- jr nc,l0cbbh ;0c73
- ld a,(hl) ;0c75
- inc hl ;0c76
- ld h,(hl) ;0c77
- ld l,a ;0c78
- and a ;0c79
- bit 0,c ;0c7a
- ret nz ;0c7c
- ld h,000h ;0c7d
- ret ;0c7f
+ call sub_1315h
+ jr nc,l0cbbh
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+ and a
+ bit 0,c
+ ret nz
+ ld h,000h
+ ret
fact_factneg:
- call fact_factor ;0c80
- dec hl ;0c83
+ call fact_factor
+ dec hl
cpl.hl:
- ld a,h ;0c84
- cpl ;0c85
- ld h,a ;0c86
- ld a,l ;0c87
- cpl ;0c88
- ld l,a ;0c89
- ret ;0c8a
+ ld a,h
+ cpl
+ ld h,a
+ ld a,l
+ cpl
+ ld l,a
+ ret
fact_factinv:
- call fact_factor ;0c8b
- jr cpl.hl ;0c8e
+ call fact_factor
+ jr cpl.hl
fact_mem:
- call EXPR1 ;0c90
- jr c,l0cbbh ;0c93
- ld a,(de) ;0c95
- cp ')' ;0c96
- jr nz,l0cbbh ;0c98
- inc de ;0c9a
+ call EXPR1
+ jr c,l0cbbh
+ ld a,(de)
+ cp ')'
+ jr nz,l0cbbh
+ inc de
comst
- ld a,(hl) ;0c9f
- inc hl ;
- ld h,(hl) ;
+ ld a,(hl)
+ inc hl ;
+ ld h,(hl) ;
comend
- ld l,a ;0ca7
- ld a,(de) ;0ca8
- inc de ;0ca9
- cp '.' ;0caa
- ret z ;0cac
- dec de ;0cad
- xor a ;0cae
- ld h,a ;0caf
- ret ;0cb0
+ ld l,a
+ ld a,(de)
+ inc de
+ cp '.'
+ ret z
+ dec de
+ xor a
+ ld h,a
+ ret
EXPR_BRCKT:
- call EXPR1 ;0cb1
- jr c,l0cbbh ;0cb4
- ld a,(de) ;0cb6
- cp ']' ;0cb7
- inc de ;0cb9
- ret z ;0cba
+ call EXPR1
+ jr c,l0cbbh
+ ld a,(de)
+ cp ']'
+ inc de
+ ret z
l0cbbh:
- jp ERROR ;0cbb
+ jp ERROR
get.number:
- call get.hexdigit ;0cbe
- ret c ;0cc1
- push de ;0cc2
+ call get.hexdigit
+ ret c
+ push de
l0cc3h:
- inc de ;0cc3
- call get.hexdigit ;0cc4
- jr nc,l0cc3h ;0cc7
- pop de ;0cc9
- cp '.' ;0cca
- jr z,l0d04h ;0ccc
- cp '"' ;0cce
- jr z,l0ce9h ;0cd0
- ld hl,0 ;0cd2
+ inc de
+ call get.hexdigit
+ jr nc,l0cc3h
+ pop de
+ cp '.'
+ jr z,l0d04h
+ cp '"'
+ jr z,l0ce9h
+ ld hl,0
l0cd5h:
- call get.hexdigit ;0cd5
- jr c,l0ce4h ;0cd8
- add hl,hl ;0cda
- add hl,hl ;0cdb
- add hl,hl ;0cdc
- add hl,hl ;0cdd
- call ADD_HL_A ;0cde
- inc de ;0ce1
- jr l0cd5h ;0ce2
+ call get.hexdigit
+ jr c,l0ce4h
+ add hl,hl
+ add hl,hl
+ add hl,hl
+ add hl,hl
+ call ADD_HL_A
+ inc de
+ jr l0cd5h
l0ce4h:
- xor 'H' ;0ce4
- ret nz ;0ce6
- inc de ;0ce7
- ret ;0ce8
+ xor 'H'
+ ret nz
+ inc de
+ ret
l0ce9h:
- ld hl,0 ;0ce9
+ ld hl,0
l0cech:
- call get.decdigit ;0cec
+ call get.decdigit
l0cefh:
- inc de ;0cef
- jr c,l0cf8h ;0cf0
- add hl,hl ;0cf2
- call ADD_HL_A ;0cf3
- jr l0cech ;0cf6
+ inc de
+ jr c,l0cf8h
+ add hl,hl
+ call ADD_HL_A
+ jr l0cech
l0cf8h:
- cp '"' ;0cf8
- jp nz,ERROR ;0cfa
- call get.decdigit ;0cfd
- jr nc,l0cefh ;0d00
- or a ;0d02
- ret ;0d03
+ cp '"'
+ jp nz,ERROR
+ call get.decdigit
+ jr nc,l0cefh
+ or a
+ ret
l0d04h:
- ld hl,0 ;0d04
+ ld hl,0
l0d07h:
- call get.decdigit ;0d07
- inc de ;0d0a
- jr c,l0d1ah ;0d0b
- push bc ;0d0d
- add hl,hl ;0d0e hl *= 10
- ld b,h ;0d0f
- ld c,l ;0d10
- add hl,hl ;0d11
- add hl,hl ;0d12
- add hl,bc ;0d13
- pop bc ;0d14
- call ADD_HL_A ;0d15
- jr l0d07h ;0d18
+ call get.decdigit
+ inc de
+ jr c,l0d1ah
+ push bc
+ add hl,hl ;0d0e hl *= 10
+ ld b,h
+ ld c,l
+ add hl,hl
+ add hl,hl
+ add hl,bc
+ pop bc
+ call ADD_HL_A
+ jr l0d07h
l0d1ah:
- cp '.' ;0d1a
- ret z ;0d1c
- jp ERROR ;0d1d
+ cp '.'
+ ret z
+ jp ERROR
sub_0d20h:
- ld a,(de) ;0d20
- cp 05bh ;0d21
- jr l0d28h ;0d23
+ ld a,(de)
+ cp 05bh
+ jr l0d28h
get.hexdigit:
- ld a,(de) ;0d25
+ ld a,(de)
sub_0d26h:
- cp 'F'+1 ;0d26
+ cp 'F'+1
l0d28h:
- ccf ;0d28
- ret c ;0d29
- cp 'A' ;0d2a
- jr c,l0d32h ;0d2c
- sub 'A'-10 ;0d2e
- ret ;0d30
+ ccf
+ ret c
+ cp 'A'
+ jr c,l0d32h
+ sub 'A'-10
+ ret
get.decdigit:
- ld a,(de) ;0d31
+ ld a,(de)
l0d32h:
- cp '9'+1 ;0d32
- jr l0d39h ;0d34
+ cp '9'+1
+ jr l0d39h
get.bindigit:
- ld a,(de) ;0d36
- cp '1'+1 ;0d37
+ ld a,(de)
+ cp '1'+1
l0d39h:
- ccf ;0d39
- ret c ;0d3a
- cp '0' ;0d3b
- ret c ;0d3d
- sub '0' ;0d3e
- ret ;0d40
+ ccf
+ ret c
+ cp '0'
+ ret c
+ sub '0'
+ ret
l0d41h:
- call assert_eol ;0d41
+ call assert_eol
prnt_cpustat:
- call prnt_f ;0d44
- call outbl2 ;0d47
- ld hl,b_0x0DFD_start ;0d4a
- ld de,b_0x0E1D_start ;0d4d
- ld b,006h ;0d50
+ call prnt_f
+ call outbl2
+ ld hl,b_0x0DFD_start
+ ld de,b_0x0E1D_start
+ ld b,006h
l0d52h:
- call prnt_regs ;0d52
- djnz l0d52h ;0d55
- push hl ;0d57
- push de ;0d58
- ld iy,(REG.PC) ;0d59
- call sub_1f77h ;0d5d
- exx ;0d60
- ex af,af' ;0d61
- call CRLF ;0d62
- call prnt_f2 ;0d65
- call outbl2 ;0d68
- pop de ;0d6b
- pop hl ;0d6c
- ld b,007h ;0d6d
+ call prnt_regs
+ djnz l0d52h
+ push hl
+ push de
+ ld iy,(REG.PC)
+ call sub_1f77h
+ exx
+ ex af,af'
+ call CRLF
+ call prnt_f2
+ call outbl2
+ pop de
+ pop hl
+ ld b,007h
l0d6fh:
- call prnt_regs ;0d6f
- djnz l0d6fh ;0d72
- exx ;0d74
- ex af,af' ;0d75
- and a ;0d76
- jr z,l0d7fh ;0d77
- call outbl6 ;0d79
- call sub_1f5bh ;0d7c
+ call prnt_regs
+ djnz l0d6fh
+ exx
+ ex af,af'
+ and a
+ jr z,l0d7fh
+ call outbl6
+ call sub_1f5bh
l0d7fh:
- jp crlf ;0d7f
+ jp crlf
prnt_f:
- ld a,(reg.f) ;0d82
- call prnt_flags ;0d85
- ld a,(reg.iff) ;0d88
- cp 0f3h ;0d8b
- jp z,outbl ;0d8d
- ld a,'E' ;0d90
- jp outchar ;0d92
+ ld a,(reg.f)
+ call prnt_flags
+ ld a,(reg.iff)
+ cp 0f3h
+ jp z,outbl
+ ld a,'E'
+ jp outchar
prnt_f2:
- ld a,(reg.f2) ;0d95
- call prnt_flags ;0d98
- jp outbl ;0d9b
+ ld a,(reg.f2)
+ call prnt_flags
+ jp outbl
prnt_flags:
- ld b,a ;0d9e
- ld a,'S' ;0d9f
- call sub_0dbeh ;0da1
- ld a,'Z' ;0da4
- call sub_0dbeh ;0da6
- rl b ;0da9
- ld a,'H' ;0dab
- call sub_0dbeh ;0dad
- rl b ;0db0
- ld a,'V' ;0db2
- call sub_0dbeh ;0db4
- ld a,'N' ;0db7
- call sub_0dbeh ;0db9
- ld a,'C' ;0dbc
+ ld b,a
+ ld a,'S'
+ call sub_0dbeh
+ ld a,'Z'
+ call sub_0dbeh
+ rl b
+ ld a,'H'
+ call sub_0dbeh
+ rl b
+ ld a,'V'
+ call sub_0dbeh
+ ld a,'N'
+ call sub_0dbeh
+ ld a,'C'
sub_0dbeh:
- rl b ;0dbe
- jp c,OUTCHAR ;0dc0
- jp OUTBL ;0dc3
+ rl b
+ jp c,OUTCHAR
+ jp OUTBL
prnt_regs:
- push bc ;0dc6
- push de ;0dc7
- call PSTR ;0dc8
- ld a,'=' ;0dcb
- call OUTCHAR ;0dcd
- ex (sp),hl ;0dd0
- ld e,(hl) ;0dd1
- inc hl ;0dd2
- ld d,(hl) ;0dd3
- inc hl ;0dd4
- ld a,(hl) ;0dd5
- inc hl ;0dd6
- push hl ;0dd7
- and a ;0dd8
- jr z,l0df2h ;0dd9
- push af ;0ddb
- ld a,(de) ;0ddc
- ld l,a ;0ddd
- inc de ;0dde
- ld a,(de) ;0ddf
- ld h,a ;0de0
- pop af ;0de1
- dec a ;0de2
- jr z,l0dedh ;0de3
- call out.hl.@ ;0de5
- call z,outbl6 ;0de8
- jr l0df6h ;0deb
+ push bc
+ push de
+ call PSTR
+ ld a,'='
+ call OUTCHAR
+ ex (sp),hl
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ inc hl
+ ld a,(hl)
+ inc hl
+ push hl
+ and a
+ jr z,l0df2h
+ push af
+ ld a,(de)
+ ld l,a
+ inc de
+ ld a,(de)
+ ld h,a
+ pop af
+ dec a
+ jr z,l0dedh
+ call out.hl.@
+ call z,outbl6
+ jr l0df6h
l0dedh:
- call out.hl ;0ded
- jr l0df6h ;0df0
+ call out.hl
+ jr l0df6h
l0df2h:
- ld a,(de) ;0df2
- call out.hex ;0df3
+ ld a,(de)
+ call out.hex
l0df6h:
- call OUTBL ;0df6
- pop de ;0df9
- pop hl ;0dfa
- pop bc ;0dfb
- ret ;0dfc
+ call OUTBL
+ pop de
+ pop hl
+ pop bc
+ ret
b_0x0DFD_start:
DC 'A '
@@ -1404,522 +1425,510 @@ b_0x0DFD_start:
DB 0
b_0x0E1D_start:
- defw reg.a ;0e1d
- defb 000h ;0e1f
- defw reg.c ;0e20
- defb 001h ;0e22
- defw reg.e ;0e23
- defb 001h ;0e25
- defw reg.l ;0e26
- defb 001h ;0e28
- defw reg.sp ;0e29
- defb 001h ;0e2b
- defw reg.pc ;0e2c
- defb 002h ;0e2e
- defw reg.a2 ;0e2f
- defb 000h ;0e31
- defw reg.c2 ;0e32
- defb 001h ;0e34
- defw reg.e2 ;0e35
- defb 001h ;0e37
- defw reg.l2 ;0e38
- defb 001h ;0e3a
- defw reg.ix ;0e3b
- defb 001h ;0e3d
- defw reg.iy ;0e3e
- defb 001h ;0e40
- defw reg.i ;0e41
- dw 0 ;0e43
+ defw reg.a
+ defb 000h
+ defw reg.c
+ defb 001h
+ defw reg.e
+ defb 001h
+ defw reg.l
+ defb 001h
+ defw reg.sp
+ defb 001h
+ defw reg.pc
+ defb 002h
+ defw reg.a2
+ defb 000h
+ defw reg.c2
+ defb 001h
+ defw reg.e2
+ defb 001h
+ defw reg.l2
+ defb 001h
+ defw reg.ix
+ defb 001h
+ defw reg.iy
+ defb 001h
+ defw reg.i
+ dw 0
CMD.G:
- sub a ;0e45
- ld (TCFLG),a ;0e46
- ld (XA747),a ;0e49
- call EXPR ;0e4c
- jr c,l0e54h ;0e4f
- ld (REG.PC),hl ;0e51
+ sub a
+ ld (TCFLG),a
+ ld (XA747),a
+ call EXPR
+ jr c,l0e54h
+ ld (REG.PC),hl
l0e54h:
- call SKIPBL ;0e54
- jp z,l1183h ;0e57
- cp ';' ;0e5a
- jp nz,ERROR ;0e5c
- inc de ;0e5f
- ld a,002h ;0e60
- call sub_0f24h ;0e62
- jp l1183h ;0e65
+ call SKIPBL
+ jp z,l1183h
+ cp ';'
+ jp nz,ERROR
+ inc de
+ ld a,002h
+ call sub_0f24h
+ jp l1183h
sub_0e68h:
- ld b,BP_CNT ;0e68
- ld ix,bp_tab ;0e6a
+ ld b,BP_CNT
+ ld ix,bp_tab
l0e6eh:
- ld a,(ix+000h) ;0e6e
- and 0f1h ;0e71
- ld (ix+000h),a ;0e73
- call sub_11c5h ;0e76
- ld de,BP_SIZE ;0e79
- add ix,de ;0e7c
- djnz l0e6eh ;0e7e
- ret ;0e80
+ ld a,(ix+000h)
+ and 0f1h
+ ld (ix+000h),a
+ call sub_11c5h
+ ld de,BP_SIZE
+ add ix,de
+ djnz l0e6eh
+ ret
CMD.B:
- call SKIPBL ;0e81
- jr z,l0ecbh ;0e84
- inc de ;0e86
- cp 'X' ;0e87
- jr z,l0e91h ;0e89
- dec de ;0e8b
- ld a,001h ;0e8c
- jp sub_0f24h ;0e8e
+ call SKIPBL
+ jr z,l0ecbh
+ inc de
+ cp 'X'
+ jr z,l0e91h
+ dec de
+ ld a,001h
+ jp sub_0f24h
l0e91h:
- call SKIPBL ;0e91
- jr z,l0ea6h ;0e94
+ call SKIPBL
+ jr z,l0ea6h
l0e96h:
- call EXPR ;0e96
- jp c,assert_eol ;0e99
- push de ;0e9c
- call sub_0ea7h ;0e9d
- pop de ;0ea0
- call skip_to_nextarg ;0ea1
- jr l0e96h ;0ea4
+ call EXPR
+ jp c,assert_eol
+ push de
+ call sub_0ea7h
+ pop de
+ call skip_to_nextarg
+ jr l0e96h
l0ea6h:
- scf ;0ea6
+ scf
sub_0ea7h:
- ld b,BP_CNT ;0ea7
- ld ix,bp_tab ;0ea9
+ ld b,BP_CNT
+ ld ix,bp_tab
l0eadh:
- push af ;0ead
- jr c,l0ebbh ;0eae
- ld e,(ix+002h) ;0eb0
- ld d,(ix+003h) ;0eb3
- call CP.HL.DE ;0eb6
- jr nz,l0ec2h ;0eb9
+ push af
+ jr c,l0ebbh
+ ld e,(ix+002h)
+ ld d,(ix+003h)
+ call CP.HL.DE
+ jr nz,l0ec2h
l0ebbh:
- ld (ix+000h),000h ;0ebb
- call sub_11c5h ;0ebf
+ ld (ix+000h),000h
+ call sub_11c5h
l0ec2h:
- ld de,BP_SIZE ;0ec2
- add ix,de ;0ec5
- pop af ;0ec7
- djnz l0eadh ;0ec8
- ret ;0eca
+ ld de,BP_SIZE
+ add ix,de
+ pop af
+ djnz l0eadh
+ ret
l0ecbh:
- ld b,BP_CNT ;0ecb
- ld ix,bp_tab ;0ecd
+ ld b,BP_CNT
+ ld ix,bp_tab
l0ed1h:
- bit 0,(ix+000h) ;0ed1
- jr z,l0f1ch ;0ed5
- ld a,'R' ;0ed7
- bit 4,(ix+000h) ;0ed9
- jr nz,l0ee1h ;0edd
- ld a,' ' ;0edf
+ bit 0,(ix+000h)
+ jr z,l0f1ch
+ ld a,'R'
+ bit 4,(ix+000h)
+ jr nz,l0ee1h
+ ld a,' '
l0ee1h:
- call OUTCHAR ;0ee1
- call OUTBL ;0ee4
- ld l,(ix+002h) ;0ee7
- ld h,(ix+003h) ;0eea
- call out.hl.@ ;0eed
- call outbl2 ;0ef0
- ld a,':' ;0ef3
- call OUTCHAR ;0ef5
- ld l,(ix+004h) ;0ef8
- ld h,(ix+005h) ;0efb
- call out.hl ;0efe
- ld l,(ix+006h) ;0f01
- ld h,(ix+007h) ;0f04
- ld a,h ;0f07
- or l ;0f08
- jr z,l0f19h ;0f09
- call outbl4 ;0f0b
- ld a,'I' ;0f0e
- call OUTCHAR ;0f10
- call outbl2 ;0f13
- call PSTR ;0f16
+ call OUTCHAR
+ call OUTBL
+ ld l,(ix+002h)
+ ld h,(ix+003h)
+ call out.hl.@
+ call outbl2
+ ld a,':'
+ call OUTCHAR
+ ld l,(ix+004h)
+ ld h,(ix+005h)
+ call out.hl
+ ld l,(ix+006h)
+ ld h,(ix+007h)
+ ld a,h
+ or l
+ jr z,l0f19h
+ call outbl4
+ ld a,'I'
+ call OUTCHAR
+ call outbl2
+ call PSTR
l0f19h:
- call CRLF ;0f19
+ call CRLF
l0f1ch:
- ld de,BP_SIZE ;0f1c
- add ix,de ;0f1f
- djnz l0ed1h ;0f21
- ret ;0f23
+ ld de,BP_SIZE
+ add ix,de
+ djnz l0ed1h
+ ret
sub_0f24h:
- ld b,a ;0f24
- call SKIPBL ;0f25
- ret z ;0f28
- cp 'R' ;0f29
- jr nz,l0f30h ;0f2b
- inc de ;0f2d
- set 4,b ;0f2e
+ ld b,a
+ call SKIPBL
+ ret z
+ cp 'R'
+ jr nz,l0f30h
+ inc de
+ set 4,b
l0f30h:
- push bc ;0f30
- call EXPR ;0f31
- jp c,ERROR ;0f34
- pop bc ;0f37
- bit 0,b ;0f38
- push bc ;0f3a
- push de ;0f3b
- push hl ;0f3c
- call nz,sub_0ea7h ;0f3d
- pop hl ;0f40
- call sub_0f68h ;0f41
- pop de ;0f44
- ld (ix+002h),l ;0f45
- ld (ix+003h),h ;0f48
- call sub_0f80h ;0f4b
- ld (ix+004h),l ;0f4e
- ld (ix+005h),h ;0f51
- call sub_0f91h ;0f54
- ld (ix+006h),l ;0f57
- ld (ix+007h),h ;0f5a
- call skip_to_nextarg ;0f5d
- pop af ;0f60
- ld (ix+000h),a ;0f61
- and 00fh ;0f64
- jr sub_0f24h ;0f66
+ push bc
+ call EXPR
+ jp c,ERROR
+ pop bc
+ bit 0,b
+ push bc
+ push de
+ push hl
+ call nz,sub_0ea7h
+ pop hl
+ call sub_0f68h
+ pop de
+ ld (ix+002h),l
+ ld (ix+003h),h
+ call sub_0f80h
+ ld (ix+004h),l
+ ld (ix+005h),h
+ call sub_0f91h
+ ld (ix+006h),l
+ ld (ix+007h),h
+ call skip_to_nextarg
+ pop af
+ ld (ix+000h),a
+ and 00fh
+ jr sub_0f24h
sub_0f68h:
- ld b,BP_CNT ;0f68
- ld ix,bp_tab ;0f6a
+ ld b,BP_CNT
+ ld ix,bp_tab
l0f6eh:
- ld a,(ix+000h) ;0f6e
- and 00fh ;0f71
- ret z ;0f73
- push bc ;0f74
- ld bc,BP_SIZE ;0f75
- add ix,bc ;0f78
- pop bc ;0f7a
- djnz l0f6eh ;0f7b
- jp ERROR ;0f7d
+ ld a,(ix+000h)
+ and 00fh
+ ret z
+ push bc
+ ld bc,BP_SIZE
+ add ix,bc
+ pop bc
+ djnz l0f6eh
+ jp ERROR
sub_0f80h:
- call SKIPBL ;0f80
- ld hl,1 ;0f83
- cp 03ah ;0f86
- ret nz ;0f88
- inc de ;0f89
- call EXPR ;0f8a
- jp c,ERROR ;0f8d
- ret ;0f90
+ call SKIPBL
+ ld hl,1
+ cp 03ah
+ ret nz
+ inc de
+ call EXPR
+ jp c,ERROR
+ ret
sub_0f91h:
- call SKIPBL ;0f91
- cp 049h ;0f94
- ld hl,0 ;0f96
- ret nz ;0f99
- inc de ;0f9a
- call SKIPBL ;0f9b
- push de ;0f9e
- call EXPR ;0f9f
- jp c,ERROR ;0fa2
- ex de,hl ;0fa5
- pop de ;0fa6
- push de ;0fa7
- sbc hl,de ;0fa8
- ld b,h ;0faa
- ld c,l ;0fab
- ld hl,(sexp1) ;0fac
- push hl ;0faf
- add hl,bc ;0fb0
- ld de,sexpbufe ;0fb1
- call CP.HL.DE ;0fb4
- jp nc,ERROR ;0fb7
- pop hl ;0fba
- ld (sexp2),hl ;0fbb
- pop de ;0fbe
- ex de,hl ;0fbf
- ldir ;0fc0
- xor a ;0fc2
- ld (de),a ;0fc3
- inc de ;0fc4
- ex de,hl ;0fc5
- ld (sexp1),hl ;0fc6
- ld hl,(sexp2) ;0fc9
- ret ;0fcc
+ call SKIPBL
+ cp 049h
+ ld hl,0
+ ret nz
+ inc de
+ call SKIPBL
+ push de
+ call EXPR
+ jp c,ERROR
+ ex de,hl
+ pop de
+ push de
+ sbc hl,de
+ ld b,h
+ ld c,l
+ ld hl,(sexp1)
+ push hl
+ add hl,bc
+ ld de,sexpbufe
+ call CP.HL.DE
+ jp nc,ERROR
+ pop hl
+ ld (sexp2),hl
+ pop de
+ ex de,hl
+ ldir
+ xor a
+ ld (de),a
+ inc de
+ ex de,hl
+ ld (sexp1),hl
+ ld hl,(sexp2)
+ ret
bpddtz:
if ROMSYS
- ld h,ROMEN ;0fcd
- jr z,l0fd2h ;0fcf
- inc h ;0fd1
+ ld h,ROMEN
+ jr z,l0fd2h
+ inc h
l0fd2h:
- push hl ;0fd2 save rom enable stat
+ push hl ;save rom enable stat
+ endif
+ push bc
+ push de
+ push ix
+ push iy
+ ld a,i
+ ld h,a
+ ld l,000h
+ push hl ;save I register
+
+ if CPU_Z180
+ ld a,0f3h ;DI
+ jp po,l0fe6h
+ ld a,0fbh ;EI
+ else ;NMOS Z80 design flaw
+ call getiff ;return Carry set, if INTs are disabled.
+ ld a,0f3h ;DI
+ jr c,l0fe6h
+ ld a,0fbh ;EI
endif
- push bc ;0fd3
- push de ;0fd4
- push ix ;0fd5
- push iy ;0fd7
- ld a,i ;0fd9
- ld h,a ;0fdb
- ld l,000h ;0fdc
- push hl ;0fde
- ld a,0f3h ;0fdf DI
- jp po,l0fe6h ;0fe1
- ld a,0fbh ;0fe4 EI
l0fe6h:
- ld (reg.iff),a ;0fe6
- ld hl,ivtab ;0fe9
- ld a,h ;0fec
- ld i,a ;0fed
- call ddtei ;0fef
- ex af,af' ;0ff2
- push af ;0ff3
- exx ;0ff4
- push bc ;0ff5
- push de ;0ff6
- push hl ;0ff7
- call bp.unset ;0ff8
- in0 a,(itc) ;0ffb
- jp p,l1017h ;0ffe
- res TRAP,a ;1001
- out0 (itc),a ;1003
- bit UFO,a ;1006
- jr z,l1011h ;1008
- ld hl,(REG.PC) ;100a
- dec hl ;100d
- ld (REG.PC),hl ;100e
+ ld (reg.iff),a
+ ld hl,ivtab
+ ld a,h
+ ld i,a
+ call ddtei
+ ex af,af'
+ push af
+ exx
+ push bc
+ push de
+ push hl
+ call bp.unset
+ if CPU_Z180
+ in0 a,(itc)
+ jp p,l1017h
+ res TRAP,a
+ out0 (itc),a
+ bit UFO,a
+ jr z,l1011h
+ ld hl,(REG.PC)
+ dec hl
+ ld (REG.PC),hl
l1011h:
- ld hl,MSG_trap ;1011
- call PSTR ;1014
+ ld hl,MSG_trap
+ call PSTR
l1017h:
- ld a,(XBFE8) ;1017
- dec a ;101a
- jr z,l1051h ;101b
- call inchar ;101d
- jr c,l102eh ;1020
- call sub_1059h ;1022
- and a ;1025
- jp z,l1183h ;1026
- and 083h ;1029
- jp z,l284ah ;102b
+ endif
+
+ ld a,(XBFE8)
+ dec a
+ jr z,l1051h
+ call inchar
+ jr c,l102eh
+ call sub_1059h
+ and a
+ jp z,l1183h
+ and 083h
+ jp z,l284ah
l102eh:
- call sub_0e68h ;102e
- call prnt_cpustat ;1031
- jp DDTZML ;1034
+ call sub_0e68h
+ call prnt_cpustat
+ jp DDTZML
+ if CPU_Z180
MSG_trap:
DB CR,LF,'Undefined opcode trap'
DB CR,LF,0
+ endif
l1051h:
- ld (XBFE8),a ;1051
- ld c,007h ;1054
- jp l119fh ;1056
+ ld (XBFE8),a
+ ld c,007h
+ jp l119fh
sub_1059h:
- ld a,080h ;1059
- ex af,af' ;105b
- sub a ;105c
- ld (XA747),a ;105d
- ld b,BP_CNT ;1060
- ld ix,bp_tab ;1062
+ ld a,080h
+ ex af,af'
+ sub a
+ ld (XA747),a
+ ld b,BP_CNT
+ ld ix,bp_tab
l1066h:
- ld a,(ix+000h) ;1066
- and 007h ;1069
- jr z,l107eh ;106b
- ld e,(ix+002h) ;106d
- ld d,(ix+003h) ;1070
- ld hl,(REG.PC) ;1073
- call CP.HL.DE ;1076
- push bc ;1079
- call z,sub_1087h ;107a
- pop bc ;107d
+ ld a,(ix+000h)
+ and 007h
+ jr z,l107eh
+ ld e,(ix+002h)
+ ld d,(ix+003h)
+ ld hl,(REG.PC)
+ call CP.HL.DE
+ push bc
+ call z,sub_1087h
+ pop bc
l107eh:
- ld de,BP_SIZE ;107e
- add ix,de ;1081
- djnz l1066h ;1083
- ex af,af' ;1085
- ret ;1086
+ ld de,BP_SIZE
+ add ix,de
+ djnz l1066h
+ ex af,af'
+ ret
sub_1087h:
- ex af,af' ;1087
- res 7,a ;1088
- ex af,af' ;108a
- ld e,(ix+006h) ;108b
- ld d,(ix+007h) ;108e
- ld a,d ;1091
- or e ;1092
- ld hl,0ffffh ;1093
- call nz,EXPR ;1096
- ld a,h ;1099
- or l ;109a
- jr z,l10aeh ;109b
- ld e,(ix+004h) ;109d
- ld d,(ix+005h) ;10a0
- dec de ;10a3
- ld a,d ;10a4
- or e ;10a5
- jr z,l10b9h ;10a6
- ld (ix+004h),e ;10a8
- ld (ix+005h),d ;10ab
+ ex af,af'
+ res 7,a
+ ex af,af'
+ ld e,(ix+006h)
+ ld d,(ix+007h)
+ ld a,d
+ or e
+ ld hl,0ffffh
+ call nz,EXPR
+ ld a,h
+ or l
+ jr z,l10aeh
+ ld e,(ix+004h)
+ ld d,(ix+005h)
+ dec de
+ ld a,d
+ or e
+ jr z,l10b9h
+ ld (ix+004h),e
+ ld (ix+005h),d
l10aeh:
- bit 4,(ix+000h) ;10ae
- ret z ;10b2
- ld a,001h ;10b3
- ld (XA747),a ;10b5
- ret ;10b8
+ bit 4,(ix+000h)
+ ret z
+ ld a,001h
+ ld (XA747),a
+ ret
l10b9h:
- ex af,af' ;10b9
- or (ix+000h) ;10ba
- ex af,af' ;10bd
+ ex af,af'
+ or (ix+000h)
+ ex af,af'
ret
bp.unset:
- ld b,BP_CNT ;10bf
- ld ix,bp_tab ;10c1
+ ld b,BP_CNT
+ ld ix,bp_tab
l10c5h:
- bit 5,(ix+000h) ;10c5
- res 5,(ix+000h) ;10c9
- jr z,l10e7h ;10cd
- ld l,(ix+002h) ;10cf
- ld h,(ix+003h) ;10d2
- ld a,(ddtrst) ;10d5
- comst ;10e2
- cp (hl) ;10dc
+ bit 5,(ix+000h)
+ res 5,(ix+000h)
+ jr z,l10e7h
+ ld l,(ix+002h)
+ ld h,(ix+003h)
+ ld a,(ddtzrst)
+ comst
+ cp (hl)
comend
- jr nz,l10e7h ;10dd
- ld a,(ix+001h) ;10df
- comst ;10e2
- ld (hl),a ;10e6
+ jr nz,l10e7h
+ ld a,(ix+001h)
+ comst
+ ld (hl),a
comend
l10e7h:
- res 3,(ix+000h) ;10e7
- ld de,BP_SIZE ;10eb
- add ix,de ;10ee
- djnz l10c5h ;10f0
- ret ;10f2
+ res 3,(ix+000h)
+ ld de,BP_SIZE
+ add ix,de
+ djnz l10c5h
+ ret
sub_10f3h:
- ld b,BP_CNT ;10f3
- ld ix,bp_tab ;10f5
+ ld b,BP_CNT
+ ld ix,bp_tab
l10f9h:
- ld a,(ix+000h) ;10f9
- and 003h ;10fc
- jr z,l110dh ;10fe
- ld e,(ix+002h) ;1100
- ld d,(ix+003h) ;1103
- ld hl,(REG.PC) ;1106
- call CP.HL.DE ;1109
- ret z ;110c
+ ld a,(ix+000h)
+ and 003h
+ jr z,l110dh
+ ld e,(ix+002h)
+ ld d,(ix+003h)
+ ld hl,(REG.PC)
+ call CP.HL.DE
+ ret z
l110dh:
- ld de,BP_SIZE ;110d
- add ix,de ;1110
- djnz l10f9h ;1112
- sub a ;1114
- inc a ;1115
- ret ;1116
+ ld de,BP_SIZE
+ add ix,de
+ djnz l10f9h
+ sub a
+ inc a
+ ret
sub_1117h:
- call sub_0f68h ;1117
- ld (ix+004h),001h ;111a
- ld (ix+005h),000h ;111e
- ld (ix+002h),l ;1122
- ld (ix+003h),h ;1125
- ld (ix+006h),000h ;1128
- ld (ix+007h),000h ;112c
- ld a,(XBFE8) ;1130
- and a ;1133
- ld a,008h ;1134
- jr nz,l113ah ;1136
- ld a,004h ;1138
+ call sub_0f68h
+ ld (ix+004h),001h
+ ld (ix+005h),000h
+ ld (ix+002h),l
+ ld (ix+003h),h
+ ld (ix+006h),000h
+ ld (ix+007h),000h
+ ld a,(XBFE8)
+ and a
+ ld a,008h
+ jr nz,l113ah
+ ld a,004h
l113ah:
- ld (ix+000h),a ;113a
- ret ;113d
+ ld (ix+000h),a
+ ret
bp.set:
- ld b,BP_CNT ;113e
- ld ix,bp_tab ;1140
+ ld b,BP_CNT
+ ld ix,bp_tab
l1144h:
- ld a,(ix+000h) ;1144
- and c ;1147
- jr z,l117bh ;1148
- set 5,(ix+000h) ;114a
- ld l,(ix+002h) ;114e
- ld h,(ix+003h) ;1151
-
- if 0
-
- comst ;1154
- ld a,(hl) ;1158
- comend
- ld (ix+001h),a ;1159
- ld a,(ddtrst) ;115c
- comst ;115f
- ld (hl),a ;1163
- comend
- and 038h ;1164
- ld h,000h ;1166
- ld l,a ;1168
- ld a,0c3h ;1169
- comrep ;116b
- inc hl ;116e
- ld de,bpent ;116f
- ld a,e ;1172
- comrep ;1173
- inc hl ;1176
- ld a,d ;1177
- comrep ;1178
+ ld a,(ix+000h)
+ and c
+ jr z,l117bh
+ set 5,(ix+000h)
+ ld l,(ix+002h)
+ ld h,(ix+003h)
- else
- ld a,(ddtrst) ;115c
- comst ;115f
- ld e,(hl) ;1158
- ld (hl),a ;1163
+ ld a,(ddtzrst)
+ comst
+ ld e,(hl)
+ ld (hl),a
comend
- ld (ix+001h),e ;1159
- and 038h ;1164
- ld h,0 ;1166
- ld l,a ;1168
- ld de,bpent ;116f
+ ld (ix+001h),e
+ and 038h
+ ld h,0
+ ld l,a
+ ld de,bpent
comst ;
- ld (hl),0c3h ;1169
- inc hl ;116e
- ld (hl),e ;1172
- inc hl ;1176
- ld (hl),d ;1177
+ ld (hl),0c3h
+ inc hl
+ ld (hl),e
+ inc hl
+ ld (hl),d
comend
- endif
-
+
l117bh:
- ld de,BP_SIZE ;117b
- add ix,de ;117e
- djnz l1144h ;1180
+ ld de,BP_SIZE
+ add ix,de
+ djnz l1144h
ret
- ;1182
+
l1183h:
- sub a ;1183
- ld (XBFE8),a ;1184
- ld a,(XA747) ;1187
- and a ;118a
- call nz,prnt_cpustat ;118b
- call sub_10f3h ;118e
- ld c,007h ;1191
- jr nz,l119fh ;1193
- ld a,001h ;1195
- ld (XBFE8),a ;1197
- call sub_26e7h ;119a
- ld c,008h ;119d
+ sub a
+ ld (XBFE8),a
+ ld a,(XA747)
+ and a
+ call nz,prnt_cpustat
+ call sub_10f3h
+ ld c,007h
+ jr nz,l119fh
+ ld a,001h
+ ld (XBFE8),a
+ call sub_26e7h
+ ld c,008h
l119fh:
- call bp.set ;119f
+ call bp.set
ld sp,$stack ;11a2 set/restore user cpu state
- pop hl ;11a5
- pop de ;11a6
- pop bc ;11a7
- pop af ;11a8
- exx ;11a9
- ex af,af' ;11aa
- pop af ;11ab
- ld i,a ;11ac
- pop iy ;11ae
- pop ix ;11b0
- pop de ;11b2
- pop bc ;11b3
+ pop hl
+ pop de
+ pop bc
+ pop af
+ exx
+ ex af,af'
+ pop af
+ ld i,a
+ pop iy
+ pop ix
+ pop de
+ pop bc
if ROMSYS
- pop hl ;11b4
- ld a,l ;11b5
- and M_MWI ;11b6
- ld l,a ;11b8
- di ;11b9
- in0 a,(dcntl) ;11ba
- and ~M_MWI ;11bd
- or l ;11bf
- ld l,a ;11c0
- ld a,h ;11c1
+ pop hl
+ ld a,l
+ and M_MWI
+ ld l,a
+ di
+ in0 a,(dcntl)
+ and ~M_MWI
+ or l
+ ld l,a
+ ld a,h
else
pop hl
di
@@ -1927,227 +1936,234 @@ l119fh:
jp $go ;11c2 common ram, switch banks and go to user prog
sub_11c5h:
- ld a,(ix+000h) ;11c5
- and 003h ;11c8
- ret nz ;11ca
- ld e,(ix+006h) ;11cb
- ld d,(ix+007h) ;11ce
- ld a,d ;11d1
- or e ;11d2
- ret z ;11d3
- push bc ;11d4
- ld h,d ;11d5
- ld l,e ;11d6
- sub a ;11d7
- ld (ix+006h),a ;11d8
- ld (ix+007h),a ;11db
- ld bc,0ffffh ;11de
- cpir ;11e1
+ ld a,(ix+000h)
+ and 003h
+ ret nz
+ ld e,(ix+006h)
+ ld d,(ix+007h)
+ ld a,d
+ or e
+ ret z
+ push bc
+ ld h,d
+ ld l,e
+ sub a
+ ld (ix+006h),a
+ ld (ix+007h),a
+ ld bc,0ffffh
+ cpir
l11e3h:
- push de ;11e3
- ld de,(sexp1) ;11e4
- call CP.HL.DE ;11e8
- pop de ;11eb
- jr nc,l11f9h ;11ec
- call sub_11ffh ;11ee
+ push de
+ ld de,(sexp1)
+ call CP.HL.DE
+ pop de
+ jr nc,l11f9h
+ call sub_11ffh
l11f1h:
- ld a,(hl) ;11f1
- ldi ;11f2
- and a ;11f4
- jr nz,l11f1h ;11f5
- jr l11e3h ;11f7
+ ld a,(hl)
+ ldi
+ and a
+ jr nz,l11f1h
+ jr l11e3h
l11f9h:
- ld (sexp1),de ;11f9
- pop bc ;11fd
- ret ;11fe
+ ld (sexp1),de
+ pop bc
+ ret
sub_11ffh:
- ld iy,bp_tab ;11ff
- push de ;1203
+ ld iy,bp_tab
+ push de
l1204h:
- ld e,(iy+006h) ;1204
- ld d,(iy+007h) ;1207
- call CP.HL.DE ;120a
- jr z,l1216h ;120d
- ld de,BP_SIZE ;120f
- add iy,de ;1212
- jr l1204h ;1214
+ ld e,(iy+006h)
+ ld d,(iy+007h)
+ call CP.HL.DE
+ jr z,l1216h
+ ld de,BP_SIZE
+ add iy,de
+ jr l1204h
l1216h:
- pop de ;1216
- ld (iy+006h),e ;1217
- ld (iy+007h),d ;121a
- ret ;121d
+ pop de
+ ld (iy+006h),e
+ ld (iy+007h),d
+ ret
CMD.Y:
- call get.decdigit ;121e
- jr c,l122fh ;1221
- inc de ;1223
- push af ;1224
- call assert_eol ;1225
- pop af ;1228
- call sub_1248h ;1229
- jp l127ch ;122c
+ call get.decdigit
+ jr c,l122fh
+ inc de
+ push af
+ call assert_eol
+ pop af
+ call sub_1248h
+ jp l127ch
l122fh:
- call assert_eol ;122f
- xor a ;1232
+ call assert_eol
+ xor a
l1233h:
- push af ;1233
- call sub_1248h ;1234
- call outbl4 ;1237
- pop af ;123a
- inc a ;123b
- bit 0,a ;123c
- push af ;123e
- call z,CRLF ;123f
- pop af ;1242
- cp LF ;1243
- jr c,l1233h ;1245
- ret ;1247
+ push af
+ call sub_1248h
+ call outbl4
+ pop af
+ inc a
+ bit 0,a
+ push af
+ call z,CRLF
+ pop af
+ cp LF
+ jr c,l1233h
+ ret
sub_1248h:
- ld c,a ;1248
- ld b,0 ;1249
- add a,'0'+080h ;124b
- ld de,msg.Y+1 ;124d
- ld (de),a ;1250
- dec de ;1251
- ld hl,reg.Y ;1252
- add hl,bc ;1255
- add hl,bc ;1256
- ex de,hl ;1257
- ld c,003h ;1258
- jp l129ah ;125a
+ ld c,a
+ ld b,0
+ add a,'0'+080h
+ ld de,msg.Y+1
+ ld (de),a
+ dec de
+ ld hl,reg.Y
+ add hl,bc
+ add hl,bc
+ ex de,hl
+ ld c,003h
+ jp l129ah
CMD.X:
- call SKIPBL ;125d
- call sub_1315h ;1260
- jp nc,l0d41h ;1263
- call assert_eol ;1266
- ld a,b ;1269
- cp 01fh ;126a
- jr z,l12c6h ;126c
- cp 020h ;126e
- jr z,l12b6h ;1270
- ex de,hl ;1272
- ld hl,b_0x132A_start ;1273
- call sub_0a48h ;1276
+ call SKIPBL
+ call sub_1315h
+ jp nc,l0d41h
+ call assert_eol
+ ld a,b
+ cp 01fh
+ jr z,l12c6h
+ cp 020h
+ jr z,l12b6h
+ ex de,hl
+ ld hl,b_0x132A_start
+ call sub_0a48h
l1279h:
- call l129ah ;1279
+ call l129ah
l127ch:
- call OUTBL ;127c
- push de ;127f
- push bc ;1280
- call INLINE ;1281
- call SKIPBL ;1284
- jr z,l1297h ;1287
- call get_arg ;1289
- ld b,h ;128c
- ld c,l ;128d
- pop af ;128e
- pop hl ;128f
- ld (hl),c ;1290
- bit 0,a ;1291
- ret z ;1293
- inc hl ;1294
- ld (hl),b ;1295
- ret ;1296
+ call OUTBL
+ push de
+ push bc
+ call INLINE
+ call SKIPBL
+ jr z,l1297h
+ call get_arg
+ ld b,h
+ ld c,l
+ pop af
+ pop hl
+ ld (hl),c
+ bit 0,a
+ ret z
+ inc hl
+ ld (hl),b
+ ret
l1297h:
- pop af ;1297
- pop hl ;1298
- ret ;1299
+ pop af
+ pop hl
+ ret
l129ah:
- ld b,c ;129a
- call PSTR ;129b
- ld a,'=' ;129e
- call OUTCHAR ;12a0
- ld a,(de) ;12a3
- bit 0,b ;12a4
- jp z,out.hex ;12a6
- ld l,a ;12a9
- inc de ;12aa
- ld a,(de) ;12ab
- dec de ;12ac
- ld h,a ;12ad
- bit 1,b ;12ae
- jp z,out.hl ;12b0
- jp out.hl.@ ;12b3
+ ld b,c
+ call PSTR
+ ld a,'='
+ call OUTCHAR
+ ld a,(de)
+ bit 0,b
+ jp z,out.hex
+ ld l,a
+ inc de
+ ld a,(de)
+ dec de
+ ld h,a
+ bit 1,b
+ jp z,out.hl
+ jp out.hl.@
l12b6h:
- call prnt_f ;12b6
- ld a,0f3h ;12b9
- ld (reg.iff),a ;12bb
- scf ;12be
- call sub_12d1h ;12bf
- ld (reg.f),a ;12c2
- ret ;12c5
+ call prnt_f
+ ld a,0f3h
+ ld (reg.iff),a
+ scf
+ call sub_12d1h
+ ld (reg.f),a
+ ret
l12c6h:
- call prnt_f2 ;12c6
- and a ;12c9
- call sub_12d1h ;12ca
- ld (reg.f2),a ;12cd
- ret ;12d0
+ call prnt_f2
+ and a
+ call sub_12d1h
+ ld (reg.f2),a
+ ret
sub_12d1h:
- ex af,af' ;12d1
- ld b,000h ;12d2
- call outbl ;12d4
- call assert_eol ;12d7
- call inline ;12da
+ ex af,af'
+ ld b,000h
+ call outbl
+ call assert_eol
+ call inline
l12ddh:
- call skipbl ;12dd
- ld a,b ;12e0
- ret z ;12e1
- push bc ;12e2
- ld hl,tab_pr_flags ;12e3
- call lookupch ;12e6
- jp nc,error ;12e9
- ld a,b ;12ec
- cp 008h ;12ed
- jr z,l12feh ;12ef
- inc b ;12f1
- ld a,001h ;12f2
- jr l12f7h ;12f4
+ call skipbl
+ ld a,b
+ ret z
+ push bc
+ ld hl,tab_pr_flags
+ call lookupch
+ jp nc,error
+ ld a,b
+ cp 008h
+ jr z,l12feh
+ inc b
+ ld a,001h
+ jr l12f7h
l12f6h:
- rlca ;12f6
+ rlca
l12f7h:
- djnz l12f6h ;12f7
- pop bc ;12f9
- or b ;12fa
- ld b,a ;12fb
- jr l12ddh ;12fc
+ djnz l12f6h
+ pop bc
+ or b
+ ld b,a
+ jr l12ddh
l12feh:
- ex af,af' ;12fe
- jp nc,ERROR ;12ff
- ex af,af' ;1302
- ld a,0FBh ;1303
- ld (reg.iff),a ;1305
- pop bc ;1308
- jr l12ddh ;1309
+ ex af,af'
+ jp nc,ERROR
+ ex af,af'
+ ld a,0FBh
+ ld (reg.iff),a
+ pop bc
+ jr l12ddh
tab_pr_flags:
db 'CNV H ZSE'
db 0
sub_1315h:
- call sub_0a0eh ;1315
- ret nc ;1318
- ld a,b ;1319
- add a,b ;131a
- add a,b ;131b
- ld hl,b_0x136C_start ;131c
- call ADD_HL_A ;131f
- ld c,(hl) ;1322
- inc hl ;1323
- ld a,(hl) ;1324
- inc hl ;1325
- ld h,(hl) ;1326
- ld l,a ;1327
- scf ;1328
- ret ;1329
+ call sub_0a0eh
+ ret nc
+ ld a,b
+ add a,b
+ add a,b
+ ld hl,b_0x136C_start
+ call ADD_HL_A
+ ld c,(hl)
+ inc hl
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+ scf
+ ret
b_0x132A_start:
+ if ROMSYS
+ DC 'ROMSEL'
+ endif
+ if CPU_Z180
DC 'CBAR'
DC 'BBR'
+ else
+ DC 'BNK'
+ endif
DC 'BC'''
DC 'DE'''
DC 'HL'''
@@ -2179,659 +2195,667 @@ b_0x132A_start:
DC 'I'
DC 'F'''
DC 'F'
- if ROMSYS
- DC 'ROMSEL'
- endif
DB 0
b_0x136C_start:
- defb 000h ;136c
- defw ucbar ;136d
- defb 000h ;136f
- defw ubbr ;1370
- defb 003h ;1372
- defw reg.c2 ;1373
- defb 003h ;1375
- defw reg.e2 ;1376
- defb 003h ;1378
- defw reg.l2 ;1379
- defb 003h ;137b
- defw reg.c ;137c
- defb 003h ;137e
- defw reg.e ;137f
- defb 003h ;1381
- defw reg.l ;1382
- defb 000h ;1384
- defw reg.a2 ;1385
- defb 000h ;1387
- defw reg.b2 ;1388
- defb 000h ;138a
- defw reg.c2 ;138b
- defb 000h ;138d
- defw reg.d2 ;138e
- defb 000h ;1390
- defw reg.e2 ;1391
- defb 000h ;1393
- defw reg.h2 ;1394
- defb 000h ;1396
- defw reg.l2 ;1397
- defb 000h ;1399
- defw reg.a ;139a
- defb 000h ;139c
- defw reg.b ;139d
- defb 000h ;139f
- defw reg.c ;13a0
- defb 000h ;13a2
- defw reg.d ;13a3
- defb 000h ;13a5
- defw reg.e ;13a6
- defb 000h ;13a8
- defw reg.h ;13a9
- defb 000h ;13ab
- defw reg.l ;13ac
- defb 003h ;13ae
- defw reg.ix ;13af
- defb 003h ;13b1
- defw reg.iy ;13b2
- defb 003h ;13b4
- defw reg.sp ;13b5
- defb 003h ;13b7
- defw reg.pc ;13b8
- defb 003h ;13ba
- defw reg.ix ;13bb
- defb 003h ;13bd
- defw reg.iy ;13be
- defb 003h ;13c0
- defw reg.sp ;13c1
- defb 003h ;13c3
- defw reg.pc ;13c4
- defb 000h ;13c6
- defw reg.i ;13c7
- defb 000h ;13c9
- defw reg.f2 ;13ca
- defb 000h ;13cc
- defw reg.f ;13cd
- if ROMSYS
- defb 000h ;13cf
- defw uromen ;13d0
+ if ROMSYS
+ defb 000h
+ defw uromen
+ endif
+ if CPU_Z180
+ defb 000h
+ defw ucbar
+ defb 000h
+ defw ubbr
+ else
+ defb 000h
+ defw ubnk
endif
+ defb 003h
+ defw reg.c2
+ defb 003h
+ defw reg.e2
+ defb 003h
+ defw reg.l2
+ defb 003h
+ defw reg.c
+ defb 003h
+ defw reg.e
+ defb 003h
+ defw reg.l
+ defb 000h
+ defw reg.a2
+ defb 000h
+ defw reg.b2
+ defb 000h
+ defw reg.c2
+ defb 000h
+ defw reg.d2
+ defb 000h
+ defw reg.e2
+ defb 000h
+ defw reg.h2
+ defb 000h
+ defw reg.l2
+ defb 000h
+ defw reg.a
+ defb 000h
+ defw reg.b
+ defb 000h
+ defw reg.c
+ defb 000h
+ defw reg.d
+ defb 000h
+ defw reg.e
+ defb 000h
+ defw reg.h
+ defb 000h
+ defw reg.l
+ defb 003h
+ defw reg.ix
+ defb 003h
+ defw reg.iy
+ defb 003h
+ defw reg.sp
+ defb 003h
+ defw reg.pc
+ defb 003h
+ defw reg.ix
+ defb 003h
+ defw reg.iy
+ defb 003h
+ defw reg.sp
+ defb 003h
+ defw reg.pc
+ defb 000h
+ defw reg.i
+ defb 000h
+ defw reg.f2
+ defb 000h
+ defw reg.f
CMD.S:
- ld hl,(lst.S) ;13d2
- call get_lastarg_def ;13d5
+ ld hl,(lst.S)
+ call get_lastarg_def
l13d8h:
- ld (lst.S),hl ;13d8
- call out.hl.@ ;13db
- call OUTBL ;13de
- comst ;13e1
- ld a,(hl) ;13e5
+ ld (lst.S),hl
+ call out.hl.@
+ call OUTBL
+ comst
+ ld a,(hl)
comend
- call out.hex ;13e6
- call outbl2 ;13e9
- call INLINE ;13ec
- call SKIPBL ;13ef
- inc hl ;13f2
- jr z,l13d8h ;13f3
- dec hl ;13f5
- inc de ;13f6
- cp '.' ;13f7
- jp z,assert_eol ;13f9
- cp '-' ;13fc
- jr nz,l1406h ;13fe
- ld a,(de) ;1400
- or a ;1401
- dec hl ;1402
- jr z,l13d8h ;1403
- inc hl ;1405
+ call out.hex
+ call outbl2
+ call INLINE
+ call SKIPBL
+ inc hl
+ jr z,l13d8h
+ dec hl
+ inc de
+ cp '.'
+ jp z,assert_eol
+ cp '-'
+ jr nz,l1406h
+ ld a,(de)
+ or a
+ dec hl
+ jr z,l13d8h
+ inc hl
l1406h:
- dec de ;1406
- call get_bytes_m ;1407
- jr l13d8h ;140a
+ dec de
+ call get_bytes_m
+ jr l13d8h
CMD.@:
- call assert_eol ;140c
- ld hl,MSG_at ;140f
- ld de,offs.@ ;1412
- ld c,001h ;1415
- jp l1279h ;1417
+ call assert_eol
+ ld hl,MSG_at
+ ld de,offs.@
+ ld c,001h
+ jp l1279h
MSG_at:
dc '@'
CMD.I:
- ld hl,CMD.I ;141b
- ld (CMD_RPT),hl ;141e
- ld hl,(lst.IP) ;1421
- call get_lastarg_def ;1424
- ld (lst.IP),hl ;1427
- ld b,h ;142a
- ld c,l ;142b
- ld a,b ;142c
- or a ;142d
- jr nz,l1442h ;142e
- ld a,c ;1430
- ld hl,ucbar ;1431
- cp cbar ;1434
- jr z,l143fh ;1436
- ld hl,ubbr ;1438
- cp bbr ;143b
- jr nz,l1442h ;143d
+ ld hl,CMD.I
+ ld (CMD_RPT),hl
+ ld hl,(lst.IP)
+ call get_lastarg_def
+ ld (lst.IP),hl
+ ld b,h
+ ld c,l
+ if CPU_Z180
+ ld a,b
+ or a
+ jr nz,l1442h
+ ld a,c
+ ld hl,ucbar
+ cp cbar
+ jr z,l143fh
+ ld hl,ubbr
+ cp bbr
+ jr nz,l1442h
l143fh:
- ld a,(hl) ;143f
- jr l1444h ;1440
+ ld a,(hl)
+ jr l1444h
l1442h:
- in a,(c) ;1442
+ endif
+ in a,(c)
l1444h:
- push af ;1444
- call out.hex ;1445
- call outbl4 ;1448
- pop af ;144b
- call out.bin.b ;144c
- jp CRLF ;144f
+ push af
+ call out.hex
+ call outbl4
+ pop af
+ call out.bin.b
+ jp CRLF
CMD.O:
- ld hl,CMD.O ;1452
- ld (CMD_RPT),hl ;1455
- ld hl,(lst.OD) ;1458
- call get_arg_def ;145b
- ld a,l ;145e
- ld (lst.OD),a ;145f
- push af ;1462
- call skip_to_nextarg ;1463
- ld hl,(lst.OP) ;1466
- call get_lastarg_def ;1469
- ld (lst.OP),hl ;146c
- ld b,h ;146f
- ld c,l ;1470
- ld a,b ;1471
- or a ;1472
- jr nz,l1489h ;1473
- ld a,c ;1475
- ld hl,ucbar ;1476
- cp cbar ;1479
- jr z,l148dh ;147b
- ld hl,ubbr ;147d
- cp bbr ;1480
- jr z,l148dh ;1482
- cp cbr ;1484
- jp z,ERROR ;1486
+ ld hl,CMD.O
+ ld (CMD_RPT),hl
+ ld hl,(lst.OD)
+ call get_arg_def
+ ld a,l
+ ld (lst.OD),a
+ push af
+ call skip_to_nextarg
+ ld hl,(lst.OP)
+ call get_lastarg_def
+ ld (lst.OP),hl
+ ld b,h
+ ld c,l
+ if CPU_Z180
+ ld a,b
+ or a
+ jr nz,l1489h
+ ld a,c
+ ld hl,ucbar
+ cp cbar
+ jr z,l148dh
+ ld hl,ubbr
+ cp bbr
+ jr z,l148dh
+ cp cbr
+ jp z,ERROR
l1489h:
- pop af ;1489
- out (c),a ;148a
- ret ;148c
+ endif
+ pop af
+ out (c),a
+ ret
+ if CPU_Z180
l148dh:
- pop af ;148d
- ld (hl),a ;148e
- ret ;148f
+ pop af
+ ld (hl),a
+ ret
+ endif
CMD.V:
- call get_arg3 ;1490 get from, size, to
+ call get_arg3 ;1490 get from, size, to
cmp_mem:
- push bc ;1493
- comst ;1494
- ld a,(de) ;1498
- ld b,(hl) ;1499
+ push bc
+ comst
+ ld a,(de)
+ ld b,(hl)
comend
- cp b ;149a
- jr z,l14bah ;149b
- ld c,a ;149d
- call out.hl.@ ;149e
- call OUTBL ;14a1
- ld a,b ;14a4
- call out.hex ;14a5
- call outbl2 ;14a8
- ld a,c ;14ab
- call out.hex ;14ac
- call OUTBL ;14af
- ex de,hl ;14b2
- call out.hl.@ ;14b3
- ex de,hl ;14b6
- call CRLF ;14b7
+ cp b
+ jr z,l14bah
+ ld c,a
+ call out.hl.@
+ call OUTBL
+ ld a,b
+ call out.hex
+ call outbl2
+ ld a,c
+ call out.hex
+ call OUTBL
+ ex de,hl
+ call out.hl.@
+ ex de,hl
+ call CRLF
l14bah:
- pop bc ;14ba
- inc hl ;14bb
- inc de ;14bc
- dec bc ;14bd
- ld a,b ;14be
- or c ;14bf
- jr nz,cmp_mem ;14c0
- ret ;14c2
+ pop bc
+ inc hl
+ inc de
+ dec bc
+ ld a,b
+ or c
+ jr nz,cmp_mem
+ ret
CMD.M:
- ld a,(de) ;14c3
- cp 'V' ;14c4
- jr nz,bm_nv ;14c6
- inc de ;14c8
+ ld a,(de)
+ cp 'V'
+ jr nz,bm_nv
+ inc de
bm_nv:
- push af ;14c9 save 'V' flag
- call get_arg3 ;14ca
- push hl ;14cd
- push de ;14ce
- push bc ;14cf
- call CP.HL.DE ;14d0
- jr nc,bm_mvdown ;14d3
- add hl,bc ;14d5
- ex de,hl ;14d6
- add hl,bc ;14d7
- ex de,hl ;14d8
- dec hl ;14d9
- dec de ;14da
- comst ;14db
- lddr ;14df
+ push af ;14c9 save 'V' flag
+ call get_arg3
+ push hl
+ push de
+ push bc
+ call CP.HL.DE
+ jr nc,bm_mvdown
+ add hl,bc
+ ex de,hl
+ add hl,bc
+ ex de,hl
+ dec hl
+ dec de
+ comst
+ lddr
comend
- jr bm_done ;14e1
+ jr bm_done
bm_mvdown:
- comst ;14e3
- ldir ;14e7
+ comst
+ ldir
comend
bm_done:
- pop bc ;14e9
- pop de ;14ea
- pop hl ;14eb
- pop af ;14ec
- jr z,cmp_mem ;14ed validate?
- ret ;14ef
+ pop bc
+ pop de
+ pop hl
+ pop af
+ jr z,cmp_mem ;14ed validate?
+ ret
CMD.H:
- call EXPR ;14f0
- jp c,l173ch ;14f3
- call skip_to_nextarg ;14f6
- push hl ;14f9
- call EXPR ;14fa
- push af ;14fd
- call assert_eol ;14fe
- pop af ;1501
- ex de,hl ;1502
- pop hl ;1503
- jr c,l1511h ;1504
- push hl ;1506
- push de ;1507
- add hl,de ;1508
- call l1511h ;1509
- pop de ;150c
- pop hl ;150d
- and a ;150e
- sbc hl,de ;150f
+ call EXPR
+ jp c,l173ch
+ call skip_to_nextarg
+ push hl
+ call EXPR
+ push af
+ call assert_eol
+ pop af
+ ex de,hl
+ pop hl
+ jr c,l1511h
+ push hl
+ push de
+ add hl,de
+ call l1511h
+ pop de
+ pop hl
+ and a
+ sbc hl,de
l1511h:
- call out.hl ;1511 val
- call outbl2 ;1514
- call sub_0928h ;1517 -val
- call outbl4 ;151a
- call out.hl.dec ;151d dec
- call outbl2 ;1520
- call out.hl.decm ;1523 -dec
- call outbl4 ;1526
- call out.bin.w ;1529 bin
- call outbl2 ;152c
- ld a,l ;152f
- call out.ascii ;1530
- jp CRLF ;1533
+ call out.hl ;1511 val
+ call outbl2
+ call sub_0928h ;1517 -val
+ call outbl4
+ call out.hl.dec ;151d dec
+ call outbl2
+ call out.hl.decm ;1523 -dec
+ call outbl4
+ call out.bin.w ;1529 bin
+ call outbl2
+ ld a,l
+ call out.ascii
+ jp CRLF
CMD.Q:
- ld a,(de) ;1536
- sub 'J' ;1537
- ld (lst.Qj),a ;1539
- jr nz,l153fh ;153c
- inc de ;153e
+ ld a,(de)
+ sub 'J'
+ ld (lst.Qj),a
+ jr nz,l153fh
+ inc de
l153fh:
- call get_arg_range ;153f
- push bc ;1542
- push hl ;1543
- call sub_15a7h ;1544
- pop hl ;1547
+ call get_arg_range
+ push bc
+ push hl
+ call sub_15a7h
+ pop hl
l1548h:
- call sub_1594h ;1548
- jr nz,l1562h ;154b
- push bc ;154d
- push hl ;154e
- ld a,(lst.Qj) ;154f
- or a ;1552
- jr nz,l1559h ;1553
- ld bc,-8 ;1555
- add hl,bc ;1558
+ call sub_1594h
+ jr nz,l1562h
+ push bc
+ push hl
+ ld a,(lst.Qj)
+ or a
+ jr nz,l1559h
+ ld bc,-8
+ add hl,bc
l1559h:
- ld bc,MEMDUMP_CNT ;1559
- and a ;155c
- call memdump ;155d
- pop hl ;1560
- pop bc ;1561
+ ld bc,MEMDUMP_CNT
+ and a
+ call memdump
+ pop hl
+ pop bc
l1562h:
- inc hl ;1562
- ex (sp),hl ;1563
- dec hl ;1564
- ld a,h ;1565
- or l ;1566
- ex (sp),hl ;1567
- jr nz,l1548h ;1568
- pop bc ;156a
- ret ;156b
+ inc hl
+ ex (sp),hl
+ dec hl
+ ld a,h
+ or l
+ ex (sp),hl
+ jr nz,l1548h
+ pop bc
+ ret
CMD.Z:
- call get_arg_range ;156c
- push bc ;156f
- push hl ;1570
- call sub_15a7h ;1571
- ld a,b ;1574
- pop hl ;1575
- pop bc ;1576
- push hl ;1577
- ex de,hl ;1578
+ call get_arg_range
+ push bc
+ push hl
+ call sub_15a7h
+ ld a,b
+ pop hl
+ pop bc
+ push hl
+ ex de,hl
l1579h:
- push af ;1579
- ld a,(hl) ;157a
- comst ;157b
- ld (de),a ;157f
+ push af
+ ld a,(hl)
+ comst
+ ld (de),a
comend
- pop af ;1580
- inc de ;1581
- cpi ;1582
- jp po,l1592h ;1584
- dec a ;1587
- jr nz,l1579h ;1588
- pop hl ;158a
- comst ;158b
- ldir ;158f
+ pop af
+ inc de
+ cpi
+ jp po,l1592h
+ dec a
+ jr nz,l1579h
+ pop hl
+ comst
+ ldir
comend
- ret ;1591
+ ret
l1592h:
- pop hl ;1592
- ret ;1593
+ pop hl
+ ret
sub_1594h:
- push hl ;1594
- push de ;1595
- push bc ;1596
+ push hl
+ push de
+ push bc
l1597h:
- ld a,(de) ;1597
- comst ;1598
- cp (hl) ;159c
+ ld a,(de)
+ comst
+ cp (hl)
comend
- jr nz,l15a3h ;159d
- inc de ;159f
- inc hl ;15a0
- djnz l1597h ;15a1
+ jr nz,l15a3h
+ inc de
+ inc hl
+ djnz l1597h
l15a3h:
- pop bc ;15a3
- pop de ;15a4
- pop hl ;15a5
- ret ;15a6
+ pop bc
+ pop de
+ pop hl
+ ret
sub_15a7h:
- ld hl,ci.buf+1 ;15a7
- call get_bytes ;15aa
- ld de,ci.buf+1 ;15ad
- and a ;15b0
- sbc hl,de ;15b1
- ld b,l ;15b3
- ret nz ;15b4
- jp ERROR ;15b5
+ ld hl,ci.buf+1
+ call get_bytes
+ ld de,ci.buf+1
+ and a
+ sbc hl,de
+ ld b,l
+ ret nz
+ jp ERROR
get_bytes:
db 0e6h ;15b8 and 037h (clear carry, skip next opc)
get_bytes_m:
scf
l15bah:
- push af ;15ba
- call skip_to_nextarg ;15bb
- cp 'W' ;15be
- jr nz,l15d9h ;15c0
- inc de ;15c2
- push hl ;15c3
- call sub_0a68h ;15c4
- ex de,hl ;15c7
- pop bc ;15c8
- pop af ;15c9
- push af ;15ca
- push bc ;15cb
- ex (sp),hl ;15cc
- jr nc,l15d3h ;15cd
- comst ;15cf
+ push af
+ call skip_to_nextarg
+ cp 'W'
+ jr nz,l15d9h
+ inc de
+ push hl
+ call sub_0a68h
+ ex de,hl
+ pop bc
+ pop af
+ push af
+ push bc
+ ex (sp),hl
+ jr nc,l15d3h
+ comst
l15d3h:
- ld (hl),e ;15d3
+ ld (hl),e
comend
- inc hl ;15d4
- ld c,d ;15d5
- pop de ;15d6
- jr l15e5h ;15d7
+ inc hl
+ ld c,d
+ pop de
+ jr l15e5h
l15d9h:
- cp '''' ;15d9
- jr z,l15f1h ;15db
- push hl ;15dd
- call EXPR ;15de
- ld c,l ;15e1
- pop hl ;15e2
- jr c,l1626h ;15e3
+ cp ''''
+ jr z,l15f1h
+ push hl
+ call EXPR
+ ld c,l
+ pop hl
+ jr c,l1626h
l15e5h:
- pop af ;15e5
- push af ;15e6
- jr nc,l15edh ;15e7
- comst ;15e9
+ pop af
+ push af
+ jr nc,l15edh
+ comst
l15edh:
- ld (hl),c ;15ed
+ ld (hl),c
comend
- inc hl ;15ee
- jr l161eh ;15ef
+ inc hl
+ jr l161eh
l15f1h:
- inc de ;15f1
- ld a,(de) ;15f2
- cp '''' ;15f3
- jr z,l1607h ;15f5
- or a ;15f7
- jr z,l1626h ;15f8
+ inc de
+ ld a,(de)
+ cp ''''
+ jr z,l1607h
+ or a
+ jr z,l1626h
l15fah:
- ld c,a ;15fa
- pop af ;15fb
- push af ;15fc
- jr nc,l1603h ;15fd
- comst ;15ff
+ ld c,a
+ pop af
+ push af
+ jr nc,l1603h
+ comst
l1603h:
- ld (hl),c ;1603
+ ld (hl),c
comend
- inc hl ;1604
- jr l15f1h ;1605
+ inc hl
+ jr l15f1h
l1607h:
- inc de ;1607
- ld a,(de) ;1608
- cp '''' ;1609
- jr z,l15fah ;160b
- cp '.' ;160d
- jr nz,l161eh ;160f
- inc de ;1611
- dec hl ;1612
- pop af ;1613
- push af ;1614
- jr nc,l161bh ;1615
- comst ;1617
+ inc de
+ ld a,(de)
+ cp ''''
+ jr z,l15fah
+ cp '.'
+ jr nz,l161eh
+ inc de
+ dec hl
+ pop af
+ push af
+ jr nc,l161bh
+ comst
l161bh:
- set 7,(hl) ;161b
+ set 7,(hl)
comend
- inc hl ;161d
+ inc hl
l161eh:
- pop af ;161e
- jr nc,l15bah ;161f
- ld (lst.S),hl ;1621
- jr l15bah ;1624
+ pop af
+ jr nc,l15bah
+ ld (lst.S),hl
+ jr l15bah
l1626h:
- pop af ;1626
- ret nc ;1627
- ld (lst.S),hl ;1628
- ret ;162b
+ pop af
+ ret nc
+ ld (lst.S),hl
+ ret
CMD.D:
- ld hl,CMD.D ;162c
- ld (CMD_RPT),hl ;162f
- ld hl,(lst.D) ;1632
- ld bc,00080h ;1635
- call sub_0a82h ;1638
- scf ;163b
+ ld hl,CMD.D
+ ld (CMD_RPT),hl
+ ld hl,(lst.D)
+ ld bc,00080h
+ call sub_0a82h
+ scf
memdump:
- push bc ;163c
- push de ;163d
- push hl ;163e
- ex af,af' ;163f
+ push bc
+ push de
+ push hl
+ ex af,af'
l1640h:
- call out.hl.@ ;1640
- call z,outbl2 ;1643
- call OUTBL ;1646
- ld de,0 ;1649
+ call out.hl.@
+ call z,outbl2
+ call OUTBL
+ ld de,0
l164ch:
- comst ;164c
- ld a,(hl) ;1650
+ comst
+ ld a,(hl)
comend
- inc hl ;1651
- call out.hex ;1652
- call OUTBL ;1655
- dec bc ;1658
- inc e ;1659
- ld a,e ;165a
- cp 010h ;165b
- jr z,l1668h ;165d
- and 003h ;165f
- call z,OUTBL ;1661
- ld a,b ;1664
- or c ;1665
- jr nz,l164ch ;1666
+ inc hl
+ call out.hex
+ call OUTBL
+ dec bc
+ inc e
+ ld a,e
+ cp 010h
+ jr z,l1668h
+ and 003h
+ call z,OUTBL
+ ld a,b
+ or c
+ jr nz,l164ch
l1668h:
- call OUTBL ;1668
- and a ;166b
- sbc hl,de ;166c
+ call OUTBL
+ and a
+ sbc hl,de
l166eh:
- comst ;166e
- ld a,(hl) ;1672
+ comst
+ ld a,(hl)
comend
- call sub_168fh ;1673
- call OUTCHAR ;1676
- inc hl ;1679
- dec e ;167a
- jr nz,l166eh ;167b
- ex af,af' ;167d
- jr nc,l1683h ;167e
- ld (lst.D),hl ;1680
+ call sub_168fh
+ call OUTCHAR
+ inc hl
+ dec e
+ jr nz,l166eh
+ ex af,af'
+ jr nc,l1683h
+ ld (lst.D),hl
l1683h:
- ex af,af' ;1683
- call CRLF ;1684
- ld a,b ;1687
- or c ;1688
- jr nz,l1640h ;1689
- pop hl ;168b
- pop de ;168c
- pop bc ;168d
- ret ;168e
+ ex af,af'
+ call CRLF
+ ld a,b
+ or c
+ jr nz,l1640h
+ pop hl
+ pop de
+ pop bc
+ ret
sub_168fh:
- and 07fh ;168f
- cp 07fh ;1691
- jr z,l1698h ;1693
- cp 020h ;1695
- ret nc ;1697
+ and 07fh
+ cp 07fh
+ jr z,l1698h
+ cp 020h
+ ret nc
l1698h:
- ld a,02eh ;1698
- ret ;169a
+ ld a,02eh
+ ret
; Read Intel Hex File from console.
CMD.R:
- ld hl,0 ;169b
+ ld hl,0
call get_lastarg_def ;169e get offset from command line
- push hl ;16a1
- ld hl,0 ;16a2
- ld (HILOD),hl ;16a5
+ push hl
+ ld hl,0
+ ld (HILOD),hl
w_recstart:
- call i.getchar ;16a8
- jr z,l16deh ;16ab
- cp ':' ;16ad
- jr nz,w_recstart ;16af
+ call i.getchar
+ jr z,l16deh
+ cp ':'
+ jr nz,w_recstart
ld c,0 ;16b1 init checksum
call i.gethexbyte ;16b3 record len
- ld b,a ;16b6
+ ld b,a
call i.gethexbyte ;16b7 address high
- ld h,a ;16ba
+ ld h,a
call i.gethexbyte ;16bb address low
- ld l,a ;16be
+ ld l,a
call i.gethexbyte ;16bf record type (ignored)
- ld a,b ;16c2
+ ld a,b
and a ;16c3 record len == 0?
- jr z,l16deh ;16c4
+ jr z,l16deh
l16c6h:
- call i.gethexbyte ;16c6
+ call i.gethexbyte
pop de ;16c9 offset
- push de ;16ca
- push hl ;16cb
- add hl,de ;16cc
- call i.storebyte ;16cd
- pop hl ;16d0
- inc hl ;16d1
+ push de
+ push hl
+ add hl,de
+ call i.storebyte
+ pop hl
+ inc hl
djnz l16c6h ;16d2 repeat for record len
call i.gethexbyte ;16d4 checksum
- ld a,c ;16d7
- and a ;16d8
+ ld a,c
+ and a
jp nz,ERROR ;16d9 exit if checksum error
jr w_recstart ;16dc next record
l16deh:
- pop hl ;16de
- call i.gethexbyte ;16df
- jp l173fh ;16e2
+ pop hl
+ call i.gethexbyte
+ jp l173fh
i.gethexbyte:
- call sub_16f6h ;16e5
- rlca ;16e8
- rlca ;16e9
- rlca ;16ea
- rlca ;16eb
- ld d,a ;16ec
- call sub_16f6h ;16ed
- add a,d ;16f0
- ld d,a ;16f1
- add a,c ;16f2
- ld c,a ;16f3
- ld a,d ;16f4
- ret ;16f5
+ call sub_16f6h
+ rlca
+ rlca
+ rlca
+ rlca
+ ld d,a
+ call sub_16f6h
+ add a,d
+ ld d,a
+ add a,c
+ ld c,a
+ ld a,d
+ ret
sub_16f6h:
- call i.getchar ;16f6
- jr z,l16ffh ;16f9
- call sub_0d26h ;16fb
- ret nc ;16fe
+ call i.getchar
+ jr z,l16ffh
+ call sub_0d26h
+ ret nc
l16ffh:
- jp ERROR ;16ff
+ jp ERROR
i.getchar:
- call $ci ;1702
- cp 01ah ;1705
- ret ;1707
+ call $ci
+ cp 01ah
+ ret
i.storebyte:
- push af ;1708
- push de ;1709
+ push af
+ push de
ld de,TPA ;170a lowest allowed load address
- call CP.HL.DE ;170d
- jp c,ERROR ;1710
+ call CP.HL.DE
+ jp c,ERROR
ld de,$stcka ;1713 highest allowed load address
- call CP.HL.DE ;1716
- jp nc,ERROR ;1719
- ld de,(HILOD) ;171c
- call CP.HL.DE ;1720
- jr c,l1728h ;1723
- ld (HILOD),hl ;1725
+ call CP.HL.DE
+ jp nc,ERROR
+ ld de,(HILOD)
+ call CP.HL.DE
+ jr c,l1728h
+ ld (HILOD),hl
l1728h:
- ld de,(MAXLOD) ;1728
- call CP.HL.DE ;172c
- jr c,l1734h ;172f
- ld (MAXLOD),hl ;1731
+ ld de,(MAXLOD)
+ call CP.HL.DE
+ jr c,l1734h
+ ld (MAXLOD),hl
l1734h:
- pop de ;1734
- pop af ;1735
- comst ;1736
+ pop de
+ pop af
+ comst
ld (hl),a ;173a store byte
comend
- ret ;173b
+ ret
l173ch:
- call assert_eol ;173c
+ call assert_eol
l173fh:
- ld hl,MSG_high ;173f
- call PSTR ;1742
- ld hl,(HILOD) ;1745
- call out.hl ;1748
- ld hl,MSG_max ;174b
- call PSTR ;174e
- ld hl,(MAXLOD) ;1751
- call out.hl ;1754
- jp CRLF ;1757
+ ld hl,MSG_high
+ call PSTR
+ ld hl,(HILOD)
+ call out.hl
+ ld hl,MSG_max
+ call PSTR
+ ld hl,(MAXLOD)
+ call out.hl
+ jp CRLF
MSG_high:
DC 'High = '
@@ -2839,1067 +2863,1067 @@ MSG_max:
DC ' Max = '
CMD.A:
- ld hl,(lst.A) ;1769
- call get_lastarg_def ;176c
- push hl ;176f
- pop iy ;1770
- ld hl,l17c4h ;1772
- ld (CMD_ERR),hl ;1775
- ld (XB068),sp ;1778
+ ld hl,(lst.A)
+ call get_lastarg_def
+ push hl
+ pop iy
+ ld hl,l17c4h
+ ld (CMD_ERR),hl
+ ld (XB068),sp
l177ch:
- push iy ;177c
- pop hl ;177e
- ld (lst.A),hl ;177f
- ld (OFFS.pc),hl ;1782
- push hl ;1785
- call sub_1f3fh ;1786
- pop iy ;1789
- ld c,b ;178b
- ld de,(offs.@) ;178c
- ld a,d ;1790
- or e ;1791
- ld b,011h ;1792
- jr z,l1798h ;1794
- ld b,019h ;1796
+ push iy
+ pop hl
+ ld (lst.A),hl
+ ld (OFFS.pc),hl
+ push hl
+ call sub_1f3fh
+ pop iy
+ ld c,b
+ ld de,(offs.@)
+ ld a,d
+ or e
+ ld b,011h
+ jr z,l1798h
+ ld b,019h
l1798h:
- call OUTBL ;1798
- ld a,(CON.COL) ;179b
- cp b ;179e
- jr c,l1798h ;179f
- push bc ;17a1
- call INLINE ;17a2
- pop bc ;17a5
- call SKIPBL ;17a6
- cp '.' ;17a9
- ret z ;17ab
- cp '-' ;17ac
- jr nz,l17b6h ;17ae
- ld iy,(XB06C) ;17b0
- jr l177ch ;17b4
+ call OUTBL
+ ld a,(CON.COL)
+ cp b
+ jr c,l1798h
+ push bc
+ call INLINE
+ pop bc
+ call SKIPBL
+ cp '.'
+ ret z
+ cp '-'
+ jr nz,l17b6h
+ ld iy,(XB06C)
+ jr l177ch
l17b6h:
- and a ;17b6
- call nz,sub_17cdh ;17b7
- ld (XB06C),iy ;17ba
- ld b,0 ;17be
- add iy,bc ;17c0
- jr l177ch ;17c2
+ and a
+ call nz,sub_17cdh
+ ld (XB06C),iy
+ ld b,0
+ add iy,bc
+ jr l177ch
l17c4h:
- call l07eah ;17c4
- ld sp,(XB068) ;17c7
- jr l177ch ;17cb
+ call l07eah
+ ld sp,(XB068)
+ jr l177ch
sub_17cdh:
- call SKIPBL ;17cd
- ld hl,t_MNEMONICS ;17d0
- call sub_0a15h ;17d3
- jp nc,ERROR ;17d6
- call SKIPBL ;17d9
- push de ;17dc
- ld a,b ;17dd
- add a,b ;17de
- add a,b ;17df
- ld hl,b_0x17EE_start ;17e0
- call ADD_HL_A ;17e3
- ld e,(hl) ;17e6
- inc hl ;17e7
- ld d,(hl) ;17e8
- inc hl ;17e9
- ld b,(hl) ;17ea
- ex de,hl ;17eb
- pop de ;17ec
- jp (hl) ;17ed
+ call SKIPBL
+ ld hl,t_MNEMONICS
+ call sub_0a15h
+ jp nc,ERROR
+ call SKIPBL
+ push de
+ ld a,b
+ add a,b
+ add a,b
+ ld hl,b_0x17EE_start
+ call ADD_HL_A
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ inc hl
+ ld b,(hl)
+ ex de,hl
+ pop de
+ jp (hl)
b_0x17EE_start:
- defw l1b54h ;17ee
+ defw l1b54h
b_0x17F0_start:
- defb 088h ;17f0
+ defb 088h
b_0x17F1_start:
- defw l1b74h ;17f1
+ defw l1b74h
b_0x17F3_start:
- defb 080h ;17f3
+ defb 080h
b_0x17F4_start:
- defw l1babh ;17f4
+ defw l1babh
b_0x17F6_start:
- defb 0a0h ;17f6
+ defb 0a0h
b_0x17F7_start:
- defw l1c14h ;17f7
+ defw l1c14h
b_0x17F9_start:
- defb 040h ;17f9
+ defb 040h
b_0x17FA_start:
- defw l1c38h ;17fa
+ defw l1c38h
b_0x17FC_start:
- defb 0c4h ;17fc
+ defb 0c4h
b_0x17FD_start:
- defw l1b36h ;17fd
+ defw l1b36h
b_0x17FF_start:
- defb 03fh ;17ff
+ defb 03fh
b_0x1800_start:
- defw l1babh ;1800
+ defw l1babh
b_0x1802_start:
- defb 0b8h ;1802
+ defb 0b8h
b_0x1803_start:
- defw gen.opc.ED2 ;1803
+ defw gen.opc.ED2
b_0x1805_start:
- defb 0a9h ;1805
+ defb 0a9h
b_0x1806_start:
- defw gen.opc.ED2 ;1806
+ defw gen.opc.ED2
b_0x1808_start:
- defb 0b9h ;1808
+ defb 0b9h
b_0x1809_start:
- defw gen.opc.ED2 ;1809
+ defw gen.opc.ED2
b_0x180B_start:
- defb 0a1h ;180b
+ defb 0a1h
b_0x180C_start:
- defw gen.opc.ED2 ;180c
+ defw gen.opc.ED2
b_0x180E_start:
- defb 0b1h ;180e
+ defb 0b1h
b_0x180F_start:
- defw l1b36h ;180f
+ defw l1b36h
b_0x1811_start:
- defb 02fh ;1811
+ defb 02fh
b_0x1812_start:
- defw l1b36h ;1812
+ defw l1b36h
b_0x1814_start:
- defb 027h ;1814
+ defb 027h
b_0x1815_start:
- defw l1dabh ;1815
+ defw l1dabh
b_0x1817_start:
- defb 005h ;1817
+ defb 005h
b_0x1818_start:
- defw l1b36h ;1818
+ defw l1b36h
b_0x181A_start:
- defb 0f3h ;181a
+ defb 0f3h
b_0x181B_start:
- defw l1ca4h ;181b
+ defw l1ca4h
b_0x181D_start:
- defb 010h ;181d
+ defb 010h
b_0x181E_start:
- defw l1b36h ;181e
+ defw l1b36h
b_0x1820_start:
- defb 0fbh ;1820
+ defb 0fbh
b_0x1821_start:
- defw l1d54h ;1821
+ defw l1d54h
b_0x1823_start:
- defb 0e3h ;1823
+ defb 0e3h
b_0x1824_start:
- defw l1b36h ;1824
+ defw l1b36h
b_0x1826_start:
- defb 0d9h ;1826
+ defb 0d9h
b_0x1827_start:
- defw l1b36h ;1827
+ defw l1b36h
b_0x1829_start:
- defb 076h ;1829
+ defb 076h
b_0x182A_start:
- defw l1cbfh ;182a
+ defw l1cbfh
b_0x182C_start:
- defb 046h ;182c
+ defb 046h
b_0x182D_start:
- defw l1cf8h ;182d
+ defw l1cf8h
b_0x182F_start:
- defb 040h ;182f
+ defb 040h
b_0x1830_start:
- defw l1dabh ;1830
+ defw l1dabh
b_0x1832_start:
- defb 004h ;1832
+ defb 004h
b_0x1833_start:
- defw gen.opc.ED2 ;1833
+ defw gen.opc.ED2
b_0x1835_start:
- defb 0aah ;1835
+ defb 0aah
b_0x1836_start:
- defw gen.opc.ED2 ;1836
+ defw gen.opc.ED2
b_0x1838_start:
- defb 0bah ;1838
+ defb 0bah
b_0x1839_start:
- defw gen.opc.ED2 ;1839
+ defw gen.opc.ED2
b_0x183B_start:
- defb 0a2h ;183b
+ defb 0a2h
b_0x183C_start:
- defw gen.opc.ED2 ;183c
+ defw gen.opc.ED2
b_0x183E_start:
- defb 0b2h ;183e
+ defb 0b2h
b_0x183F_start:
- defw l1c5eh ;183f
+ defw l1c5eh
b_0x1841_start:
- defb 0c2h ;1841
+ defb 0c2h
b_0x1842_start:
- defw l1cabh ;1842
+ defw l1cabh
b_0x1844_start:
- defb 020h ;1844
+ defb 020h
b_0x1845_start:
- defw l1934h ;1845
+ defw l1934h
b_0x1847_start:
- defb 040h ;1847
+ defb 040h
b_0x1848_start:
- defw gen.opc.ED2 ;1848
+ defw gen.opc.ED2
b_0x184A_start:
- defb 0a8h ;184a
+ defb 0a8h
b_0x184B_start:
- defw gen.opc.ED2 ;184b
+ defw gen.opc.ED2
b_0x184D_start:
- defb 0b8h ;184d
+ defb 0b8h
b_0x184E_start:
- defw gen.opc.ED2 ;184e
+ defw gen.opc.ED2
b_0x1850_start:
- defb 0a0h ;1850
+ defb 0a0h
b_0x1851_start:
- defw gen.opc.ED2 ;1851
+ defw gen.opc.ED2
b_0x1853_start:
- defb 0b0h ;1853
+ defb 0b0h
b_0x1854_start:
- defw gen.opc.ED2 ;1854
+ defw gen.opc.ED2
b_0x1856_start:
- defb 044h ;1856
+ defb 044h
b_0x1857_start:
- defw l1b36h ;1857
+ defw l1b36h
b_0x1859_start:
- defb 000h ;1859
+ defb 000h
b_0x185A_start:
- defw l1babh ;185a
+ defw l1babh
b_0x185C_start:
- defb 0b0h ;185c
+ defb 0b0h
b_0x185D_start:
- defw gen.opc.ED2 ;185d
+ defw gen.opc.ED2
b_0x185F_start:
- defb 0bbh ;185f
+ defb 0bbh
b_0x1860_start:
- defw gen.opc.ED2 ;1860
+ defw gen.opc.ED2
b_0x1862_start:
- defb 0b3h ;1862
+ defb 0b3h
b_0x1863_start:
- defw l1d2ch ;1863
+ defw l1d2ch
b_0x1865_start:
- defb 041h ;1865
+ defb 041h
b_0x1866_start:
- defw gen.opc.ED2 ;1866
+ defw gen.opc.ED2
b_0x1868_start:
- defb 0abh ;1868
+ defb 0abh
b_0x1869_start:
- defw gen.opc.ED2 ;1869
+ defw gen.opc.ED2
b_0x186B_start:
- defb 0a3h ;186b
+ defb 0a3h
b_0x186C_start:
- defw l1ce4h ;186c
+ defw l1ce4h
b_0x186E_start:
- defb 0c1h ;186e
+ defb 0c1h
b_0x186F_start:
- defw l1ce4h ;186f
+ defw l1ce4h
b_0x1871_start:
- defb 0c5h ;1871
+ defb 0c5h
b_0x1872_start:
- defw l1c14h ;1872
+ defw l1c14h
b_0x1874_start:
- defb 080h ;1874
+ defb 080h
b_0x1875_start:
- defw l1c50h ;1875
+ defw l1c50h
b_0x1877_start:
- defb 0c0h ;1877
+ defb 0c0h
b_0x1878_start:
- defw gen.opc.ED2 ;1878
+ defw gen.opc.ED2
b_0x187A_start:
- defb 04dh ;187a
+ defb 04dh
b_0x187B_start:
- defw gen.opc.ED2 ;187b
+ defw gen.opc.ED2
b_0x187D_start:
- defb 045h ;187d
+ defb 045h
b_0x187E_start:
- defw l1bd8h ;187e
+ defw l1bd8h
b_0x1880_start:
- defb 010h ;1880
+ defb 010h
b_0x1881_start:
- defw l1b36h ;1881
+ defw l1b36h
b_0x1883_start:
- defb 017h ;1883
+ defb 017h
b_0x1884_start:
- defw l1bd8h ;1884
+ defw l1bd8h
b_0x1886_start:
- defb 000h ;1886
+ defb 000h
b_0x1887_start:
- defw l1b36h ;1887
+ defw l1b36h
b_0x1889_start:
- defb 007h ;1889
+ defb 007h
b_0x188A_start:
- defw gen.opc.ED2 ;188a
+ defw gen.opc.ED2
b_0x188C_start:
- defb 06fh ;188c
+ defb 06fh
b_0x188D_start:
- defw l1bd8h ;188d
+ defw l1bd8h
b_0x188F_start:
- defb 018h ;188f
+ defb 018h
b_0x1890_start:
- defw l1b36h ;1890
+ defw l1b36h
b_0x1892_start:
- defb 01fh ;1892
+ defb 01fh
b_0x1893_start:
- defw l1bd8h ;1893
+ defw l1bd8h
b_0x1895_start:
- defb 008h ;1895
+ defb 008h
b_0x1896_start:
- defw l1b36h ;1896
+ defw l1b36h
b_0x1898_start:
- defb 00fh ;1898
+ defb 00fh
b_0x1899_start:
- defw gen.opc.ED2 ;1899
+ defw gen.opc.ED2
b_0x189B_start:
- defb 067h ;189b
+ defb 067h
b_0x189C_start:
- defw l1cd5h ;189c
+ defw l1cd5h
b_0x189E_start:
- defb 0c7h ;189e
+ defb 0c7h
b_0x189F_start:
- defw l1b54h ;189f
+ defw l1b54h
b_0x18A1_start:
- defb 098h ;18a1
+ defb 098h
b_0x18A2_start:
- defw l1b36h ;18a2
+ defw l1b36h
b_0x18A4_start:
- defb 037h ;18a4
+ defb 037h
b_0x18A5_start:
- defw l1c14h ;18a5
+ defw l1c14h
b_0x18A7_start:
- defb 0c0h ;18a7
+ defb 0c0h
b_0x18A8_start:
- defw l1bd8h ;18a8
+ defw l1bd8h
b_0x18AA_start:
- defb 020h ;18aa
+ defb 020h
b_0x18AB_start:
- defw l1bd8h ;18ab
+ defw l1bd8h
b_0x18AD_start:
- defb 028h ;18ad
+ defb 028h
b_0x18AE_start:
- defw l1bd8h ;18ae
+ defw l1bd8h
b_0x18B0_start:
- defb 038h ;18b0
+ defb 038h
b_0x18B1_start:
- defw l1babh ;18b1
+ defw l1babh
b_0x18B3_start:
- defb 090h ;18b3
+ defb 090h
b_0x18B4_start:
- defw l1babh ;18b4
+ defw l1babh
b_0x18B6_start:
- defb 0a8h ;18b6
+ defb 0a8h
b_0x18B7_start:
- defw A.IN0 ;18b7
+ defw A.IN0
b_0x18B9_start:
- defb 000h ;18b9
+ defb 000h
b_0x18BA_start:
- defw A.MLT ;18ba
+ defw A.MLT
b_0x18BC_start:
- defb 04ch ;18bc
- ld b,e ;18bd
- dec de ;18be
+ defb 04ch
+ ld b,e
+ dec de
b_0x18BF_start:
- defb 08bh ;18bf
+ defb 08bh
b_0x18C0_start:
- defw gen.opc.ED2 ;18c0
+ defw gen.opc.ED2
b_0x18C2_start:
- defb 09bh ;18c2
+ defb 09bh
b_0x18C3_start:
- defw gen.opc.ED2 ;18c3
+ defw gen.opc.ED2
b_0x18C5_start:
- defb 083h ;18c5
+ defb 083h
b_0x18C6_start:
- defw gen.opc.ED2 ;18c6
+ defw gen.opc.ED2
b_0x18C8_start:
- defb 093h ;18c8
+ defb 093h
b_0x18C9_start:
- defw l18fdh ;18c9
+ defw l18fdh
b_0x18CB_start:
- defb 001h ;18cb
+ defb 001h
b_0x18CC_start:
- defw gen.opc.ED2 ;18cc
+ defw gen.opc.ED2
b_0x18CE_start:
- defb 076h ;18ce
+ defb 076h
b_0x18CF_start:
- defw l191dh ;18cf
+ defw l191dh
b_0x18D1_start:
- defb 004h ;18d1
+ defb 004h
b_0x18D2_start:
- defw l192ch ;18d2
+ defw l192ch
b_0x18D4_start:
- defb 074h ;18d4
+ defb 074h
A.IN0:
- call sub_1e41h ;18d5
- jr nc,l1931h ;18d8
- cp 006h ;18da
- jr z,l1931h ;18dc
- rlca ;18de
- rlca ;18df
- rlca ;18e0
- add a,b ;18e1
- ld b,a ;18e2
- call sub_1ed1h ;18e3
- call sub_1e06h ;18e6
+ call sub_1e41h
+ jr nc,l1931h
+ cp 006h
+ jr z,l1931h
+ rlca
+ rlca
+ rlca
+ add a,b
+ ld b,a
+ call sub_1ed1h
+ call sub_1e06h
l18e9h:
- call assert_eol ;18e9
- comst ;18ec
- ld (iy+000h),0edh ;18f0
- ld (iy+001h),b ;18f4
- ld (iy+002h),l ;18f7
+ call assert_eol
+ comst
+ ld (iy+000h),0edh
+ ld (iy+001h),b
+ ld (iy+002h),l
comend
- ld c,003h ;18fa
- ret ;18fc
+ ld c,003h
+ ret
l18fdh:
- call sub_1e06h ;18fd
- call sub_1ed1h ;1900
- call sub_1e41h ;1903
- jr nc,l1931h ;1906
- cp 006h ;1908
- jr z,l1931h ;190a
- rlca ;190c
- rlca ;190d
- rlca ;190e
- add a,b ;190f
- ld b,a ;1910
- jr l18e9h ;1911
+ call sub_1e06h
+ call sub_1ed1h
+ call sub_1e41h
+ jr nc,l1931h
+ cp 006h
+ jr z,l1931h
+ rlca
+ rlca
+ rlca
+ add a,b
+ ld b,a
+ jr l18e9h
A.MLT:
- call sub_1e2eh ;1913
- jr nc,l1931h ;1916
- add a,b ;1918
- ld b,a ;1919
- jp gen.opc.ED2 ;191a
+ call sub_1e2eh
+ jr nc,l1931h
+ add a,b
+ ld b,a
+ jp gen.opc.ED2
l191dh:
- call sub_1e41h ;191d
- jr nc,l192ah ;1920
- rlca ;1922
- rlca ;1923
- rlca ;1924
- add a,b ;1925
- ld b,a ;1926
- jp gen.opc.ED2 ;1927
+ call sub_1e41h
+ jr nc,l192ah
+ rlca
+ rlca
+ rlca
+ add a,b
+ ld b,a
+ jp gen.opc.ED2
l192ah:
- ld b,064h ;192a
+ ld b,064h
l192ch:
- call sub_1e12h ;192c
- jr l18e9h ;192f
+ call sub_1e12h
+ jr l18e9h
l1931h:
- jp ERROR ;1931
+ jp ERROR
l1934h:
- call sub_1e41h ;1934
- jp c,l19bfh ;1937
- call sub_1e68h ;193a
- jp c,l1a64h ;193d
- call sub_1e2eh ;1940
- jp c,l1a93h ;1943
- call sub_1e50h ;1946
- jp c,l1af0h ;1949
- ld a,(de) ;194c
- cp 049h ;194d
- jp z,l1b0ch ;194f
- cp 052h ;1952
- jp z,l1b14h ;1954
- cp 028h ;1957
- jp nz,ERROR ;1959
- inc de ;195c
- call sub_1e2eh ;195d
- jp c,l1b23h ;1960
- call tst_EXPR ;1963
- call sub_1ed8h ;1966
- call sub_1ed1h ;1969
- call sub_1e2eh ;196c
- jr c,l19adh ;196f
- call sub_1e50h ;1971
- jr nc,l1991h ;1974
- ld b,022h ;1976
+ call sub_1e41h
+ jp c,l19bfh
+ call sub_1e68h
+ jp c,l1a64h
+ call sub_1e2eh
+ jp c,l1a93h
+ call sub_1e50h
+ jp c,l1af0h
+ ld a,(de)
+ cp 049h
+ jp z,l1b0ch
+ cp 052h
+ jp z,l1b14h
+ cp 028h
+ jp nz,ERROR
+ inc de
+ call sub_1e2eh
+ jp c,l1b23h
+ call tst_EXPR
+ call sub_1ed8h
+ call sub_1ed1h
+ call sub_1e2eh
+ jr c,l19adh
+ call sub_1e50h
+ jr nc,l1991h
+ ld b,022h
l1978h:
- call assert_eol ;1978
- ld a,(pfx.IXY) ;197b
+ call assert_eol
+ ld a,(pfx.IXY)
l197eh:
- comst ;197e
- ld (iy+000h),a ;1982
- ld (iy+001h),b ;1985
- ld (iy+002h),l ;1988
- ld (iy+003h),h ;198b
+ comst
+ ld (iy+000h),a
+ ld (iy+001h),b
+ ld (iy+002h),l
+ ld (iy+003h),h
comend
- ld c,004h ;198e
- ret ;1990
+ ld c,004h
+ ret
l1991h:
- ld a,(de) ;1991
- cp 041h ;1992
- jp nz,ERROR ;1994
- inc de ;1997
- ld b,032h ;1998
+ ld a,(de)
+ cp 041h
+ jp nz,ERROR
+ inc de
+ ld b,032h
l199ah:
- call assert_eol ;199a
- comst ;199d
- ld (iy+000h),b ;19a1
- ld (iy+001h),l ;19a4
- ld (iy+002h),h ;19a7
+ call assert_eol
+ comst
+ ld (iy+000h),b
+ ld (iy+001h),l
+ ld (iy+002h),h
comend
- ld c,003h ;19aa
- ret ;19ac
+ ld c,003h
+ ret
l19adh:
- cp 020h ;19ad
- jr z,l19bbh ;19af
- add a,043h ;19b1
- ld b,a ;19b3
+ cp 020h
+ jr z,l19bbh
+ add a,043h
+ ld b,a
l19b4h:
- call assert_eol ;19b4
- ld a,0edh ;19b7
- jr l197eh ;19b9
+ call assert_eol
+ ld a,0edh
+ jr l197eh
l19bbh:
- ld b,022h ;19bb
- jr l199ah ;19bd
+ ld b,022h
+ jr l199ah
l19bfh:
- ld b,a ;19bf
- call sub_1ed1h ;19c0
- call sub_1e41h ;19c3
- jr nc,l19dbh ;19c6
- push af ;19c8
- ld a,b ;19c9
- rlca ;19ca
- rlca ;19cb
- rlca ;19cc
- ld b,a ;19cd
- pop af ;19ce
- add a,b ;19cf
- add a,040h ;19d0
- cp 076h ;19d2
- jp z,ERROR ;19d4
+ ld b,a
+ call sub_1ed1h
+ call sub_1e41h
+ jr nc,l19dbh
+ push af
+ ld a,b
+ rlca
+ rlca
+ rlca
+ ld b,a
+ pop af
+ add a,b
+ add a,040h
+ cp 076h
+ jp z,ERROR
l19d7h:
- ld b,a ;19d7
- jp l1b36h ;19d8
+ ld b,a
+ jp l1b36h
l19dbh:
- call sub_1e68h ;19db
- jr nc,l1a02h ;19de
- ld a,b ;19e0
- rlca ;19e1
- rlca ;19e2
- rlca ;19e3
- add a,046h ;19e4
- cp 076h ;19e6
- jp z,ERROR ;19e8
+ call sub_1e68h
+ jr nc,l1a02h
+ ld a,b
+ rlca
+ rlca
+ rlca
+ add a,046h
+ cp 076h
+ jp z,ERROR
l19ebh:
- ld b,a ;19eb
- call assert_eol ;19ec
- ld a,(pfx.IXY) ;19ef
- comst ;19f2
- ld (iy+000h),a ;19f6
- ld (iy+001h),b ;19f9
- ld (iy+002h),c ;19fc
+ ld b,a
+ call assert_eol
+ ld a,(pfx.IXY)
+ comst
+ ld (iy+000h),a
+ ld (iy+001h),b
+ ld (iy+002h),c
comend
- ld c,003h ;19ff
- ret ;1a01
+ ld c,003h
+ ret
l1a02h:
- ld a,(de) ;1a02
- cp 'I' ;1a03
- jr z,l1a15h ;1a05
- cp 'R' ;1a07
- jr nz,l1a21h ;1a09
- ld a,b ;1a0b
- cp 007h ;1a0c
- jp nz,ERROR ;1a0e
- ld b,05fh ;1a11
- jr l1a1dh ;1a13
+ ld a,(de)
+ cp 'I'
+ jr z,l1a15h
+ cp 'R'
+ jr nz,l1a21h
+ ld a,b
+ cp 007h
+ jp nz,ERROR
+ ld b,05fh
+ jr l1a1dh
l1a15h:
- ld a,b ;1a15
- cp 007h ;1a16
- jp nz,ERROR ;1a18
- ld b,057h ;1a1b
+ ld a,b
+ cp 007h
+ jp nz,ERROR
+ ld b,057h
l1a1dh:
- inc de ;1a1d
- jp gen.opc.ED2 ;1a1e
+ inc de
+ jp gen.opc.ED2
l1a21h:
- cp '(' ;1a21
- jr z,l1a3fh ;1a23
- call sub_1e12h ;1a25
+ cp '('
+ jr z,l1a3fh
+ call sub_1e12h
ld a,b ;1a28 ld r,nn
- rlca ;1a29
- rlca ;1a2a
- rlca ;1a2b
- add a,006h ;1a2c
+ rlca
+ rlca
+ rlca
+ add a,006h
l1a2eh:
- ld b,a ;1a2e
+ ld b,a
l1a2fh:
- call assert_eol ;1a2f
- comst ;1a32
- ld (iy+000h),b ;1a36
- ld (iy+001h),l ;1a39
+ call assert_eol
+ comst
+ ld (iy+000h),b
+ ld (iy+001h),l
comend
- ld c,002h ;1a3c
- ret ;1a3e
+ ld c,002h
+ ret
l1a3fh:
- inc de ;1a3f
- ld a,b ;1a40
- cp 007h ;1a41
- jp nz,ERROR ;1a43
- call sub_1e2eh ;1a46
- jr nc,l1a59h ;1a49
- cp 030h ;1a4b
- jp nc,ERROR ;1a4d
- add a,00ah ;1a50
- ld b,a ;1a52
- call sub_1ed8h ;1a53
- jp l1b36h ;1a56
+ inc de
+ ld a,b
+ cp 007h
+ jp nz,ERROR
+ call sub_1e2eh
+ jr nc,l1a59h
+ cp 030h
+ jp nc,ERROR
+ add a,00ah
+ ld b,a
+ call sub_1ed8h
+ jp l1b36h
l1a59h:
- call tst_EXPR ;1a59
- call sub_1ed8h ;1a5c
- ld b,03ah ;1a5f
- jp l199ah ;1a61
+ call tst_EXPR
+ call sub_1ed8h
+ ld b,03ah
+ jp l199ah
l1a64h:
- call sub_1ed1h ;1a64
- call sub_1e41h ;1a67
- jr nc,l1a76h ;1a6a
- cp 006h ;1a6c
- jp z,ERROR ;1a6e
- add a,070h ;1a71
- jp l19ebh ;1a73
+ call sub_1ed1h
+ call sub_1e41h
+ jr nc,l1a76h
+ cp 006h
+ jp z,ERROR
+ add a,070h
+ jp l19ebh
l1a76h:
- call sub_1e12h ;1a76
- call assert_eol ;1a79
- ld a,(pfx.IXY) ;1a7c
- comst ;1a7f
+ call sub_1e12h
+ call assert_eol
+ ld a,(pfx.IXY)
+ comst
ld (iy+000h),a ;1a83 dd/fd
- ld (iy+001h),036h ;1a86
+ ld (iy+001h),036h
ld (iy+002h),c ;1a8a displacement
ld (iy+003h),l ;1a8d nn
comend
- ld c,4 ;1a90
- ret ;1a92
+ ld c,4
+ ret
l1a93h:
- ld b,a ;1a93
- call sub_1ed1h ;1a94
- ld hl,t_HL.AF ;1a97
- call sub_0a23h ;1a9a
- jr c,l1abeh ;1a9d
- call sub_1e50h ;1a9f
- jr nc,l1ac7h ;1aa2
- ld a,b ;1aa4
- cp 030h ;1aa5
- jr nz,l1b20h ;1aa7
- ld b,0f9h ;1aa9
+ ld b,a
+ call sub_1ed1h
+ ld hl,t_HL.AF
+ call sub_0a23h
+ jr c,l1abeh
+ call sub_1e50h
+ jr nc,l1ac7h
+ ld a,b
+ cp 030h
+ jr nz,l1b20h
+ ld b,0f9h
l1aabh:
- call assert_eol ;1aab
- ld a,(pfx.IXY) ;1aae
- comst ;1ab1
- ld (iy+000h),a ;1ab5
- ld (iy+001h),b ;1ab8
+ call assert_eol
+ ld a,(pfx.IXY)
+ comst
+ ld (iy+000h),a
+ ld (iy+001h),b
comend
- ld c,002h ;1abb
- ret ;1abd
+ ld c,002h
+ ret
l1abeh:
- ld a,b ;1abe
- cp 030h ;1abf
- jr nz,l1b20h ;1ac1
- ld b,0f9h ;1ac3
- jr l1b36h ;1ac5
+ ld a,b
+ cp 030h
+ jr nz,l1b20h
+ ld b,0f9h
+ jr l1b36h
l1ac7h:
- ld a,(de) ;1ac7
- cp 028h ;1ac8
- jr nz,l1ae3h ;1aca
- inc de ;1acc
- call tst_EXPR ;1acd
- call sub_1ed8h ;1ad0
- ld a,b ;1ad3
- cp 020h ;1ad4
- jr z,l1adeh ;1ad6
- add a,04bh ;1ad8
- ld b,a ;1ada
- jp l19b4h ;1adb
+ ld a,(de)
+ cp 028h
+ jr nz,l1ae3h
+ inc de
+ call tst_EXPR
+ call sub_1ed8h
+ ld a,b
+ cp 020h
+ jr z,l1adeh
+ add a,04bh
+ ld b,a
+ jp l19b4h
l1adeh:
- ld b,02ah ;1ade
- jp l199ah ;1ae0
+ ld b,02ah
+ jp l199ah
l1ae3h:
- call tst_EXPR ;1ae3
- call assert_eol ;1ae6
- ld a,001h ;1ae9
- add a,b ;1aeb
- ld b,a ;1aec
- jp l199ah ;1aed
+ call tst_EXPR
+ call assert_eol
+ ld a,001h
+ add a,b
+ ld b,a
+ jp l199ah
l1af0h:
- call sub_1ed1h ;1af0
- ld a,(de) ;1af3
- cp 028h ;1af4
- jr nz,l1b04h ;1af6
- inc de ;1af8
- call tst_EXPR ;1af9
- call sub_1ed8h ;1afc
- ld b,02ah ;1aff
- jp l1978h ;1b01
+ call sub_1ed1h
+ ld a,(de)
+ cp 028h
+ jr nz,l1b04h
+ inc de
+ call tst_EXPR
+ call sub_1ed8h
+ ld b,02ah
+ jp l1978h
l1b04h:
- call tst_EXPR ;1b04
- ld b,021h ;1b07
- jp l1978h ;1b09
+ call tst_EXPR
+ ld b,021h
+ jp l1978h
l1b0ch:
- inc de ;1b0c
- call sub_1ed1h ;1b0d
- ld b,047h ;1b10
- jr l1b1ah ;1b12
+ inc de
+ call sub_1ed1h
+ ld b,047h
+ jr l1b1ah
l1b14h:
- inc de ;1b14
- call sub_1ed1h ;1b15
- ld b,04fh ;1b18
+ inc de
+ call sub_1ed1h
+ ld b,04fh
l1b1ah:
- ld a,(de) ;1b1a
- inc de ;1b1b
- cp 041h ;1b1c
- jr z,gen.opc.ED2 ;1b1e
+ ld a,(de)
+ inc de
+ cp 041h
+ jr z,gen.opc.ED2
l1b20h:
- jp ERROR ;1b20
+ jp ERROR
l1b23h:
- cp 020h ;1b23
- jr nc,l1b20h ;1b25
- add a,002h ;1b27
- ld b,a ;1b29
- call sub_1ed8h ;1b2a
- call sub_1ed1h ;1b2d
- ld a,(de) ;1b30
- cp 041h ;1b31
- jr nz,l1b20h ;1b33
- inc de ;1b35
+ cp 020h
+ jr nc,l1b20h
+ add a,002h
+ ld b,a
+ call sub_1ed8h
+ call sub_1ed1h
+ ld a,(de)
+ cp 041h
+ jr nz,l1b20h
+ inc de
l1b36h:
- call assert_eol ;1b36
- comst ;1b39
- ld (iy+000h),b ;1b3d
+ call assert_eol
+ comst
+ ld (iy+000h),b
comend
- ld c,001h ;1b40
- ret ;1b42
+ ld c,001h
+ ret
gen.opc.ED2:
- call assert_eol ;1b43
- comst ;1b46
- ld (iy+000h),0edh ;1b4a
- ld (iy+001h),b ;1b4e
+ call assert_eol
+ comst
+ ld (iy+000h),0edh
+ ld (iy+001h),b
comend
- ld c,002h ;1b51
- ret ;1b53
+ ld c,002h
+ ret
l1b54h:
- ld hl,t_HL.AF ;1b54
- call sub_0a23h ;1b57
- jr nc,l1babh ;1b5a
- call sub_1ed1h ;1b5c
- call sub_1e2eh ;1b5f
- jp nc,ERROR ;1b62
- push af ;1b65
- ld a,b ;1b66
- cp 088h ;1b67
- ld b,04ah ;1b69
- jr z,l1b6fh ;1b6b
- ld b,042h ;1b6d
+ ld hl,t_HL.AF
+ call sub_0a23h
+ jr nc,l1babh
+ call sub_1ed1h
+ call sub_1e2eh
+ jp nc,ERROR
+ push af
+ ld a,b
+ cp 088h
+ ld b,04ah
+ jr z,l1b6fh
+ ld b,042h
l1b6fh:
- pop af ;1b6f
- add a,b ;1b70
+ pop af
+ add a,b
l1b71h:
- ld b,a ;1b71
- jr gen.opc.ED2 ;1b72
+ ld b,a
+ jr gen.opc.ED2
l1b74h:
- ld hl,t_HL.AF ;1b74
- call sub_0a23h ;1b77
- jr c,l1b9dh ;1b7a
- call sub_1e50h ;1b7c
- jr nc,l1babh ;1b7f
- call sub_1ed1h ;1b81
- ld hl,t_BC.DE.IX.SP ;1b84
- ld a,(pfx.IXY) ;1b87
- cp 0fdh ;1b8a
- jr nz,l1b91h ;1b8c
- ld hl,t_BC.DE.IY.SP ;1b8e
+ ld hl,t_HL.AF
+ call sub_0a23h
+ jr c,l1b9dh
+ call sub_1e50h
+ jr nc,l1babh
+ call sub_1ed1h
+ ld hl,t_BC.DE.IX.SP
+ ld a,(pfx.IXY)
+ cp 0fdh
+ jr nz,l1b91h
+ ld hl,t_BC.DE.IY.SP
l1b91h:
- call sub_1e2bh ;1b91
- jp nc,ERROR ;1b94
- add a,009h ;1b97
+ call sub_1e2bh
+ jp nc,ERROR
+ add a,009h
l1b99h:
- ld b,a ;1b99
- jp l1aabh ;1b9a
+ ld b,a
+ jp l1aabh
l1b9dh:
- call sub_1ed1h ;1b9d
- call sub_1e2eh ;1ba0
- jp nc,ERROR ;1ba3
- add a,009h ;1ba6
- jp l19d7h ;1ba8
+ call sub_1ed1h
+ call sub_1e2eh
+ jp nc,ERROR
+ add a,009h
+ jp l19d7h
l1babh:
- ld a,(de) ;1bab
- cp 041h ;1bac
- jr nz,l1bbbh ;1bae
- push de ;1bb0
- inc de ;1bb1
- call skip_to_nextarg ;1bb2
- jr z,l1bbah ;1bb5
- pop de ;1bb7
- jr l1bbbh ;1bb8
+ ld a,(de)
+ cp 041h
+ jr nz,l1bbbh
+ push de
+ inc de
+ call skip_to_nextarg
+ jr z,l1bbah
+ pop de
+ jr l1bbbh
l1bbah:
- pop af ;1bba
+ pop af
l1bbbh:
- call sub_1e41h ;1bbb
- jr c,l1bceh ;1bbe
- call sub_1e68h ;1bc0
- jr c,l1bd2h ;1bc3
- call sub_1e12h ;1bc5
- ld a,b ;1bc8
- add a,046h ;1bc9
- jp l1a2eh ;1bcb
+ call sub_1e41h
+ jr c,l1bceh
+ call sub_1e68h
+ jr c,l1bd2h
+ call sub_1e12h
+ ld a,b
+ add a,046h
+ jp l1a2eh
l1bceh:
- add a,b ;1bce
- jp l19d7h ;1bcf
+ add a,b
+ jp l19d7h
l1bd2h:
- ld a,b ;1bd2
- add a,006h ;1bd3
- jp l19ebh ;1bd5
+ ld a,b
+ add a,006h
+ jp l19ebh
l1bd8h:
- call sub_1e41h ;1bd8
- jr c,l1c01h ;1bdb
- call sub_1e68h ;1bdd
- jp nc,ERROR ;1be0
- ld a,b ;1be3
- add a,006h ;1be4
- ld b,a ;1be6
+ call sub_1e41h
+ jr c,l1c01h
+ call sub_1e68h
+ jp nc,ERROR
+ ld a,b
+ add a,006h
+ ld b,a
l1be7h:
- call assert_eol ;1be7
- ld a,(pfx.IXY) ;1bea
- comst ;1bed
- ld (iy+000h),a ;1bf1
- ld (iy+001h),0cbh ;1bf4
- ld (iy+002h),c ;1bf8
- ld (iy+003h),b ;1bfb
+ call assert_eol
+ ld a,(pfx.IXY)
+ comst
+ ld (iy+000h),a
+ ld (iy+001h),0cbh
+ ld (iy+002h),c
+ ld (iy+003h),b
comend
- ld c,004h ;1bfe
- ret ;1c00
+ ld c,004h
+ ret
l1c01h:
- add a,b ;1c01
+ add a,b
l1c02h:
- ld b,a ;1c02
- call assert_eol ;1c03
- comst ;1c06
- ld (iy+000h),0cbh ;1c0a
- ld (iy+001h),b ;1c0e
+ ld b,a
+ call assert_eol
+ comst
+ ld (iy+000h),0cbh
+ ld (iy+001h),b
comend
- ld c,002h ;1c11
- ret ;1c13
+ ld c,002h
+ ret
l1c14h:
- call sub_1de6h ;1c14
- call sub_1ed1h ;1c17
- call sub_1e41h ;1c1a
- jr c,l1c2fh ;1c1d
- call sub_1e68h ;1c1f
- jp nc,ERROR ;1c22
- ld a,l ;1c25
- rlca ;1c26
- rlca ;1c27
- rlca ;1c28
- add a,006h ;1c29
- add a,b ;1c2b
- ld b,a ;1c2c
- jr l1be7h ;1c2d
+ call sub_1de6h
+ call sub_1ed1h
+ call sub_1e41h
+ jr c,l1c2fh
+ call sub_1e68h
+ jp nc,ERROR
+ ld a,l
+ rlca
+ rlca
+ rlca
+ add a,006h
+ add a,b
+ ld b,a
+ jr l1be7h
l1c2fh:
- add a,b ;1c2f
- ld b,a ;1c30
- ld a,l ;1c31
- rlca ;1c32
- rlca ;1c33
- rlca ;1c34
- add a,b ;1c35
- jr l1c02h ;1c36
+ add a,b
+ ld b,a
+ ld a,l
+ rlca
+ rlca
+ rlca
+ add a,b
+ jr l1c02h
l1c38h:
- push de ;1c38
- call sub_1eb8h ;1c39
- jr nc,l1c47h ;1c3c
- add a,b ;1c3e
- ld b,a ;1c3f
- call skip_to_nextarg ;1c40
- jr z,l1c49h ;1c43
- pop de ;1c45
- push de ;1c46
+ push de
+ call sub_1eb8h
+ jr nc,l1c47h
+ add a,b
+ ld b,a
+ call skip_to_nextarg
+ jr z,l1c49h
+ pop de
+ push de
l1c47h:
- ld b,0cdh ;1c47
+ ld b,0cdh
l1c49h:
- pop af ;1c49
- call tst_EXPR ;1c4a
- jp l199ah ;1c4d
+ pop af
+ call tst_EXPR
+ jp l199ah
l1c50h:
- call sub_1eb8h ;1c50
- jr nc,l1c59h ;1c53
- add a,b ;1c55
- ld b,a ;1c56
- jr l1c5bh ;1c57
+ call sub_1eb8h
+ jr nc,l1c59h
+ add a,b
+ ld b,a
+ jr l1c5bh
l1c59h:
- ld b,0c9h ;1c59
+ ld b,0c9h
l1c5bh:
- jp l1b36h ;1c5b
+ jp l1b36h
l1c5eh:
- push de ;1c5e
- call sub_1eb8h ;1c5f
- jr c,l1c71h ;1c62
+ push de
+ call sub_1eb8h
+ jr c,l1c71h
l1c64h:
- pop de ;1c64
- ld hl,b_0x1C97_start ;1c65
- call sub_0a15h ;1c68
- jr c,l1c7fh ;1c6b
- ld b,0c3h ;1c6d
- jr l1c79h ;1c6f
+ pop de
+ ld hl,b_0x1C97_start
+ call sub_0a15h
+ jr c,l1c7fh
+ ld b,0c3h
+ jr l1c79h
l1c71h:
- add a,b ;1c71
- ld b,a ;1c72
- call skip_to_nextarg ;1c73
- jr nz,l1c64h ;1c76
- pop af ;1c78
+ add a,b
+ ld b,a
+ call skip_to_nextarg
+ jr nz,l1c64h
+ pop af
l1c79h:
- call tst_EXPR ;1c79
- jp l199ah ;1c7c
+ call tst_EXPR
+ jp l199ah
l1c7fh:
- call assert_eol ;1c7f
- ld a,b ;1c82
- and a ;1c83
- jr nz,l1c8bh ;1c84
- ld b,0e9h ;1c86
- jp l1b36h ;1c88
+ call assert_eol
+ ld a,b
+ and a
+ jr nz,l1c8bh
+ ld b,0e9h
+ jp l1b36h
l1c8bh:
- ld b,0ddh ;1c8b
- dec a ;1c8d
- jr z,l1c92h ;1c8e
- ld b,0fdh ;1c90
+ ld b,0ddh
+ dec a
+ jr z,l1c92h
+ ld b,0fdh
l1c92h:
- ld l,0e9h ;1c92
- jp l1a2fh ;1c94
+ ld l,0e9h
+ jp l1a2fh
b_0x1C97_start:
DC '(HL)'
@@ -3908,128 +3932,128 @@ b_0x1C97_start:
DB 0
l1ca4h:
- call skip_to_nextarg ;1ca4
- ld b,010h ;1ca7
- jr l1cb9h ;1ca9
+ call skip_to_nextarg
+ ld b,010h
+ jr l1cb9h
l1cabh:
- call sub_1ebfh ;1cab
- jr c,l1cb4h ;1cae
- ld b,018h ;1cb0
- jr l1cb9h ;1cb2
+ call sub_1ebfh
+ jr c,l1cb4h
+ ld b,018h
+ jr l1cb9h
l1cb4h:
- add a,b ;1cb4
- ld b,a ;1cb5
- call sub_1ed1h ;1cb6
+ add a,b
+ ld b,a
+ call sub_1ed1h
l1cb9h:
- call sub_1defh ;1cb9
- jp l1a2fh ;1cbc
+ call sub_1defh
+ jp l1a2fh
l1cbfh:
- call sub_1e12h ;1cbf
- ld a,l ;1cc2
- cp 003h ;1cc3
- jr nc,l1d23h ;1cc5
- and a ;1cc7
- jr z,l1cd2h ;1cc8
- ld b,056h ;1cca
- cp 001h ;1ccc
- jr z,l1cd2h ;1cce
- ld b,05eh ;1cd0
+ call sub_1e12h
+ ld a,l
+ cp 003h
+ jr nc,l1d23h
+ and a
+ jr z,l1cd2h
+ ld b,056h
+ cp 001h
+ jr z,l1cd2h
+ ld b,05eh
l1cd2h:
- jp gen.opc.ED2 ;1cd2
+ jp gen.opc.ED2
l1cd5h:
- call sub_1e12h ;1cd5
- ld a,l ;1cd8
- push af ;1cd9
- add a,b ;1cda
- ld b,a ;1cdb
- pop af ;1cdc
- and 0c7h ;1cdd
- jr nz,l1d23h ;1cdf
- jp l1b36h ;1ce1
+ call sub_1e12h
+ ld a,l
+ push af
+ add a,b
+ ld b,a
+ pop af
+ and 0c7h
+ jr nz,l1d23h
+ jp l1b36h
l1ce4h:
- call sub_1e50h ;1ce4
- jr c,l1cf2h ;1ce7
- call sub_1e25h ;1ce9
- jr nc,l1d23h ;1cec
- add a,b ;1cee
- jp l19d7h ;1cef
+ call sub_1e50h
+ jr c,l1cf2h
+ call sub_1e25h
+ jr nc,l1d23h
+ add a,b
+ jp l19d7h
l1cf2h:
- ld a,b ;1cf2
- add a,020h ;1cf3
- jp l1b99h ;1cf5
+ ld a,b
+ add a,020h
+ jp l1b99h
l1cf8h:
- call sub_1e41h ;1cf8
- jr nc,l1d23h ;1cfb
- cp 006h ;1cfd
- jr z,l1d23h ;1cff
- rlca ;1d01
- rlca ;1d02
- rlca ;1d03
- add a,b ;1d04
- ld b,a ;1d05
- cp 078h ;1d06
- jr nz,l1d1ah ;1d08
- call sub_1ed1h ;1d0a
- call sub_1d26h ;1d0d
- jr c,l1d20h ;1d10
- call sub_1e06h ;1d12
- ld b,0dbh ;1d15
- jp l1a2fh ;1d17
+ call sub_1e41h
+ jr nc,l1d23h
+ cp 006h
+ jr z,l1d23h
+ rlca
+ rlca
+ rlca
+ add a,b
+ ld b,a
+ cp 078h
+ jr nz,l1d1ah
+ call sub_1ed1h
+ call sub_1d26h
+ jr c,l1d20h
+ call sub_1e06h
+ ld b,0dbh
+ jp l1a2fh
l1d1ah:
- call sub_1ed1h ;1d1a
- call sub_1d26h ;1d1d
+ call sub_1ed1h
+ call sub_1d26h
l1d20h:
- jp c,gen.opc.ED2 ;1d20
+ jp c,gen.opc.ED2
l1d23h:
- jp ERROR ;1d23
+ jp ERROR
sub_1d26h:
- ld hl,t__C_ ;1d26
- jp sub_0a23h ;1d29
+ ld hl,t__C_
+ jp sub_0a23h
l1d2ch:
- call sub_1d26h ;1d2c
- jr nc,l1d44h ;1d2f
- call sub_1ed1h ;1d31
- call sub_1e41h ;1d34
- jr nc,l1d23h ;1d37
- cp 006h ;1d39
- jr z,l1d23h ;1d3b
- rlca ;1d3d
- rlca ;1d3e
- rlca ;1d3f
- add a,b ;1d40
- jp l1b71h ;1d41
+ call sub_1d26h
+ jr nc,l1d44h
+ call sub_1ed1h
+ call sub_1e41h
+ jr nc,l1d23h
+ cp 006h
+ jr z,l1d23h
+ rlca
+ rlca
+ rlca
+ add a,b
+ jp l1b71h
l1d44h:
- call sub_1e06h ;1d44
- call sub_1ed1h ;1d47
- cp 041h ;1d4a
- jr nz,l1d23h ;1d4c
- inc de ;1d4e
- ld b,0d3h ;1d4f
- jp l1a2fh ;1d51
+ call sub_1e06h
+ call sub_1ed1h
+ cp 041h
+ jr nz,l1d23h
+ inc de
+ ld b,0d3h
+ jp l1a2fh
l1d54h:
- ld hl,b_0x1D80_start ;1d54
- call sub_0a15h ;1d57
- jp nc,ERROR ;1d5a
- ld c,b ;1d5d
- call assert_eol ;1d5e
- ld b,000h ;1d61
- ld hl,b_0x1DA1_start ;1d63
- add hl,bc ;1d66
- add hl,bc ;1d67
- ld a,(hl) ;1d68
- comst ;1d69
- ld (iy+000h),a ;1d6d
+ ld hl,b_0x1D80_start
+ call sub_0a15h
+ jp nc,ERROR
+ ld c,b
+ call assert_eol
+ ld b,000h
+ ld hl,b_0x1DA1_start
+ add hl,bc
+ add hl,bc
+ ld a,(hl)
+ comst
+ ld (iy+000h),a
comend
- ld c,001h ;1d70
- inc hl ;1d72
- ld a,(hl) ;1d73
- and a ;1d74
- ret z ;1d75
- comst ;1d76
- ld (iy+001h),a ;1d7a
+ ld c,001h
+ inc hl
+ ld a,(hl)
+ and a
+ ret z
+ comst
+ ld (iy+001h),a
comend
- ld c,002h ;1d7d
- ret ;1d7f
+ ld c,002h
+ ret
b_0x1D80_start:
DC 'AF,AF'''
@@ -4038,1359 +4062,1360 @@ l1d86h:
DC '(SP),HL'
DC '(SP),IX'
DC '(SP),IY'
- db 000h ;1da0
+ db 000h
b_0x1DA1_start:
- db 008h ;1da1
- db 000h ;1da2
- db 0ebh ;1da3
- db 000h ;1da4
- db 0e3h ;1da5
- db 000h ;1da6
- db 0ddh ;1da7
- db 0e3h ;1da8
- db 0fdh ;1da9
- db 0e3h ;1daa
+ db 008h
+ db 000h
+ db 0ebh
+ db 000h
+ db 0e3h
+ db 000h
+ db 0ddh
+ db 0e3h
+ db 0fdh
+ db 0e3h
l1dabh:
- call sub_1e50h ;1dab
- jr c,l1dc6h ;1dae
- call sub_1e2eh ;1db0
- jr c,l1dd2h ;1db3
- call sub_1e41h ;1db5
- jr c,l1ddfh ;1db8
- call sub_1e68h ;1dba
- jp nc,ERROR ;1dbd
- ld a,b ;1dc0
- add a,030h ;1dc1
- jp l19ebh ;1dc3
+ call sub_1e50h
+ jr c,l1dc6h
+ call sub_1e2eh
+ jr c,l1dd2h
+ call sub_1e41h
+ jr c,l1ddfh
+ call sub_1e68h
+ jp nc,ERROR
+ ld a,b
+ add a,030h
+ jp l19ebh
l1dc6h:
- ld a,b ;1dc6
- ld b,023h ;1dc7
- cp 004h ;1dc9
- jr z,l1dcfh ;1dcb
- ld b,02bh ;1dcd
+ ld a,b
+ ld b,023h
+ cp 004h
+ jr z,l1dcfh
+ ld b,02bh
l1dcfh:
- jp l1aabh ;1dcf
+ jp l1aabh
l1dd2h:
- push af ;1dd2
- ld a,b ;1dd3
- ld b,003h ;1dd4
- cp 004h ;1dd6
- jr z,l1ddch ;1dd8
- ld b,00bh ;1dda
+ push af
+ ld a,b
+ ld b,003h
+ cp 004h
+ jr z,l1ddch
+ ld b,00bh
l1ddch:
- pop af ;1ddc
- jr l1de2h ;1ddd
+ pop af
+ jr l1de2h
l1ddfh:
- rlca ;1ddf
- rlca ;1de0
- rlca ;1de1
+ rlca
+ rlca
+ rlca
l1de2h:
- add a,b ;1de2
- jp l19d7h ;1de3
+ add a,b
+ jp l19d7h
sub_1de6h:
- call sub_1e12h ;1de6
- ld a,l ;1de9
- cp 008h ;1dea
- jr nc,error1 ;1dec
- ret ;1dee
+ call sub_1e12h
+ ld a,l
+ cp 008h
+ jr nc,error1
+ ret
sub_1defh:
- call tst_EXPR ;1def
- push bc ;1df2
- push iy ;1df3
- pop bc ;1df5
- and a ;1df6
- sbc hl,bc ;1df7
- dec hl ;1df9
- dec hl ;1dfa
- pop bc ;1dfb
- call sub_1e15h ;1dfc
- ld a,h ;1dff
- xor l ;1e00
- bit 7,a ;1e01
- jr nz,error1 ;1e03
- ret ;1e05
+ call tst_EXPR
+ push bc
+ push iy
+ pop bc
+ and a
+ sbc hl,bc
+ dec hl
+ dec hl
+ pop bc
+ call sub_1e15h
+ ld a,h
+ xor l
+ bit 7,a
+ jr nz,error1
+ ret
sub_1e06h:
- ld a,(de) ;1e06
- cp 028h ;1e07
- jr nz,sub_1e12h ;1e09
- inc de ;1e0b
- call sub_1e12h ;1e0c
- jp sub_1ed8h ;1e0f
+ ld a,(de)
+ cp 028h
+ jr nz,sub_1e12h
+ inc de
+ call sub_1e12h
+ jp sub_1ed8h
sub_1e12h:
- call tst_EXPR ;1e12
+ call tst_EXPR
sub_1e15h:
- ld a,h ;1e15
- and a ;1e16
- ret z ;1e17
- inc a ;1e18
- ret z ;1e19
- jr error1 ;1e1a
+ ld a,h
+ and a
+ ret z
+ inc a
+ ret z
+ jr error1
tst_EXPR:
- push bc ;1e1c
- call EXPR ;1e1d
- pop bc ;1e20
- ret nc ;1e21
+ push bc
+ call EXPR
+ pop bc
+ ret nc
error1:
- jp ERROR ;1e22
+ jp ERROR
sub_1e25h:
- push hl ;1e25
- ld hl,t_BC.DE.HL.AF ;1e26
- jr l1e32h ;1e29
+ push hl
+ ld hl,t_BC.DE.HL.AF
+ jr l1e32h
sub_1e2bh:
- push hl ;1e2b
- jr l1e32h ;1e2c
+ push hl
+ jr l1e32h
sub_1e2eh:
- push hl ;1e2e
- ld hl,t_BC.DE.HL.SP ;1e2f
+ push hl
+ ld hl,t_BC.DE.HL.SP
l1e32h:
- push bc ;1e32
- call sub_0a15h ;1e33
- jr nc,l1e3eh ;1e36
- ld a,b ;1e38
- rlca ;1e39
- rlca ;1e3a
- rlca ;1e3b
- rlca ;1e3c
- scf ;1e3d
+ push bc
+ call sub_0a15h
+ jr nc,l1e3eh
+ ld a,b
+ rlca
+ rlca
+ rlca
+ rlca
+ scf
l1e3eh:
- pop bc ;1e3e
- pop hl ;1e3f
- ret ;1e40
+ pop bc
+ pop hl
+ ret
sub_1e41h:
- call SKIPBL ;1e41
- push bc ;1e44
- push hl ;1e45
- ld hl,t_BCDEHL_HL_A ;1e46
- call sub_0a15h ;1e49
- ld a,b ;1e4c
- pop hl ;1e4d
- pop bc ;1e4e
- ret ;1e4f
+ call SKIPBL
+ push bc
+ push hl
+ ld hl,t_BCDEHL_HL_A
+ call sub_0a15h
+ ld a,b
+ pop hl
+ pop bc
+ ret
sub_1e50h:
- push hl ;1e50
- push bc ;1e51
- ld hl,t_IX.IY ;1e52
- call sub_0a15h ;1e55
- jr nc,l1e65h ;1e58
- ld a,0ddh ;1e5a
- dec b ;1e5c
- jr nz,l1e61h ;1e5d
- ld a,0fdh ;1e5f
+ push hl
+ push bc
+ ld hl,t_IX.IY
+ call sub_0a15h
+ jr nc,l1e65h
+ ld a,0ddh
+ dec b
+ jr nz,l1e61h
+ ld a,0fdh
l1e61h:
- ld (pfx.IXY),a ;1e61
- scf ;1e64
+ ld (pfx.IXY),a
+ scf
l1e65h:
- pop bc ;1e65
- pop hl ;1e66
- ret ;1e67
+ pop bc
+ pop hl
+ ret
sub_1e68h:
- push hl ;1e68
- push bc ;1e69
- ld a,(de) ;1e6a
- cp '(' ;1e6b
- jr nz,l1eb4h ;1e6d
- push de ;1e6f
- inc de ;1e70
- ld hl,t_IX.IY ;1e71
- call sub_0a15h ;1e74
- jr nc,l1eb3h ;1e77
- pop af ;1e79
- ld a,0ddh ;1e7a
- dec b ;1e7c
- jr nz,l1e81h ;1e7d
- ld a,0fdh ;1e7f
+ push hl
+ push bc
+ ld a,(de)
+ cp '('
+ jr nz,l1eb4h
+ push de
+ inc de
+ ld hl,t_IX.IY
+ call sub_0a15h
+ jr nc,l1eb3h
+ pop af
+ ld a,0ddh
+ dec b
+ jr nz,l1e81h
+ ld a,0fdh
l1e81h:
- ld (pfx.IXY),a ;1e81
- ld a,(de) ;1e84
- cp '+' ;1e85
- jr z,l1e95h ;1e87
- cp ')' ;1e89
- ld hl,0 ;1e8b
- jr z,l1eadh ;1e8e
- cp '-' ;1e90
- jp nz,ERROR ;1e92
+ ld (pfx.IXY),a
+ ld a,(de)
+ cp '+'
+ jr z,l1e95h
+ cp ')'
+ ld hl,0
+ jr z,l1eadh
+ cp '-'
+ jp nz,ERROR
l1e95h:
- push af ;1e95
- inc de ;1e96
+ push af
+ inc de
call sub_1e12h ;1e97 get displacement
- pop af ;1e9a
- cp '+' ;1e9b
- jr z,l1ea7h ;1e9d
- ld b,h ;1e9f
- ld c,l ;1ea0
- ld hl,0 ;1ea1
- and a ;1ea4
- sbc hl,bc ;1ea5
+ pop af
+ cp '+'
+ jr z,l1ea7h
+ ld b,h
+ ld c,l
+ ld hl,0
+ and a
+ sbc hl,bc
l1ea7h:
- ld a,(de) ;1ea7
- cp ')' ;1ea8
- jp nz,ERROR ;1eaa
+ ld a,(de)
+ cp ')'
+ jp nz,ERROR
l1eadh:
- inc de ;1ead
- pop bc ;1eae
- ld c,l ;1eaf
- pop hl ;1eb0
- scf ;1eb1
- ret ;1eb2
+ inc de
+ pop bc
+ ld c,l
+ pop hl
+ scf
+ ret
l1eb3h:
- pop de ;1eb3
+ pop de
l1eb4h:
- pop bc ;1eb4
- pop hl ;1eb5
- and a ;1eb6
- ret ;1eb7
+ pop bc
+ pop hl
+ and a
+ ret
sub_1eb8h:
- ld hl,t_tstfl_ZCPS ;1eb8
- ld c,007h ;1ebb
- jr l1ec4h ;1ebd
+ ld hl,t_tstfl_ZCPS
+ ld c,007h
+ jr l1ec4h
sub_1ebfh:
- ld hl,t_tstfl_ZC ;1ebf
- ld c,003h ;1ec2
+ ld hl,t_tstfl_ZC
+ ld c,003h
l1ec4h:
- push bc ;1ec4
- call sub_0a15h ;1ec5
- ld a,b ;1ec8
- pop bc ;1ec9
- ret nc ;1eca
- and c ;1ecb
- rlca ;1ecc
- rlca ;1ecd
- rlca ;1ece
- scf ;1ecf
- ret ;1ed0
+ push bc
+ call sub_0a15h
+ ld a,b
+ pop bc
+ ret nc
+ and c
+ rlca
+ rlca
+ rlca
+ scf
+ ret
sub_1ed1h:
- call skip_to_nextarg ;1ed1
- ret z ;1ed4
+ call skip_to_nextarg
+ ret z
l1ed5h:
- jp ERROR ;1ed5
+ jp ERROR
sub_1ed8h:
- ld a,(de) ;1ed8
- cp 029h ;1ed9
- jr nz,l1ed5h ;1edb
- inc de ;1edd
- ret ;1ede
+ ld a,(de)
+ cp 029h
+ jr nz,l1ed5h
+ inc de
+ ret
CMD.L:
- ld hl,CMD.L ;1edf
- ld (CMD_RPT),hl ;1ee2
- call EXPR ;1ee5
- jr nc,l1eedh ;1ee8
- ld hl,(lst.L) ;1eea
+ ld hl,CMD.L
+ ld (CMD_RPT),hl
+ call EXPR
+ jr nc,l1eedh
+ ld hl,(lst.L)
l1eedh:
- push hl ;1eed
- pop iy ;1eee
- call skip_to_nextarg ;1ef0
- call sub_0aa5h ;1ef3
- jr nc,l1f17h ;1ef6
- call assert_eol ;1ef8
- ld b,010h ;1efb
+ push hl
+ pop iy
+ call skip_to_nextarg
+ call sub_0aa5h
+ jr nc,l1f17h
+ call assert_eol
+ ld b,010h
l1efdh:
- push bc ;1efd
- push iy ;1efe
- pop hl ;1f00
- push hl ;1f01
- call sub_1f3fh ;1f02
- call CRLF ;1f05
- pop iy ;1f08
- ld c,b ;1f0a
- ld b,000h ;1f0b
- add iy,bc ;1f0d
- ld (lst.L),iy ;1f0f
- pop bc ;1f13
- djnz l1efdh ;1f14
- ret ;1f16
+ push bc
+ push iy
+ pop hl
+ push hl
+ call sub_1f3fh
+ call CRLF
+ pop iy
+ ld c,b
+ ld b,000h
+ add iy,bc
+ ld (lst.L),iy
+ pop bc
+ djnz l1efdh
+ ret
l1f17h:
- call assert_eol ;1f17
- ld h,b ;1f1a
- ld l,c ;1f1b
- ld a,b ;1f1c
- or c ;1f1d
- jr nz,l1f21h ;1f1e
- dec hl ;1f20
+ call assert_eol
+ ld h,b
+ ld l,c
+ ld a,b
+ or c
+ jr nz,l1f21h
+ dec hl
l1f21h:
- push hl ;1f21
- push iy ;1f22
- pop hl ;1f24
- push hl ;1f25
- call sub_1f3fh ;1f26
- call CRLF ;1f29
- pop iy ;1f2c
- ld e,b ;1f2e
- ld d,000h ;1f2f
- add iy,de ;1f31
- ld (lst.L),iy ;1f33
- pop hl ;1f37
- and a ;1f38
- sbc hl,de ;1f39
- ret z ;1f3b
- ret c ;1f3c
- jr l1f21h ;1f3d
+ push hl
+ push iy
+ pop hl
+ push hl
+ call sub_1f3fh
+ call CRLF
+ pop iy
+ ld e,b
+ ld d,000h
+ add iy,de
+ ld (lst.L),iy
+ pop hl
+ and a
+ sbc hl,de
+ ret z
+ ret c
+ jr l1f21h
sub_1f3fh:
- call out.hl.@ ;1f3f
- call z,OUTBL ;1f42
- call OUTBL ;1f45
- sub a ;1f48
- ld (CON.COL),a ;1f49
- call sub_1f77h ;1f4c
- and a ;1f4f
- ret z ;1f50
+ call out.hl.@
+ call z,OUTBL
+ call OUTBL
+ sub a
+ ld (CON.COL),a
+ call sub_1f77h
+ and a
+ ret z
l1f51h:
- call OUTBL ;1f51
- ld a,(CON.COL) ;1f54
- cp 010h ;1f57
- jr c,l1f51h ;1f59
+ call OUTBL
+ ld a,(CON.COL)
+ cp 010h
+ jr c,l1f51h
sub_1f5bh:
- ld de,(offs.@) ;1f5b
- ld a,d ;1f5f
- or e ;1f60
- ret z ;1f61
- ld a,'(' ;1f62
- call OUTCHAR ;1f64
- ld a,'@' ;1f67
- call OUTCHAR ;1f69
- and a ;1f6c
- sbc hl,de ;1f6d
- call out.hl ;1f6f
- ld a,')' ;1f72
- jp OUTCHAR ;1f74
+ ld de,(offs.@)
+ ld a,d
+ or e
+ ret z
+ ld a,'('
+ call OUTCHAR
+ ld a,'@'
+ call OUTCHAR
+ and a
+ sbc hl,de
+ call out.hl
+ ld a,')'
+ jp OUTCHAR
sub_1f77h:
- sub a ;1f77
- ld (XBE03),a ;1f78
- call sub_1f9eh ;1f7b
- jr nc,l1f91h ;1f7e
- push bc ;1f80
- call sub_2581h ;1f81
- ex de,hl ;1f84
- call sub_1fdbh ;1f85
- pop bc ;1f88
- ld a,(XBE03) ;1f89
- ld hl,(XBE01) ;1f8c
- scf ;1f8f
- ret ;1f90
+ sub a
+ ld (XBE03),a
+ call sub_1f9eh
+ jr nc,l1f91h
+ push bc
+ call sub_2581h
+ ex de,hl
+ call sub_1fdbh
+ pop bc
+ ld a,(XBE03)
+ ld hl,(XBE01)
+ scf
+ ret
l1f91h:
- ld hl,b_0x1F9B_start ;1f91
- call PSTR ;1f94
- ld b,001h ;1f97
- sub a ;1f99
- ret ;1f9a
+ ld hl,b_0x1F9B_start
+ call PSTR
+ ld b,001h
+ sub a
+ ret
b_0x1F9B_start:
DC '???'
-
+
sub_1f9eh:
- sub a ;1f9e
- ld (is.pfx.IXY),a ;1f9f
- comst ;1fa2
- ld a,(iy+000h) ;1fa6
+ sub a
+ ld (is.pfx.IXY),a
+ comst
+ ld a,(iy+000h)
comend
- cp 0edh ;1fa9
- jp z,disas_pfx.ED ;1fab
- cp 0ddh ;1fae
- jr z,l1fc5h ;1fb0
- cp 0fdh ;1fb2
- jr z,l1fc9h ;1fb4
+ cp 0edh
+ jp z,disas_pfx.ED
+ cp 0ddh
+ jr z,l1fc5h
+ cp 0fdh
+ jr z,l1fc9h
sub_1fb6h:
- comst ;1fb6
- ld a,(iy+000h) ;1fba
+ comst
+ ld a,(iy+000h)
comend
- cp 0cbh ;1fbd
- jp z,l2061h ;1fbf
- jp l2078h ;1fc2
+ cp 0cbh
+ jp z,l2061h
+ jp l2078h
l1fc5h:
- ld a,001h ;1fc5
- jr l1fcbh ;1fc7
+ ld a,001h
+ jr l1fcbh
l1fc9h:
- ld a,002h ;1fc9
+ ld a,002h
l1fcbh:
- ld (is.pfx.IXY),a ;1fcb
- call sub_1fdch ;1fce
- ret nc ;1fd1
- push bc ;1fd2
- call sub_1fb6h ;1fd3
- pop af ;1fd6
- add a,b ;1fd7
- ld b,a ;1fd8
- scf ;1fd9
- ret ;1fda
+ ld (is.pfx.IXY),a
+ call sub_1fdch
+ ret nc
+ push bc
+ call sub_1fb6h
+ pop af
+ add a,b
+ ld b,a
+ scf
+ ret
sub_1fdbh:
- jp (hl) ;1fdb
+ jp (hl)
sub_1fdch:
- inc iy ;1fdc
- ld hl,b_0x2011_start ;1fde
- call sub_20bbh ;1fe1
- ld b,002h ;1fe4
- ret c ;1fe6
- ld hl,l202ch ;1fe7
- call sub_20bbh ;1fea
- ld b,001h ;1fed
- ret c ;1fef
- comst ;1ff0
- ld a,(iy+000h) ;1ff4
+ inc iy
+ ld hl,b_0x2011_start
+ call sub_20bbh
+ ld b,002h
+ ret c
+ ld hl,l202ch
+ call sub_20bbh
+ ld b,001h
+ ret c
+ comst
+ ld a,(iy+000h)
comend
- cp 0cbh ;1ff7
- jr nz,l200fh ;1ff9
- comst ;1ffb
- ld a,(iy+002h) ;1fff
+ cp 0cbh
+ jr nz,l200fh
+ comst
+ ld a,(iy+002h)
comend
- cp 036h ;2002
- ret z ;2004
- and 007h ;2005
- cp 006h ;2007
- jr nz,l200fh ;2009
- ld b,002h ;200b
- scf ;200d
- ret ;200e
+ cp 036h
+ ret z
+ and 007h
+ cp 006h
+ jr nz,l200fh
+ ld b,002h
+ scf
+ ret
l200fh:
- and a ;200f
- ret ;2010
+ and a
+ ret
b_0x2011_start:
- db 034h ;2011
- db 035h ;2012
- db 036h ;2013
- db 046h ;2014
- db 04eh ;2015
- db 056h ;2016
- db 05eh ;2017
- db 066h ;2018
- db 06eh ;2019
- db 070h ;201a
- db 071h ;201b
- db 072h ;201c
- db 073h ;201d
- db 074h ;201e
- db 075h ;201f
- db 076h ;2020
- db 077h ;2021
- db 07eh ;2022
- db 086h ;2023
- db 08eh ;2024
- db 096h ;2025
- db 09eh ;2026
- db 0a6h ;2027
- db 0aeh ;2028
- db 0b6h ;2029
- db 0beh ;202a
- db 000h ;202b
+ db 034h
+ db 035h
+ db 036h
+ db 046h
+ db 04eh
+ db 056h
+ db 05eh
+ db 066h
+ db 06eh
+ db 070h
+ db 071h
+ db 072h
+ db 073h
+ db 074h
+ db 075h
+ db 076h
+ db 077h
+ db 07eh
+ db 086h
+ db 08eh
+ db 096h
+ db 09eh
+ db 0a6h
+ db 0aeh
+ db 0b6h
+ db 0beh
+ db 000h
l202ch:
- db 009h ;202c
- db 019h ;202d
- db 021h ;202e
- db 022h ;202f
- db 023h ;2030
- db 029h ;2031
- db 02ah ;2032
- db 02bh ;2033
- db 039h ;2034
- db 0e1h ;2035
- db 0e3h ;2036
- db 0e5h ;2037
- db 0e9h ;2038
- db 0f9h ;2039
- db 000h ;203a
+ db 009h
+ db 019h
+ db 021h
+ db 022h
+ db 023h
+ db 029h
+ db 02ah
+ db 02bh
+ db 039h
+ db 0e1h
+ db 0e3h
+ db 0e5h
+ db 0e9h
+ db 0f9h
+ db 000h
disas_pfx.ED:
- inc iy ;203b
- ld hl,b_0x2200_start ;203d
- call sub_209dh ;2040
- ld b,002h ;2043
- ret c ;2045
- ld hl,l2235h ;2046
- call lookup_opc ;2049
- ld b,002h ;204c
- ret c ;204e
- ld hl,l228bh ;204f
- call lookup_opc ;2052
- ld b,003h ;2055
- ret c ;2057
- ld hl,l22b4h ;2058
- call lookup_opc ;205b
- ld b,004h ;205e
- ret ;2060
+ inc iy
+ ld hl,b_0x2200_start
+ call sub_209dh
+ ld b,002h
+ ret c
+ ld hl,l2235h
+ call lookup_opc
+ ld b,002h
+ ret c
+ ld hl,l228bh
+ call lookup_opc
+ ld b,003h
+ ret c
+ ld hl,l22b4h
+ call lookup_opc
+ ld b,004h
+ ret
l2061h:
- push iy ;2061
- inc iy ;2063
- ld a,(is.pfx.IXY) ;2065
- and a ;2068
- jr z,l206dh ;2069
- inc iy ;206b
+ push iy
+ inc iy
+ ld a,(is.pfx.IXY)
+ and a
+ jr z,l206dh
+ inc iy
l206dh:
- ld hl,l22c9h ;206d
- call lookup_opc ;2070
- pop iy ;2073
- ld b,002h ;2075
- ret ;2077
+ ld hl,l22c9h
+ call lookup_opc
+ pop iy
+ ld b,002h
+ ret
l2078h:
- ld hl,b_0x218B_start ;2078
- call lookup_opc ;207b
- ld b,002h ;207e
- ret c ;2080
- ld hl,b_0x20ED_start ;2081
- call sub_209dh ;2084
- ld b,001h ;2087
- ret c ;2089
- ld hl,b_0x2108_start ;208a
- call lookup_opc ;208d
- ld b,001h ;2090
- ret c ;2092
- ld hl,b_0x21D2_start ;2093
- call lookup_opc ;2096
- ret nc ;2099
- ld b,003h ;209a
- ret ;209c
+ ld hl,b_0x218B_start
+ call lookup_opc
+ ld b,002h
+ ret c
+ ld hl,b_0x20ED_start
+ call sub_209dh
+ ld b,001h
+ ret c
+ ld hl,b_0x2108_start
+ call lookup_opc
+ ld b,001h
+ ret c
+ ld hl,b_0x21D2_start
+ call lookup_opc
+ ret nc
+ ld b,003h
+ ret
sub_209dh:
- ld a,(hl) ;209d
- cp 0ffh ;209e
- ret z ;20a0
- comst ;20a1
- cp (iy+000h) ;20a5
+ ld a,(hl)
+ cp 0ffh
+ ret z
+ comst
+ cp (iy+000h)
comend
- jr z,l20aeh ;20a8
- inc hl ;20aa
- inc hl ;20ab
- jr sub_209dh ;20ac
+ jr z,l20aeh
+ inc hl
+ inc hl
+ jr sub_209dh
l20aeh:
- inc hl ;20ae
- ld c,(hl) ;20af
- ld hl,t_MNEMONICS ;20b0
- ld b,000h ;20b3
- add hl,bc ;20b5
- ld de,l230bh ;20b6
- scf ;20b9
- ret ;20ba
+ inc hl
+ ld c,(hl)
+ ld hl,t_MNEMONICS
+ ld b,000h
+ add hl,bc
+ ld de,l230bh
+ scf
+ ret
sub_20bbh:
- ld a,(hl) ;20bb
- and a ;20bc
- ret z ;20bd
- inc hl ;20be
- comst ;20bf
- cp (iy+000h) ;20c3
+ ld a,(hl)
+ and a
+ ret z
+ inc hl
+ comst
+ cp (iy+000h)
comend
- jr nz,sub_20bbh ;20c6
- scf ;20c8
- ret ;20c9
+ jr nz,sub_20bbh
+ scf
+ ret
lookup_opc:
- comst ;20ca
- ld a,(iy+000h) ;20ce
+ comst
+ ld a,(iy+000h)
comend
- and (hl) ;20d1
- inc hl ;20d2
- cp (hl) ;20d3
- jr z,l20dfh ;20d4
- inc hl ;20d6
- inc hl ;20d7
- inc hl ;20d8
- inc hl ;20d9
- ld a,(hl) ;20da
- and a ;20db
- jr nz,lookup_opc ;20dc
- ret ;20de
+ and (hl)
+ inc hl
+ cp (hl)
+ jr z,l20dfh
+ inc hl
+ inc hl
+ inc hl
+ inc hl
+ ld a,(hl)
+ and a
+ jr nz,lookup_opc
+ ret
l20dfh:
- inc hl ;20df
- ld c,(hl) ;20e0
- inc hl ;20e1
- ld e,(hl) ;20e2
- inc hl ;20e3
- ld d,(hl) ;20e4
- ld hl,t_MNEMONICS ;20e5
- ld b,000h ;20e8
- add hl,bc ;20ea
- scf ;20eb
- ret ;20ec
+ inc hl
+ ld c,(hl)
+ inc hl
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ ld hl,t_MNEMONICS
+ ld b,000h
+ add hl,bc
+ scf
+ ret
b_0x20ED_start: ; 1 byte opcodes (no parameters)
db 076h ;20ed halt
- db 039h ;20ee
+ db 039h ;20ee
db 0d9h ;20ef exx
- db 036h ;20f0
+ db 036h
db 0f3h ;20f1 di
- db 02ch ;20f2
+ db 02ch
db 0fbh ;20f3 ei
- db 032h ;20f4
+ db 032h
db 000h ;20f5 nop
- db 069h ;20f6
+ db 069h
db 007h ;20f7 rlca
- db 09eh ;20f8
+ db 09eh
db 00fh ;20f9 rrca
- db 0adh ;20fa
+ db 0adh
db 017h ;20fb rla
- db 098h ;20fc
+ db 098h
db 01fh ;20fd rra
- db 0a7h ;20fe
+ db 0a7h
db 027h ;20ff daa
- db 026h ;2100
+ db 026h
db 02fh ;2101 cpl
- db 023h ;2102
+ db 023h
db 037h ;2103 scf
- db 0bah ;2104
+ db 0bah
db 03fh ;2105 ccf
- db 010h ;2106
+ db 010h
db 0ffh ;2107 EOT
b_0x2108_start: ; 1 byte opcodes
defb 0c0h ;2108 ld r,r
- defb 040h ;2109
- defb 056h ;210a
- defw l22fch ;210b
+ defb 040h
+ defb 056h
+ defw l22fch
defb 0f8h ;210d add a,r
- defb 080h ;210e
- defb 003h ;210f
- defw l2305h ;2110
+ defb 080h
+ defb 003h
+ defw l2305h
defb 0f8h ;2112 adc a,r
- defb 088h ;2113
- defb 000h ;2114
- defw l2305h ;2115
-
- defb 0f8h ;2117
- defb 090h ;2118
- defb 0c9h ;2119
- defw l24ebh ;211a
-
- defb 0f8h ;211c
- defb 098h ;211d
- defb 0b7h ;211e
- defw l2305h ;211f
-
- defb 0f8h ;2121
- defb 0a0h ;2122
- defb 006h ;2123
- defw l24ebh ;2124
-
- defb 0f8h ;2126
- defb 0a8h ;2127
- defb 0cch ;2128
- defw l24ebh ;2129
-
- defb 0f8h ;212b
- defb 0b0h ;212c
- defb 06ch ;212d
- defw l24ebh ;212e
-
- defb 0f8h ;2130
- defb 0b8h ;2131
- defb 013h ;2132
- defw l24ebh ;2133
-
- defb 0c7h ;2135
+ defb 088h
+ defb 000h
+ defw l2305h
+
+ defb 0f8h
+ defb 090h
+ defb 0c9h
+ defw l24ebh
+
+ defb 0f8h
+ defb 098h
+ defb 0b7h
+ defw l2305h
+
+ defb 0f8h
+ defb 0a0h
+ defb 006h
+ defw l24ebh
+
+ defb 0f8h
+ defb 0a8h
+ defb 0cch
+ defw l24ebh
+
+ defb 0f8h
+ defb 0b0h
+ defb 06ch
+ defw l24ebh
+
+ defb 0f8h
+ defb 0b8h
+ defb 013h
+ defw l24ebh
+
+ defb 0c7h
defb 0c0h ;2136 ret cc
- defb 08bh ;2137
- defw l2561h ;2138
+ defb 08bh
+ defw l2561h
defb 0c7h ;213a rst
- defb 0c7h ;213b
- defb 0b4h ;213c
- defw l231eh ;213d
+ defb 0c7h
+ defb 0b4h
+ defw l231eh
defb 0ffh ;213f ret
- defb 0c9h ;2140
- defb 08bh ;2141
- defw l230bh ;2142
+ defb 0c9h
+ defb 08bh
+ defw l230bh
defb 0cfh ;2144 pop rr
- defb 0c1h ;2145
- defb 081h ;2146
- defw l2546h ;2147
+ defb 0c1h
+ defb 081h
+ defw l2546h
defb 0cfh ;2149 push rr
- defb 0c5h ;214a
- defb 084h ;214b
- defw l2546h ;214c
+ defb 0c5h
+ defb 084h
+ defw l2546h
defb 0ffh ;214e ex (sp),hl
- defb 0e3h ;214f
- defb 034h ;2150
- defw l232ah ;2151
+ defb 0e3h
+ defb 034h
+ defw l232ah
defb 0ffh ;2153 jp (hl)
- defb 0e9h ;2154
- defb 052h ;2155
- defw l2338h ;2156
+ defb 0e9h
+ defb 052h
+ defw l2338h
defb 0ffh ;2158 ex de,hl
- defb 0ebh ;2159
- defb 034h ;215a
- defw l2345h ;215b
+ defb 0ebh
+ defb 034h
+ defw l2345h
defb 0ffh ;215d ld sp,hl
- defb 0f9h ;215e
- defb 056h ;215f
- defw l234bh ;2160
+ defb 0f9h
+ defb 056h
+ defw l234bh
defb 0cfh ;2162 inc rr
- defb 003h ;2163
- defb 041h ;2164
- defw l254bh ;2165
+ defb 003h
+ defb 041h
+ defw l254bh
defb 0cfh ;2167 dec rr
- defb 00bh ;2168
- defb 029h ;2169
- defw l254bh ;216a
+ defb 00bh
+ defb 029h
+ defw l254bh
+
defb 0c7h ;216c inc r
- defb 004h ;216d
- defb 041h ;216e
- defw l24dfh ;216f
+ defb 004h
+ defb 041h
+ defw l24dfh
defb 0c7h ;2171 dec r
- defb 005h ;2172
- defb 029h ;2173
- defw l24dfh ;2174
+ defb 005h
+ defb 029h
+ defw l24dfh
defb 0ffh ;2176 ex af,af'
- defb 008h ;2177
- defb 034h ;2178
- defw l2357h ;2179
+ defb 008h
+ defb 034h
+ defw l2357h
defb 0cfh ;217b add hl,rr
- defb 009h ;217c
- defb 003h ;217d
- defw l235dh ;217e
+ defb 009h
+ defb 003h
+ defw l235dh
defb 0efh ;2180 ld (rr),a ;rr=bc,de
- defb 002h ;2181
- defb 056h ;2182
- defw l2366h ;2183
+ defb 002h
+ defb 056h
+ defw l2366h
defb 0efh ;2185 ld a,(rr) ;rr=bc,de
- defb 00ah ;2186
- defb 056h ;2187
- defw l236fh ;2188
+ defb 00ah
+ defb 056h
+ defw l236fh
defb 000h ;218a EOT
b_0x218B_start: ; 2 byte opdodes
defb 0c7h ;218b ld r,nn
- defb 006h ;218c
- defb 056h ;218d
- defw l2384h ;218e
+ defb 006h
+ defb 056h
+ defw l2384h
defb 0ffh ;2190 add a,nn
- defb 0c6h ;2191
- defb 003h ;2192
- defw l237fh ;2193
+ defb 0c6h
+ defb 003h
+ defw l237fh
defb 0ffh ;2195 adc a,nn
- defb 0ceh ;2196
- defb 000h ;2197
- defw l237fh ;2198
+ defb 0ceh
+ defb 000h
+ defw l237fh
defb 0ffh ;219a sub a,nn
- defb 0d6h ;219b
- defb 0c9h ;219c
- defw l2397h ;219d
+ defb 0d6h
+ defb 0c9h
+ defw l2397h
- defb 0ffh ;219f
- defb 0deh ;21a0
- defb 0b7h ;21a1
- defw l237fh ;21a2
+ defb 0ffh
+ defb 0deh
+ defb 0b7h
+ defw l237fh
defb 0ffh ;21a4 and a,nn
- defb 0e6h ;21a5
- defb 006h ;21a6
- defw l2397h ;21a7
+ defb 0e6h
+ defb 006h
+ defw l2397h
- defb 0ffh ;21a9
- defb 0eeh ;21aa
- defb 0cch ;21ab
- defw l2397h ;21ac
+ defb 0ffh
+ defb 0eeh
+ defb 0cch
+ defw l2397h
- defb 0ffh ;21ae
- defb 0f6h ;21af
- defb 06ch ;21b0
- defw l2397h ;21b1
+ defb 0ffh
+ defb 0f6h
+ defb 06ch
+ defw l2397h
defb 0ffh ;21b3 cp a,nn
- defb 0feh ;21b4
- defb 013h ;21b5
- defw l2397h ;21b6
+ defb 0feh
+ defb 013h
+ defw l2397h
defb 0ffh ;21b8 djnz
- defb 010h ;21b9
- defb 02eh ;21ba
- defw l23b0h ;21bb
+ defb 010h
+ defb 02eh
+ defw l23b0h
defb 0ffh ;21bd jr
- defb 018h ;21be
- defb 054h ;21bf
- defw l23b0h ;21c0
+ defb 018h
+ defb 054h
+ defw l23b0h
defb 0e7h ;21c2 jr,cc
- defb 020h ;21c3
- defb 054h ;21c4
- defw l23a1h ;21c5
+ defb 020h
+ defb 054h
+ defw l23a1h
- defb 0ffh ;21c7
+ defb 0ffh
defb 0d3h ;21c8 out (nn),a
- defb 076h ;21c9
- defw l23d5h ;21ca
+ defb 076h
+ defw l23d5h
defb 0ffh ;21cc in a,(nn)
- defb 0dbh ;21cd
- defb 03fh ;21ce
- defw l23c3h ;21cf
+ defb 0dbh
+ defb 03fh
+ defw l23c3h
defb 000h ;21d1 EOT
b_0x21D2_start: ; 3 byte opcodes
- defb 0c7h ;21d2
- defb 0c2h ;21d3
- defb 052h ;21d4
- defw l23e0h ;21d5
-
- defb 0c7h ;21d7
- defb 0c4h ;21d8
- defb 00ch ;21d9
- defw l23e0h ;21da
-
- defb 0cfh ;21dc
- defb 001h ;21dd
- defb 056h ;21de
- defw l23fch ;21df
-
- defb 0ffh ;21e1
- defb 0c3h ;21e2
- defb 052h ;21e3
- defw l23e6h ;21e4
-
- defb 0ffh ;21e6
- defb 0cdh ;21e7
- defb 00ch ;21e8
- defw l23e6h ;21e9
-
- defb 0ffh ;21eb
- defb 022h ;21ec
- defb 056h ;21ed
- defw l2404h ;21ee
-
- defb 0ffh ;21f0
- defb 02ah ;21f1
- defb 056h ;21f2
- defw l240dh ;21f3
-
- defb 0ffh ;21f5
- defb 032h ;21f6
- defb 056h ;21f7
- defw l2416h ;21f8
-
- defb 0ffh ;21fa
- defb 03ah ;21fb
- defb 056h ;21fc
- defw l2421h ;21fd
-
- defb 000h ;21ff
+ defb 0c7h
+ defb 0c2h
+ defb 052h
+ defw l23e0h
+
+ defb 0c7h
+ defb 0c4h
+ defb 00ch
+ defw l23e0h
+
+ defb 0cfh
+ defb 001h
+ defb 056h
+ defw l23fch
+
+ defb 0ffh
+ defb 0c3h
+ defb 052h
+ defw l23e6h
+
+ defb 0ffh
+ defb 0cdh
+ defb 00ch
+ defw l23e6h
+
+ defb 0ffh
+ defb 022h
+ defb 056h
+ defw l2404h
+
+ defb 0ffh
+ defb 02ah
+ defb 056h
+ defw l240dh
+
+ defb 0ffh
+ defb 032h
+ defb 056h
+ defw l2416h
+
+ defb 0ffh
+ defb 03ah
+ defb 056h
+ defw l2421h
+
+ defb 000h
b_0x2200_start: ; prefix ED + 1 byte opcode
defb 044h ;2200 neg
- defb 066h ;2201
+ defb 066h
defb 045h ;2202 retn
- defb 092h ;2203
+ defb 092h
defb 04dh ;2204 reti
- defb 08eh ;2205
+ defb 08eh
defb 067h ;2206 rrd
- defb 0b1h ;2207
+ defb 0b1h
defb 06fh ;2208 rld
- defb 0a2h ;2209
+ defb 0a2h
defb 0a0h ;220a ldi
- defb 05fh ;220b
- defb 0a1h ;220c
- defb 01ch ;220d
- defb 0a2h ;220e
- defb 04bh ;220f
- defb 0a3h ;2210
- defb 07dh ;2211
+ defb 05fh
+ defb 0a1h
+ defb 01ch
+ defb 0a2h
+ defb 04bh
+ defb 0a3h
+ defb 07dh
defb 0a8h ;2212 ldd
- defb 058h ;2213
- defb 0a9h ;2214
- defb 015h ;2215
- defb 0aah ;2216
- defb 044h ;2217
- defb 0abh ;2218
- defb 079h ;2219
+ defb 058h
+ defb 0a9h
+ defb 015h
+ defb 0aah
+ defb 044h
+ defb 0abh
+ defb 079h
defb 0b0h ;221a ldir
- defb 062h ;221b
- defb 0b1h ;221c
- defb 01fh ;221d
- defb 0b2h ;221e
- defb 04eh ;221f
- defb 0b3h ;2220
- defb 072h ;2221
+ defb 062h
+ defb 0b1h
+ defb 01fh
+ defb 0b2h
+ defb 04eh
+ defb 0b3h
+ defb 072h
defb 0b8h ;2222 lddr
- defb 05bh ;2223
- defb 0b9h ;2224
- defb 018h ;2225
- defb 0bah ;2226
- defb 047h ;2227
- defb 0bbh ;2228
- defb 06eh ;2229
+ defb 05bh
+ defb 0b9h
+ defb 018h
+ defb 0bah
+ defb 047h
+ defb 0bbh
+ defb 06eh
defb 08bh ;222a otdm
- defb 0d5h ;222b
+ defb 0d5h
defb 09bh ;222c otdmr
- defb 0d9h ;222d
+ defb 0d9h
defb 083h ;222e otim
- defb 0deh ;222f
+ defb 0deh
defb 093h ;2230 otimr
- defb 0e2h ;2231
+ defb 0e2h
defb 076h ;2232 slp
- defb 0ebh ;2233
+ defb 0ebh
defb 0ffh ;2234 EOT
-
+
l2235h:
defb 0e7h ;2235 in r,(c) ;r=bcde
- defb 040h ;2236
- defb 03fh ;2237
- defw l2455h ;2238
+ defb 040h
+ defb 03fh
+ defw l2455h
defb 0f7h ;223a in r,(c) ;r=hl
- defb 060h ;223b
- defb 03fh ;223c
- defw l2455h ;223d
+ defb 060h
+ defb 03fh
+ defw l2455h
defb 0ffh ;223f in r,(c) ;r=a
- defb 078h ;2240
- defb 03fh ;2241
- defw l2455h ;2242
+ defb 078h
+ defb 03fh
+ defw l2455h
- defb 0e7h ;2244
- defb 041h ;2245
- defb 076h ;2246
- defw l2461h ;2247
+ defb 0e7h
+ defb 041h
+ defb 076h
+ defw l2461h
- defb 0f7h ;2249
- defb 061h ;224a
- defb 076h ;224b
- defw l2461h ;224c
+ defb 0f7h
+ defb 061h
+ defb 076h
+ defw l2461h
defb 0ffh ;224e out (c),r ;r=a
- defb 079h ;224f
- defb 076h ;2250
- defw l2461h ;2251
+ defb 079h
+ defb 076h
+ defw l2461h
defb 0cfh ;2253 sbc hl,rr
- defb 042h ;2254
- defb 0b7h ;2255
- defw l246dh ;2256
+ defb 042h
+ defb 0b7h
+ defw l246dh
defb 0cfh ;2258 adc hl,rr
- defb 04ah ;2259
- defb 000h ;225a
- defw l246dh ;225b
+ defb 04ah
+ defb 000h
+ defw l246dh
defb 0ffh ;225d im 0
- defb 046h ;225e
- defb 03dh ;225f
- defw l2427h ;2260
+ defb 046h
+ defb 03dh
+ defw l2427h
defb 0ffh ;2262 im 1
- defb 056h ;2263
- defb 03dh ;2264
- defw l242bh ;2265
+ defb 056h
+ defb 03dh
+ defw l242bh
defb 0ffh ;2267 im 2
- defb 05eh ;2268
- defb 03dh ;2269
- defw l242fh ;226a
+ defb 05eh
+ defb 03dh
+ defw l242fh
defb 0ffh ;226c ld i,a
- defb 047h ;226d
- defb 056h ;226e
- defw l2434h ;226f
+ defb 047h
+ defb 056h
+ defw l2434h
- defb 0ffh ;2271
- defb 057h ;2272
- defb 056h ;2273
- defw l2439h ;2274
+ defb 0ffh
+ defb 057h
+ defb 056h
+ defw l2439h
- defb 0ffh ;2276
- defb 04fh ;2277
- defb 056h ;2278
- defw l243eh ;2279
+ defb 0ffh
+ defb 04fh
+ defb 056h
+ defw l243eh
- defb 0ffh ;227b
- defb 05fh ;227c
- defb 056h ;227d
- defw l2443h ;227e
+ defb 0ffh
+ defb 05fh
+ defb 056h
+ defw l2443h
defb 0cfh ;2280 mlt rr
- defb 04ch ;2281
- defb 0d2h ;2282
- defw l254bh ;2283
+ defb 04ch
+ defb 0d2h
+ defw l254bh
defb 0c7h ;2285 tst r
- defb 004h ;2286
- defb 0eeh ;2287
- defw l24dfh ;2288
+ defb 004h
+ defb 0eeh
+ defw l24dfh
- defb 000h ;228a
+ defb 000h
l228bh:
- defb 0e7h ;228b
- defb 000h ;228c
- defb 0cfh ;228d
+ defb 0e7h
+ defb 000h
+ defb 0cfh
b_0x228E_start:
- defw l230ch ;228e
+ defw l230ch
b_0x2290_start:
- defb 0f7h ;2290
- defb 020h ;2291
- defb 0cfh ;2292
+ defb 0f7h
+ defb 020h
+ defb 0cfh
b_0x2293_start:
- defw l230ch ;2293
+ defw l230ch
b_0x2295_start:
- defb 0ffh ;2295
- defb 038h ;2296
- defb 0cfh ;2297
+ defb 0ffh
+ defb 038h
+ defb 0cfh
b_0x2298_start:
- defw l230ch ;2298
+ defw l230ch
b_0x229A_start:
- defb 0e7h ;229a
- defb 001h ;229b
- defb 0e7h ;229c
+ defb 0e7h
+ defb 001h
+ defb 0e7h
b_0x229D_start:
- defw l2315h ;229d
+ defw l2315h
b_0x229F_start:
- defb 0f7h ;229f
- defb 021h ;22a0
- defb 0e7h ;22a1
+ defb 0f7h
+ defb 021h
+ defb 0e7h
b_0x22A2_start:
- defw l2315h ;22a2
+ defw l2315h
b_0x22A4_start:
- defb 0ffh ;22a4
- defb 039h ;22a5
- defb 0e7h ;22a6
+ defb 0ffh
+ defb 039h
+ defb 0e7h
b_0x22A7_start:
- defw l2315h ;22a7
+ defw l2315h
b_0x22A9_start:
- defb 0ffh ;22a9
- defb 064h ;22aa
- defb 0eeh ;22ab
+ defb 0ffh
+ defb 064h
+ defb 0eeh
b_0x22AC_start:
- defw l2397h ;22ac
+ defw l2397h
b_0x22AE_start:
- defb 0ffh ;22ae
- defb 074h ;22af
- defb 0f1h ;22b0
+ defb 0ffh
+ defb 074h
+ defb 0f1h
b_0x22B1_start:
- defw l2397h ;22b1
+ defw l2397h
b_0x22B3_start:
- defb 000h ;22b3
+ defb 000h
l22b4h:
- defb 0efh ;22b4
- defb 043h ;22b5
- defb 056h ;22b6
+ defb 0efh
+ defb 043h
+ defb 056h
b_0x22B7_start:
- defw l2476h ;22b7
+ defw l2476h
b_0x22B9_start:
- defb 0ffh ;22b9
- defb 073h ;22ba
- defb 056h ;22bb
+ defb 0ffh
+ defb 073h
+ defb 056h
b_0x22BC_start:
- defw l2476h ;22bc
+ defw l2476h
b_0x22BE_start:
- defb 0efh ;22be
- defb 04bh ;22bf
- defb 056h ;22c0
+ defb 0efh
+ defb 04bh
+ defb 056h
b_0x22C1_start:
- defw l247fh ;22c1
+ defw l247fh
b_0x22C3_start:
- defb 0ffh ;22c3
- defb 07bh ;22c4
- defb 056h ;22c5
+ defb 0ffh
+ defb 07bh
+ defb 056h
b_0x22C6_start:
- defw l247fh ;22c6
+ defw l247fh
b_0x22C8_start:
- defb 000h ;22c8
+ defb 000h
l22c9h:
- defb 0f8h ;22c9
- defb 000h ;22ca
- defb 09bh ;22cb
+ defb 0f8h
+ defb 000h
+ defb 09bh
b_0x22CC_start:
- defw l24aeh ;22cc
+ defw l24aeh
b_0x22CE_start:
- defb 0f8h ;22ce
- defb 008h ;22cf
- defb 0aah ;22d0
+ defb 0f8h
+ defb 008h
+ defb 0aah
b_0x22D1_start:
- defw l24aeh ;22d1
+ defw l24aeh
b_0x22D3_start:
- defb 0f8h ;22d3
- defb 010h ;22d4
- defb 096h ;22d5
+ defb 0f8h
+ defb 010h
+ defb 096h
b_0x22D6_start:
- defw l24aeh ;22d6
+ defw l24aeh
b_0x22D8_start:
- defb 0f8h ;22d8
- defb 018h ;22d9
- defb 0a5h ;22da
+ defb 0f8h
+ defb 018h
+ defb 0a5h
b_0x22DB_start:
- defw l24aeh ;22db
+ defw l24aeh
b_0x22DD_start:
- defb 0f8h ;22dd
- defb 020h ;22de
- defb 0c0h ;22df
+ defb 0f8h
+ defb 020h
+ defb 0c0h
b_0x22E0_start:
- defw l24aeh ;22e0
+ defw l24aeh
b_0x22E2_start:
- defb 0f8h ;22e2
- defb 028h ;22e3
- defb 0c3h ;22e4
+ defb 0f8h
+ defb 028h
+ defb 0c3h
b_0x22E5_start:
- defw l24aeh ;22e5
+ defw l24aeh
b_0x22E7_start:
- defb 0f8h ;22e7
- defb 038h ;22e8
- defb 0c6h ;22e9
+ defb 0f8h
+ defb 038h
+ defb 0c6h
b_0x22EA_start:
- defw l24aeh ;22ea
+ defw l24aeh
b_0x22EC_start:
- defb 0c0h ;22ec
- defb 040h ;22ed
- defb 009h ;22ee
+ defb 0c0h
+ defb 040h
+ defb 009h
b_0x22EF_start:
- defw l2487h ;22ef
+ defw l2487h
b_0x22F1_start:
- defb 0c0h ;22f1
- defb 080h ;22f2
- defb 088h ;22f3
+ defb 0c0h
+ defb 080h
+ defb 088h
b_0x22F4_start:
- defw l2487h ;22f4
+ defw l2487h
b_0x22F6_start:
- defb 0c0h ;22f6
- defb 0c0h ;22f7
- defb 0bdh ;22f8
+ defb 0c0h
+ defb 0c0h
+ defb 0bdh
b_0x22F9_start:
- defw l2487h ;22f9
+ defw l2487h
b_0x22FB_start:
- defb 000h ;22fb
+ defb 000h
l22fch:
- call l24dfh ;22fc
- call sub_257ch ;22ff
- jp l24ebh ;2302
+ call l24dfh
+ call sub_257ch
+ jp l24ebh
l2305h:
- call sub_2579h ;2305
- jp l24ebh ;2308
+ call sub_2579h
+ jp l24ebh
l230bh:
- ret ;230b
+ ret
l230ch:
- call l24dfh ;230c
- call sub_257ch ;230f
- jp l23c6h ;2312
+ call l24dfh
+ call sub_257ch
+ jp l23c6h
l2315h:
- call l23c6h ;2315
- call sub_257ch ;2318
- jp l24dfh ;231b
+ call l23c6h
+ call sub_257ch
+ jp l24dfh
l231eh:
- comst ;231e
- ld a,(iy+000h) ;2322
+ comst
+ ld a,(iy+000h)
comend
- and 038h ;2325
- jp out.hex ;2327
+ and 038h
+ jp out.hex
l232ah:
- ld hl,b_0x2333_start ;232a
- call PSTR ;232d
- jp l253eh ;2330
+ ld hl,b_0x2333_start
+ call PSTR
+ jp l253eh
b_0x2333_start:
DC '(SP),'
l2338h:
- ld a,'(' ;2338
- call OUTCHAR ;233a
- call l253eh ;233d
- ld a,')' ;2340
- jp OUTCHAR ;2342
+ ld a,'('
+ call OUTCHAR
+ call l253eh
+ ld a,')'
+ jp OUTCHAR
l2345h:
- ld hl,l1d86h ;2345
- jp PSTR ;2348
+ ld hl,l1d86h
+ jp PSTR
l234bh:
- ld hl,b_0x2354_start ;234b
- call PSTR ;234e
- jp l253eh ;2351
+ ld hl,b_0x2354_start
+ call PSTR
+ jp l253eh
b_0x2354_start:
DC 'SP,'
l2357h:
- ld hl,b_0x1D80_start ;2357
- jp PSTR ;235a
+ ld hl,b_0x1D80_start
+ jp PSTR
l235dh:
- call l253eh ;235d
- call sub_257ch ;2360
- jp l254bh ;2363
+ call l253eh
+ call sub_257ch
+ jp l254bh
l2366h:
- call sub_2372h ;2366
- call sub_257ch ;2369
- jp l23dbh ;236c
+ call sub_2372h
+ call sub_257ch
+ jp l23dbh
l236fh:
- call sub_2579h ;236f
+ call sub_2579h
sub_2372h:
- ld a,'(' ;2372
- call OUTCHAR ;2374
- call l254bh ;2377
- ld a,')' ;237a
- jp OUTCHAR ;237c
+ ld a,'('
+ call OUTCHAR
+ call l254bh
+ ld a,')'
+ jp OUTCHAR
l237fh:
- call sub_2579h ;237f
- jr l2397h ;2382
+ call sub_2579h
+ jr l2397h
l2384h:
- call l24dfh ;2384
- call sub_257ch ;2387
- ld a,(is.pfx.IXY) ;238a
- and a ;238d
- comst ;238e
- ld a,(iy+002h) ;2392
+ call l24dfh
+ call sub_257ch
+ ld a,(is.pfx.IXY)
+ and a
+ comst
+ ld a,(iy+002h)
comend
- jr nz,l239eh ;2395
+ jr nz,l239eh
l2397h:
- comst ;2397
- ld a,(iy+001h) ;239b
+ comst
+ ld a,(iy+001h)
comend
l239eh:
- jp out.hex ;239e
+ jp out.hex
l23a1h:
- comst ;23a1
- ld a,(iy+000h) ;23a5
+ comst
+ ld a,(iy+000h)
comend
- and 018h ;23a8
- call sub_2568h ;23aa
- call sub_257ch ;23ad
+ and 018h
+ call sub_2568h
+ call sub_257ch
l23b0h:
- comst ;23b0
- ld c,(iy+001h) ;23b4
+ comst
+ ld c,(iy+001h)
comend
- ld a,c ;23b7
- rla ;23b8
- sbc a,a ;23b9
- ld b,a ;23ba
- push iy ;23bb
- pop hl ;23bd
- add hl,bc ;23be
- inc hl ;23bf
- inc hl ;23c0
- jr l23f0h ;23c1
+ ld a,c
+ rla
+ sbc a,a
+ ld b,a
+ push iy
+ pop hl
+ add hl,bc
+ inc hl
+ inc hl
+ jr l23f0h
l23c3h:
- call sub_2579h ;23c3
+ call sub_2579h
l23c6h:
- ld a,028h ;23c6
- call OUTCHAR ;23c8
- comst ;23cb
- ld a,(iy+001h) ;23cf
+ ld a,028h
+ call OUTCHAR
+ comst
+ ld a,(iy+001h)
comend
- jp l252bh ;23d2
+ jp l252bh
l23d5h:
- call l23c6h ;23d5
- call sub_257ch ;23d8
+ call l23c6h
+ call sub_257ch
l23dbh:
- ld a,041h ;23db
- jp OUTCHAR ;23dd
+ ld a,041h
+ jp OUTCHAR
l23e0h:
- call l2561h ;23e0
- call sub_257ch ;23e3
+ call l2561h
+ call sub_257ch
l23e6h:
- comst ;23e6
- ld l,(iy+001h) ;23ea
- ld h,(iy+002h) ;23ed
+ comst
+ ld l,(iy+001h)
+ ld h,(iy+002h)
comend
l23f0h:
- ld a,002h ;23f0
+ ld a,002h
sub_23f2h:
- ld (XBE03),a ;23f2
- ld (XBE01),hl ;23f5
- call out.hl ;23f8
- ret ;23fb
+ ld (XBE03),a
+ ld (XBE01),hl
+ call out.hl
+ ret
l23fch:
- call l254bh ;23fc
- call sub_257ch ;23ff
- jr l23e6h ;2402
+ call l254bh
+ call sub_257ch
+ jr l23e6h
l2404h:
- call sub_24c6h ;2404
- call sub_257ch ;2407
- jp l253eh ;240a
+ call sub_24c6h
+ call sub_257ch
+ jp l253eh
l240dh:
- call l253eh ;240d
- call sub_257ch ;2410
- jp sub_24c6h ;2413
+ call l253eh
+ call sub_257ch
+ jp sub_24c6h
l2416h:
- call sub_24c6h ;2416
- call sub_257ch ;2419
- ld a,041h ;241c
- jp OUTCHAR ;241e
+ call sub_24c6h
+ call sub_257ch
+ ld a,041h
+ jp OUTCHAR
l2421h:
- call sub_2579h ;2421
- jp sub_24c6h ;2424
+ call sub_2579h
+ jp sub_24c6h
l2427h:
- ld a,030h ;2427
- jr l2431h ;2429
+ ld a,030h
+ jr l2431h
l242bh:
- ld a,031h ;242b
- jr l2431h ;242d
+ ld a,031h
+ jr l2431h
l242fh:
- ld a,032h ;242f
+ ld a,032h
l2431h:
- jp OUTCHAR ;2431
+ jp OUTCHAR
l2434h:
- ld hl,b_0x2449_start ;2434
- jr l2446h ;2437
+ ld hl,b_0x2449_start
+ jr l2446h
l2439h:
- ld hl,l244ch ;2439
- jr l2446h ;243c
+ ld hl,l244ch
+ jr l2446h
l243eh:
- ld hl,l244fh ;243e
- jr l2446h ;2441
+ ld hl,l244fh
+ jr l2446h
l2443h:
- ld hl,l2452h ;2443
+ ld hl,l2452h
l2446h:
- jp PSTR ;2446
+ jp PSTR
b_0x2449_start:
DC 'I,A'
@@ -5402,124 +5427,124 @@ l2452h:
DC 'A,R'
l2455h:
- call l24dfh ;2455
- call sub_257ch ;2458
- ld hl,t__C_ ;245b
- jp PSTR ;245e
+ call l24dfh
+ call sub_257ch
+ ld hl,t__C_
+ jp PSTR
l2461h:
- ld hl,t__C_ ;2461
- call PSTR ;2464
- call sub_257ch ;2467
- jp l24dfh ;246a
+ ld hl,t__C_
+ call PSTR
+ call sub_257ch
+ jp l24dfh
l246dh:
- call l253eh ;246d
- call sub_257ch ;2470
- jp l254bh ;2473
+ call l253eh
+ call sub_257ch
+ jp l254bh
l2476h:
- call sub_24c6h ;2476
- call sub_257ch ;2479
- jp l254bh ;247c
+ call sub_24c6h
+ call sub_257ch
+ jp l254bh
l247fh:
- call l254bh ;247f
- call sub_257ch ;2482
- jr sub_24c6h ;2485
+ call l254bh
+ call sub_257ch
+ jr sub_24c6h
l2487h:
- ld a,(is.pfx.IXY) ;2487
- and a ;248a
- jr nz,l2496h ;248b
- comst ;248d
- ld a,(iy+001h) ;2491
+ ld a,(is.pfx.IXY)
+ and a
+ jr nz,l2496h
+ comst
+ ld a,(iy+001h)
comend
- jr l249dh ;2494
+ jr l249dh
l2496h:
- comst ;2496
- ld a,(iy+002h) ;249a
+ comst
+ ld a,(iy+002h)
comend
l249dh:
- push af ;249d
- rra ;249e
- rra ;249f
- rra ;24a0
- and 007h ;24a1
- add a,'0' ;24a3
- call OUTCHAR ;24a5
- call sub_257ch ;24a8
- pop af ;24ab
- jr l24f2h ;24ac
+ push af
+ rra
+ rra
+ rra
+ and 007h
+ add a,'0'
+ call OUTCHAR
+ call sub_257ch
+ pop af
+ jr l24f2h
l24aeh:
- ld a,(is.pfx.IXY) ;24ae
- and a ;24b1
- jr nz,l24bdh ;24b2
- comst ;24b4
- ld a,(iy+001h) ;24b8
+ ld a,(is.pfx.IXY)
+ and a
+ jr nz,l24bdh
+ comst
+ ld a,(iy+001h)
comend
- jr l24c4h ;24bb
+ jr l24c4h
l24bdh:
- comst ;24bd
- ld a,(iy+002h) ;24c1
+ comst
+ ld a,(iy+002h)
comend
l24c4h:
- jr l24f2h ;24c4
+ jr l24f2h
sub_24c6h:
- ld a,'(' ;24c6
- call OUTCHAR ;24c8
- comst ;24cb
- ld l,(iy+001h) ;24cf
- ld h,(iy+002h) ;24d2
+ ld a,'('
+ call OUTCHAR
+ comst
+ ld l,(iy+001h)
+ ld h,(iy+002h)
comend
- ld a,001h ;24d5
- call sub_23f2h ;24d7
- ld a,')' ;24da
- jp OUTCHAR ;24dc
+ ld a,001h
+ call sub_23f2h
+ ld a,')'
+ jp OUTCHAR
l24dfh:
- comst ;24df
- ld a,(iy+000h) ;24e3
+ comst
+ ld a,(iy+000h)
comend
- rra ;24e6
- rra ;24e7
- rra ;24e8
- jr l24f2h ;24e9
+ rra
+ rra
+ rra
+ jr l24f2h
l24ebh:
- comst ;24eb
- ld a,(iy+000h) ;24ef
+ comst
+ ld a,(iy+000h)
comend
l24f2h:
- and 007h ;24f2
- cp 006h ;24f4
- jr nz,l2533h ;24f6
- ld a,(is.pfx.IXY) ;24f8
- and a ;24fb
- ld a,006h ;24fc
- jr z,l2533h ;24fe
- ld hl,b_0x2538_start ;2500
- ld a,(is.pfx.IXY) ;2503
- dec a ;2506
- jr z,l250ch ;2507
- ld hl,b_0x253B_start ;2509
+ and 007h
+ cp 006h
+ jr nz,l2533h
+ ld a,(is.pfx.IXY)
+ and a
+ ld a,006h
+ jr z,l2533h
+ ld hl,b_0x2538_start
+ ld a,(is.pfx.IXY)
+ dec a
+ jr z,l250ch
+ ld hl,b_0x253B_start
l250ch:
- call PSTR ;250c
- comst ;250f
- ld a,(iy+001h) ;2513
+ call PSTR
+ comst
+ ld a,(iy+001h)
comend
- and a ;2516
- push af ;2517
- jp m,l2523h ;2518
- ld a,'+' ;251b
- call OUTCHAR ;251d
- pop af ;2520
- jr l252bh ;2521
+ and a
+ push af
+ jp m,l2523h
+ ld a,'+'
+ call OUTCHAR
+ pop af
+ jr l252bh
l2523h:
- ld a,'-' ;2523
- call OUTCHAR ;2525
- pop af ;2528
- neg ;2529
+ ld a,'-'
+ call OUTCHAR
+ pop af
+ neg
l252bh:
- call out.hex ;252b
- ld a,')' ;252e
- jp OUTCHAR ;2530
+ call out.hex
+ ld a,')'
+ jp OUTCHAR
l2533h:
- ld hl,t_BCDEHL_HL_A ;2533
- jr l2572h ;2536
+ ld hl,t_BCDEHL_HL_A
+ jr l2572h
b_0x2538_start:
DC '(IX'
@@ -5527,55 +5552,55 @@ b_0x253B_start:
DC '(IY'
l253eh:
- ld a,(is.pfx.IXY) ;253e
- ld hl,t_HL.IX.IY ;2541
- jr l2572h ;2544
+ ld a,(is.pfx.IXY)
+ ld hl,t_HL.IX.IY
+ jr l2572h
l2546h:
- ld hl,t_BC.DE.HL.AF ;2546
- jr l254eh ;2549
+ ld hl,t_BC.DE.HL.AF
+ jr l254eh
l254bh:
- ld hl,t_BC.DE.HL.SP ;254b
+ ld hl,t_BC.DE.HL.SP
l254eh:
- comst ;254e
- ld a,(iy+000h) ;2552
+ comst
+ ld a,(iy+000h)
comend
- rra ;2555
- rra ;2556
- rra ;2557
- rra ;2558
- and 003h ;2559
- cp 002h ;255b
- jr z,l253eh ;255d
- jr l2572h ;255f
+ rra
+ rra
+ rra
+ rra
+ and 003h
+ cp 002h
+ jr z,l253eh
+ jr l2572h
l2561h:
- comst ;2561
- ld a,(iy+000h) ;2565
+ comst
+ ld a,(iy+000h)
comend
sub_2568h:
- rra ;2568
- rra ;2569
- rra ;256a
- and 007h ;256b
- ld hl,t_tstfl_ZCPS ;256d
- jr l2572h ;2570
+ rra
+ rra
+ rra
+ and 007h
+ ld hl,t_tstfl_ZCPS
+ jr l2572h
l2572h:
- ld b,a ;2572
- call sub_0a48h ;2573
- jp PSTR ;2576
+ ld b,a
+ call sub_0a48h
+ jp PSTR
sub_2579h:
- call l23dbh ;2579
+ call l23dbh
sub_257ch:
- ld a,',' ;257c
- jp OUTCHAR ;257e
+ ld a,','
+ jp OUTCHAR
sub_2581h:
- call PSTR ;2581
+ call PSTR
l2584h:
- call OUTBL ;2584
- inc c ;2587
- ld a,c ;2588
- cp 006h ;2589
- jr nz,l2584h ;258b
- ret ;258d
+ call OUTBL
+ inc c
+ ld a,c
+ cp 006h
+ jr nz,l2584h
+ ret
t_MNEMONICS:
DC 'ADC'
@@ -5656,7 +5681,7 @@ t_MNEMONICS:
DC 'TST'
DC 'TSTIO'
DB 0
-
+
t_BCDEHL_HL_A:
DC 'B'
DC 'C'
@@ -5729,572 +5754,500 @@ t__C_:
DB 0
sub_26e7h:
- ld hl,(REG.PC) ;26e7
- ld a,h ;26ea
- or l ;26eb
- jr z,l2715h ;26ec
- ld iy,(REG.PC) ;26ee
- call sub_1f9eh ;26f2
- jp nc,ERROR ;26f5
- ld c,b ;26f8
- ld b,000h ;26f9
- ld hl,(REG.PC) ;26fb
- add hl,bc ;26fe
- call sub_1117h ;26ff
- ld iy,(REG.PC) ;2702
- ld hl,b_0x2717_start ;2706
- call lookup_opc ;2709
- ccf ;270c
- ret c ;270d
- ex de,hl ;270e
- call CALL.HL ;270f
- call c,sub_1117h ;2712
+ ld hl,(REG.PC)
+ ld a,h
+ or l
+ jr z,l2715h
+ ld iy,(REG.PC)
+ call sub_1f9eh
+ jp nc,ERROR
+ ld c,b
+ ld b,000h
+ ld hl,(REG.PC)
+ add hl,bc
+ call sub_1117h
+ ld iy,(REG.PC)
+ ld hl,b_0x2717_start
+ call lookup_opc
+ ccf
+ ret c
+ ex de,hl
+ call CALL.HL
+ call c,sub_1117h
l2715h:
- scf ;2715
- ret ;2716
+ scf
+ ret
b_0x2717_start:
- db 0ffh ;2717
- db 0ddh ;2718
- db 000h ;2719
+ db 0ffh
+ db 0ddh
+ db 000h
dw x278d
- db 0ffh ;271c
- db 0fdh ;271d
- db 000h ;271e
+ db 0ffh
+ db 0fdh
+ db 000h
dw x2792
- db 0ffh ;2721
- db 0edh ;2722
- db 000h ;2723
+ db 0ffh
+ db 0edh
+ db 000h
dw x27a2
l2726h:
- db 0ffh ;2726
- db 0cdh ;2727
- db 000h ;2728
+ db 0ffh
+ db 0cdh
+ db 000h
dw x275e
- db 0ffh ;272b
- db 0c3h ;272c
- db 000h ;272d
+ db 0ffh
+ db 0c3h
+ db 000h
dw x2769
- db 0ffh ;2730
- db 0e9h ;2731
- db 000h ;2732
+ db 0ffh
+ db 0e9h
+ db 000h
dw x2788
- db 0ffh ;2735
- db 0c9h ;2736
- db 000h ;2737
+ db 0ffh
+ db 0c9h
+ db 000h
dw x27c9
- db 0ffh ;273a
- db 0cfh ;273b
- db 000h ;273c
+ db 0ffh
+ db 0cfh
+ db 000h
dw x280e
- db 0c7h ;273f
- db 0c7h ;2740
- db 000h ;2741
+ db 0c7h
+ db 0c7h
+ db 000h
dw x27ea
- db 0c7h ;2744
- db 0c4h ;2745
- db 000h ;2746
+ db 0c7h
+ db 0c4h
+ db 000h
dw x275e
- db 0f7h ;2749
- db 010h ;274a
- db 000h ;274b
+ db 0f7h
+ db 010h
+ db 000h
dw x2775
- db 0e7h ;274e
- db 020h ;274f
- db 000h ;2750
+ db 0e7h
+ db 020h
+ db 000h
dw x2775
- db 0c7h ;2753
- db 0c2h ;2754
- db 000h ;2755
+ db 0c7h
+ db 0c2h
+ db 000h
dw x2769
- db 0c7h ;2758
- db 0c0h ;2759
- db 000h ;275a
+ db 0c7h
+ db 0c0h
+ db 000h
dw x27b3
- db 000h ;275d
+ db 000h
x275e:
- ld a,(XBFE8) ;275e
- and a ;2761
- jr nz,x2769 ;2762
- ld a,(TCFLG) ;2764
- and a ;2767
- ret nz ;2768
+ ld a,(XBFE8)
+ and a
+ jr nz,x2769
+ ld a,(TCFLG)
+ and a
+ ret nz
x2769:
- comst ;2769
- ld l,(iy+001h) ;276d
- ld h,(iy+002h) ;2770
+ comst
+ ld l,(iy+001h)
+ ld h,(iy+002h)
comend
- scf ;2773
- ret ;2774
+ scf
+ ret
x2775:
- comst ;2775
- ld c,(iy+001h) ;2779
+ comst
+ ld c,(iy+001h)
comend
- ld a,c ;277c
- rla ;277d
- sbc a,a ;277e
- ld b,a ;277f
- ld hl,(REG.PC) ;2780
- add hl,bc ;2783
- inc hl ;2784
- inc hl ;2785
- scf ;2786
- ret ;2787
+ ld a,c
+ rla
+ sbc a,a
+ ld b,a
+ ld hl,(REG.PC)
+ add hl,bc
+ inc hl
+ inc hl
+ scf
+ ret
x2788:
- ld hl,(REG.L) ;2788
- scf ;278b
- ret ;278c
+ ld hl,(REG.L)
+ scf
+ ret
x278d:
- ld hl,(reg.ix) ;278d
- jr l2795h ;2790
+ ld hl,(reg.ix)
+ jr l2795h
x2792:
- ld hl,(reg.iy) ;2792
+ ld hl,(reg.iy)
l2795h:
- comst ;2795
- ld a,(iy+001h) ;2799
+ comst
+ ld a,(iy+001h)
comend
- cp 0e9h ;279c
- scf ;279e
- ret z ;279f
- and a ;27a0
- ret ;27a1
+ cp 0e9h
+ scf
+ ret z
+ and a
+ ret
x27a2:
- comst ;27a2
- ld a,(iy+001h) ;27a6
+ comst
+ ld a,(iy+001h)
comend
- cp 04dh ;27a9
- jr z,x27c9 ;27ab
- cp 045h ;27ad
- jr z,x27c9 ;27af
- and a ;27b1
- ret ;27b2
+ cp 04dh
+ jr z,x27c9
+ cp 045h
+ jr z,x27c9
+ and a
+ ret
x27b3:
- comst ;27b3
- ld a,(iy+000h) ;27b7
+ comst
+ ld a,(iy+000h)
comend
- ld (XBEDD),a ;27ba
- ld hl,(REG.F) ;27bd
- push hl ;27c0
- pop af ;27c1
- call XBEDD ;27c2
- scf ;27c5
- jr c,x27c9 ;27c6
- ret ;27c8
+ ld (XBEDD),a
+ ld hl,(REG.F)
+ push hl
+ pop af
+ call XBEDD
+ scf
+ jr c,x27c9
+ ret
x27c9:
- ld a,(XBFE8) ;27c9
- and a ;27cc
- jr nz,l27dah ;27cd
- ld a,(TCFLG) ;27cf
- and a ;27d2
- jr z,l27dah ;27d3
- call l27dah ;27d5
- pop hl ;27d8
- ret ;27d9
+ ld a,(XBFE8)
+ and a
+ jr nz,l27dah
+ ld a,(TCFLG)
+ and a
+ jr z,l27dah
+ call l27dah
+ pop hl
+ ret
l27dah:
- ld hl,(REG.SP) ;27da
- comst ;27dd
- ld e,(hl) ;27e1
- inc hl ;27e2
- ld d,(hl) ;27e3
+ ld hl,(REG.SP)
+ comst
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
comend
- ex de,hl ;27e4
- call sub_1117h ;27e5
- and a ;27e8
- ret ;27e9
+ ex de,hl
+ call sub_1117h
+ and a
+ ret
x27ea:
- ld a,(ddtrst) ;27ea
- comst ;27ed
- cp (iy+000h) ;27f1
+ ld a,(ddtzrst)
+ comst
+ cp (iy+000h)
comend
- ret z ;27f4
- comst ;27f5
- ld a,(iy+000h) ;27f9
+ ret z
+ comst
+ ld a,(iy+000h)
comend
- and 038h ;27fc
- ld l,a ;27fe
- ld h,000h ;27ff
- ld a,(XBFE8) ;2801
- and a ;2804
- jr nz,l280ch ;2805
- ld a,(TCFLG) ;2807
- and a ;280a
- ret nz ;280b
+ and 038h
+ ld l,a
+ ld h,000h
+ ld a,(XBFE8)
+ and a
+ jr nz,l280ch
+ ld a,(TCFLG)
+ and a
+ ret nz
l280ch:
- scf ;280c
- ret ;280d
+ scf
+ ret
x280e:
- and a ;280e
- ret ;280f
+ and a
+ ret
CMD.C:
- ld hl,CMD.C ;2810
- ld a,001h ;2813
- jr l281bh ;2815
+ ld hl,CMD.C
+ ld a,001h
+ jr l281bh
CMD.T:
- xor a ;2817
- ld hl,CMD.T ;2818
+ xor a
+ ld hl,CMD.T
l281bh:
- ld (CMD_RPT),hl ;281b
- ld (TCFLG),a ;281e
- ld a,(de) ;2821
- sub 'N' ;2822
- jr nz,l2827h ;2824
- inc de ;2826
+ ld (CMD_RPT),hl
+ ld (TCFLG),a
+ ld a,(de)
+ sub 'N'
+ jr nz,l2827h
+ inc de
l2827h:
- ld (TCNFLG),a ;2827
- ld a,(de) ;282a
- sub 'J' ;282b
- jr nz,l2830h ;282d
- inc de ;282f
+ ld (TCNFLG),a
+ ld a,(de)
+ sub 'J'
+ jr nz,l2830h
+ inc de
l2830h:
- ld (TRJFLG),a ;2830
- call sub_289fh ;2833
- jr z,l283eh ;2836
- ld hl,1 ;2838
- call get_lastarg_def ;283b
+ ld (TRJFLG),a
+ call sub_289fh
+ jr z,l283eh
+ ld hl,1
+ call get_lastarg_def
l283eh:
- ld (TCCSTR),hl ;283e
- sub a ;2841
- ld (XA747),a ;2842
+ ld (TCCSTR),hl
+ sub a
+ ld (XA747),a
l2845h:
- call sub_26e7h ;2845
- jr l289ch ;2848
+ call sub_26e7h
+ jr l289ch
l284ah:
- call sub_0e68h ;284a
- ld a,(TRJFLG) ;284d
- and a ;2850
- jr nz,l2864h ;2851
- ld iy,(REG.PC) ;2853
- call sub_28c1h ;2857
- jr z,l2864h ;285a
- ld hl,l2726h ;285c
- call lookup_opc ;285f
- jr nc,l2845h ;2862
+ call sub_0e68h
+ ld a,(TRJFLG)
+ and a
+ jr nz,l2864h
+ ld iy,(REG.PC)
+ call sub_28c1h
+ jr z,l2864h
+ ld hl,l2726h
+ call lookup_opc
+ jr nc,l2845h
l2864h:
- ld a,(XBFEA) ;2864
- and a ;2867
- jr z,l2881h ;2868
- ld de,(TCCSTR) ;286a
- call EXPR ;286e
- ld a,h ;2871
- or l ;2872
- add a,0ffh ;2873
- sbc a,a ;2875
- ld hl,XBFEA ;2876
- xor (hl) ;2879
- bit 1,a ;287a
- jr z,l288ch ;287c
+ ld a,(XBFEA)
+ and a
+ jr z,l2881h
+ ld de,(TCCSTR)
+ call EXPR
+ ld a,h
+ or l
+ add a,0ffh
+ sbc a,a
+ ld hl,XBFEA
+ xor (hl)
+ bit 1,a
+ jr z,l288ch
l287eh:
- jp l102eh ;287e
+ jp l102eh
l2881h:
- ld hl,(TCCSTR) ;2881
- dec hl ;2884
- ld (TCCSTR),hl ;2885
- ld a,h ;2888
- or l ;2889
- jr z,l287eh ;288a
+ ld hl,(TCCSTR)
+ dec hl
+ ld (TCCSTR),hl
+ ld a,h
+ or l
+ jr z,l287eh
l288ch:
- call sub_26e7h ;288c
- jr nc,l287eh ;288f
- ld a,(TCNFLG) ;2891
- ld b,a ;2894
- ld a,(XA747) ;2895
- or b ;2898
- ld (XA747),a ;2899
+ call sub_26e7h
+ jr nc,l287eh
+ ld a,(TCNFLG)
+ ld b,a
+ ld a,(XA747)
+ or b
+ ld (XA747),a
l289ch:
- jp l1183h ;289c
+ jp l1183h
sub_289fh:
- call SKIPBL ;289f
- xor a ;28a2
- ld (XBFEA),a ;28a3
- ld a,(de) ;28a6
- cp 'U' ;28a7
- jr z,l28aeh ;28a9
- cp 'W' ;28ab
- ret nz ;28ad
+ call SKIPBL
+ xor a
+ ld (XBFEA),a
+ ld a,(de)
+ cp 'U'
+ jr z,l28aeh
+ cp 'W'
+ ret nz
l28aeh:
- inc de ;28ae
- push af ;28af
- push de ;28b0
- call EXPR ;28b1
- jp c,ERROR ;28b4
- call assert_eol ;28b7
- pop hl ;28ba
- pop af ;28bb
- ld (XBFEA),a ;28bc
- sub a ;28bf
- ret ;28c0
+ inc de
+ push af
+ push de
+ call EXPR
+ jp c,ERROR
+ call assert_eol
+ pop hl
+ pop af
+ ld (XBFEA),a
+ sub a
+ ret
sub_28c1h:
- comst
- ld a,(iy+000h)
+ comst
+ ld a,(iy+000h)
ld b,(iy+0001)
comend
- cp 0edh
- jr z,l28dbh
- and 0dfh
- cp 0ddh
- ret nz
+ cp 0edh
+ jr z,l28dbh
+ and 0dfh
+ cp 0ddh
+ ret nz
ld a,b
- cp 0e9h
- ret
+ cp 0e9h
+ ret
l28dbh:
ld a,b
- and 0f7h
- cp 045h
- ret
+ and 0f7h
+ cp 045h
+ ret
?excom:
- ex (sp),hl ;28e7
- push af ;28e8
- push bc ;28e9
- push de ;28ea
- ld c,(hl) ;28eb
- ld b,000h ;28ec
- inc hl ;28ee
+ ex (sp),hl
+ push af
+ push bc
+ push de
+ ld c,(hl)
+ ld b,000h
+ inc hl
ld a,?lcmax
sub c
- ld de,?exeit ;28ef
+ ld de,?exeit
ldir
ex de,hl
ld (hl),018h
inc hl
ld (hl),a
ex de,hl
- pop de ;28f7
- pop bc ;28f8
- pop af ;28f9
- ex (sp),hl ;28fa
-?exclst:
- push hl ;28fb
- ld hl,(ubbr) ;2900
+ pop de
+ pop bc
+ pop af
+ ex (sp),hl
+ if CPU_Z180
+ push hl
+ ld hl,(ubbr)
+ else
+ push af
+ ld a,(ubnk)
+ endif
if ROMSYS
- push af ;28fc
- ld a,(uromen) ;28fd
+ push af
+ ld a,(uromen)
endif
- jp ?comcod ;2903
-
+ jp ?comcod
+
;------------------------------------------
; ddtram
;------------------------------------------
vartab:
- dseg
-ddtram:
+; dseg
+ cseg
+ddtram:
;todo:
; The following 2 params are changeable by user.
; Should these moved to top ram?
;
-ddtrst: inidat ;
- rst DRSTNUM ;rst used by ddtz
- inidate ;
-ddtei: inidat ;
- ei ;ints enabled/disabled while ddtz is running
+ddtzrst:
+ rst DDTZRSTVEC ;rst used by ddtz
+ddtei: ei ;ints enabled/disabled while ddtz is running
ret ;
- inidate ;
offs.pc:
- inidat
- dw TPA
- inidate
+ dw TPA
offs.@:
- inidat
- dw 0
- inidate
+ dw 0
CMD_ERR:
- inidat
- dw 0
- inidate
+ dw 0
CMD_RPT:
- inidat
- dw DDTZML
- inidate
+ dw DDTZML
ci.buf:
- inidat
- db 80
+ db 80
rept 83
db 0
endm
- inidate
CON.COL:
- inidat
- db 0
- inidate
+ db 0
XA747:
- inidat
- db 0
- inidate
+ db 0
bp_tab:
- inidat
- rept BP_CNT
+ rept BP_CNT
db 0,0
dw 0,0,0
endm
BP_SIZE equ 8
- inidate
sexp1:
- inidat
- dw sexpbuf
- inidate
+ dw sexpbuf
sexp2:
- inidat
- dw sexpbuf
- inidate
+ dw sexpbuf
sexpbuf:
- inidat
- rept 128
+ rept 128
db 0
endm
- inidate
sexpbufe:
msg.Y:
- inidat
- dc 'Y0'
- inidate
+ dc 'Y0'
reg.Y:
- inidat
- rept 10
+ rept 10
dw 0
endm
- inidate
lst.S:
- inidat
- dw 0
- inidate
+ dw 0
lst.IP:
- inidat
- dw 0
- inidate
+ dw 0
lst.OP:
- inidat
- dw 0
- inidate
+ dw 0
lst.OD:
- inidat
db 0
- inidate
lst.Qj:
- inidat
db 0
- inidate
lst.D:
- inidat
- dw 0
- inidate
+ dw 0
HILOD:
- inidat
- dw 0
- inidate
+ dw 0
MAXLOD:
- inidat
- dw 0
- inidate
+ dw 0
XB068:
- inidat
- dw 0
- inidate
+ dw 0
lst.A:
- inidat
- dw 0
- inidate
+ dw 0
XB06C:
- inidat
- dw 0
- inidate
+ dw 0
pfx.IXY:
- inidat
- db 000h
- inidate
+ db 000h
is.pfx.IXY:
- inidat
- db 000h
- inidate
+ db 000h
lst.L:
- inidat
- dw 0
- inidate
+ dw 0
XBE01:
- inidat
- dw 0
- inidate
+ dw 0
XBE03:
- inidat
- db 000h
- inidate
+ db 000h
XBEDD:
- inidat
ret ;ret cc
- and a
- pop hl
- inc hl
- jp (hl)
- inidate
+ and a
+ pop hl
+ inc hl
+ jp (hl)
XBFE8:
- inidat
- db 0
- inidate
+ db 0
TCFLG:
- inidat
- db 0
- inidate
+ db 0
XBFEA:
- inidat
- db 0
- inidate
+ db 0
TCCSTR:
- inidat
- dw 0
- inidate
+ dw 0
TCNFLG:
- inidat
- db 0
- inidate
+ db 0
TRJFLG:
- inidat
- db 0
- inidate
+ db 0
wstrtflg:
- inidat
db 1
- inidate
cseg
vartabe:
;------------------------------------------
- .phase sysram_start+stacksize
+ .phase sysram_start+bs$stack$size
$stack:
-$stcka equ $ - stacksize
+$stcka equ $ - bs$stack$size
curphse defl $
.dephase
@@ -6322,8 +6275,13 @@ reg.b: db 0 ; 0fe61h
udcntl: db CWAITIO ; 0fe62h (mem-, io- wait)
uromen: db ROM_DIS ; 0fe63h
endif
+ if CPU_Z180
ubbr: db 0 ; 0fe64h
ucbar: db USR$CBAR ; 0fe65h
+ else
+ db 0 ; 0fe64h
+ubnk: db 0 ; 0fe65h
+ endif
reg.f: db 0 ; 0fe66h
reg.a: db 0 ; 0fe67h
reg.l: db 0 ; 0fe68h
@@ -6333,68 +6291,93 @@ reg.sp: dw TOPRAM ; 0fe6ah
$go:
if ROMSYS
out (000h),a ;064c fe6c
- out0 (dcntl),l ;064e
- pop hl ;0651
+ out0 (dcntl),l
+ pop hl
endif
- out0 (cbar),h ;0652
- out0 (bbr),l ;0655
- pop af ;0658
- pop hl ;0659
- ld sp,(reg.sp) ;065a
+ if CPU_Z180
+ out0 (cbar),h
+ out0 (bbr),l
+ else
+ ld a,h
+ call selbnk
+ endif
+ pop af
+ pop hl
+ ld sp,(reg.sp)
reg.iff:
- ei ;065e
+ ei
db 0C3h ;jp TPA ;065f feff ($+1): reg.pc
reg.pc:
dw TPA
-
+
bpent:
ld (reg.l),hl ;0662 fe82: bpent:
- pop hl ;0665
- dec hl ;0666
- ld (reg.pc),hl ;0667
- ld (reg.sp),sp ;066a
- ld sp,reg.l ;066e
- push af ;0671
- in0 h,(cbar) ;0672
- in0 l,(bbr) ;0675
- push hl ;0678
- ld a,SYS$CBAR ;0679
- out0 (cbar),a ;067b
+ pop hl
+ dec hl
+ ld (reg.pc),hl
+ ld (reg.sp),sp
+ ld sp,reg.l
+ push af
+ if CPU_Z180
+;;; TODO: cbar on trap?
+ in0 h,(cbar)
+ in0 l,(bbr)
+ ld a,SYS$CBAR
+ out0 (cbar),a
+ else
+ ld a,(@cbnk)
+ ld h,a
+ xor a
+ ld l,a
+ call selbnk
+ endif
+ push hl
if ROMSYS
- in0 l,(dcntl) ;067e
- ld a,CWAITROM+CWAITIO ;0681
- out0 (dcntl),a ;0683
- ld a,($crom) ;0686
- cp c$rom ;0689
- ld a,ROM_EN ;068b
- out (000h),a ;068d
+ in0 l,(dcntl)
+ ld a,CWAITROM+CWAITIO
+ out0 (dcntl),a
+ ld a,($crom)
+ cp c$rom
+ ld a,ROM_EN
+ out (000h),a
endif
- jp bpddtz ;068f
+ jp bpddtz
?comcod:
if ROMSYS
out (000h),a ;0692 feb2
- pop af ;069a
+ pop af
endif
- out0 (cbar),h ;0694
- out0 (bbr),l ;0697
- pop hl ;069b
+ if CPU_Z180
+ out0 (cbar),h
+ out0 (bbr),l
+ pop hl
+ else
+ call selbnk
+ pop af
+ endif
?exeit:
ds ?lcmax+2
- push af ;069f
- ld a,SYS$CBAR ;06a0
- out0 (cbar),a ;06a2
+ push af
+ if CPU_Z180
+ ld a,SYS$CBAR
+ out0 (cbar),a
+;;; TODO: bbr?
+ else
+ xor a
+ call selbnk
+ endif
if ROMSYS
- ld a,ROM_EN ;06a5
- out (000h),a ;06a7
+ ld a,ROM_EN
+ out (000h),a
endif
-
- pop af ;06a9
- ret ;06aa
+
+ pop af
+ ret
topcodend:
curph defl $
@@ -6402,4 +6385,3 @@ curph defl $
sysrame:
end
-
diff --git a/z180/fifoio.180 b/z180/fifoio.180
index dd99c53..cbcece9 100644
--- a/z180/fifoio.180
+++ b/z180/fifoio.180
@@ -1,6 +1,6 @@
page 255
.z80
-
+
;
; FIFO channels for communication with stm32
;
@@ -15,10 +15,10 @@
;--------------------------------------------------------------
dseg
-
- mkbuf rx.buf,rx.buf_len
- mkbuf tx.buf,tx.buf_len
+
+ mkbuf ci.fifo_id, rx.buf,rx.buf_len
+ mkbuf co.fifo_id, tx.buf,tx.buf_len
;--------------------------------------------------------------
@@ -48,7 +48,7 @@ buf.empty:
ret z
or 0ffh
ret
-
+
f.in:
push ix
@@ -69,12 +69,12 @@ bg.wait:
inc h
bg.nc:
ld l,(hl)
-
+
ld a,(ix+o.out_idx) ;
inc a
and (ix+o.mask)
ld (ix+o.out_idx),a
-
+
ld a,l
pop hl
pop ix
@@ -118,7 +118,7 @@ bp.wait:
jr z,bp.wait
ld (hl),b
ld (ix+o.in_idx),a
-
+
ld a,b
pop bc
pop hl
@@ -126,4 +126,3 @@ bp.wait:
ret
end
-
diff --git a/z180/init-80.180 b/z180/init-80.180
new file mode 100644
index 0000000..8b71993
--- /dev/null
+++ b/z180/init-80.180
@@ -0,0 +1,591 @@
+ page 255
+ .z80
+
+ extrn ddtz,bpent
+ extrn $stack
+ extrn charini,?const,?conin
+ extrn ?cono,?conos
+
+ extrn romend
+
+ global iobyte
+ global isv_sw
+
+ include config.inc
+
+
+
+
+;----------------------------------------------------------------------
+
+ cseg
+romstart equ $
+
+ org romstart+0
+ jp start
+
+iobyte: db 0
+
+; restart vectors
+
+rsti defl 1
+ rept 7
+
+ org 8*rsti + romstart
+ jp bpent
+rsti defl rsti+1
+ endm
+
+;----------------------------------------------------------------------
+
+ org romstart+40h
+
+ dw 0
+ db 0
+
+ cseg
+
+ if ROMSYS
+$crom: defb c$rom ;
+ else
+ db 0 ;
+ endif
+
+
+hwini0:
+ db 0 ;count
+; db rcr,CREFSH ;configure DRAM refresh
+; db dcntl,INIWAITS ;wait states
+; db cbar,SYS$CBAR
+
+
+;----------------------------------------------------------------------
+
+ org romstart+50h
+
+start:
+ jp cstart
+ jp wstart
+ jp ?const
+ jp ?conin
+ jp ?cono
+ jp ?conos
+ jp charini
+
+cstart:
+ di
+
+ xor a
+ ld (@cbnk),a
+
+; search warm start mark
+
+ ld ix,mark_55AA ; top of common area
+ ld a,0aah ;
+ cp (ix+000h) ;
+ jr nz,kstart ;
+ cp (ix+002h) ;
+ jr nz,kstart ;
+ cpl ;
+ cp (ix+001h) ;
+ jr nz,kstart ;
+ cp (ix+003h) ;
+ jr nz,kstart ;
+ ld sp,$stack ; mark found, check
+; call checkcrc_alv ;
+ jp z,wstart ; check ok,
+
+;
+; ram not ok, initialize -- kstart --
+
+kstart:
+ ld sp,$stack ;01e1
+
+; Clear RAM
+
+; Init bank manager
+
+;----------------------------------------------------------------------
+;
+
+ ld hl,055AAh ;set warm start mark
+ ld (mark_55AA),hl ;
+ ld (mark_55AA+2),hl;
+
+;
+; -- wstart --
+;
+wstart:
+ call sysram_init ;027f
+ call ivtab_init
+
+ call charini
+ call bufferinit
+
+ ld c,0
+ call selbnk
+
+
+ im 2 ;?030e
+ ei ;0282
+
+ call ?const ;0284
+ call ?const ;0287
+ or a ;028a
+ call nz,?conin ;028d
+
+;;; ld a,(banktab) ;
+;;; ld e,a ;
+ jp ddtz ;0290
+
+
+;----------------------------------------------------------------------
+;
+
+;TODO: Make a ringbuffer module.
+
+ global buf.init
+
+buf.init:
+ ld (ix+o.in_idx),0
+ ld (ix+o.out_idx),0
+ ld (ix+o.mask),a
+ ret
+
+;----------------------------------------------------------------------
+
+
+ extrn msginit,msg.sout
+ extrn mtx.fifo,mrx.fifo
+ extrn co.fifo,ci.fifo
+
+
+bufferinit:
+ call msginit
+
+ ld hl,buffers
+ ld b,buftablen
+bfi_1:
+ ld a,(hl)
+ inc hl
+ ld (bufdat+0),a
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ inc hl
+ ex de,hl
+
+ or a
+ jr nz,bfi_2
+
+ ld a,(@cbnk)
+ call bnk2phys
+
+ ld (40h+0),hl
+ ld (40h+2),a
+ out (AVRINT5),a
+ jr bfi_3
+bfi_2:
+
+ ld a,(@cbnk)
+ call bnk2phys
+
+ ld (bufdat+1),hl
+ ld (bufdat+3),a
+ ld hl,inimsg
+ call msg.sout
+bfi_3:
+ ex de,hl
+ djnz bfi_1
+ ret
+
+
+buffers:
+ db 0
+ dw mtx.fifo
+ db 1
+ dw mrx.fifo
+ db 2
+ dw co.fifo
+ db 3
+ dw ci.fifo
+buftablen equ ($ - buffers)/3
+
+inimsg:
+ db inimsg_e - $ -1
+ db 0AEh
+ db inimsg_e - $ -1
+ db 0
+bufdat:
+ db 0
+ dw 0
+ db 0
+inimsg_e:
+
+
+;
+;----------------------------------------------------------------------
+;
+
+bnk2phys:
+ sla h
+ jr nc,b2p_1 ;A15=1 --> common
+ ld a,3
+b2p_1:
+ srl a
+ rr h
+ ret
+
+;
+;----------------------------------------------------------------------
+;
+
+sysram_init:
+ ld hl,sysramw
+ ld de,topcodsys
+ ld bc,sysrame-sysramw
+ ldir
+
+ ret
+
+;----------------------------------------------------------------------
+
+ivtab_init:
+ ld hl,ivtab ;
+ ld a,h ;
+ ld i,a ;
+; out0 (il),l ;
+
+; Let all vectors point to spurious int routines.
+
+ ld d,high sp.int0
+ ld a,low sp.int0
+ ld b,9
+ivt_i1:
+ ld (hl),a
+ inc l
+ ld (hl),d
+ inc l
+ add a,sp.int.len
+ djnz ivt_i1
+ ret
+
+;----------------------------------------------------------------------
+;
+
+ global io.ini
+
+io.ini:
+ push bc
+
+ if CPU_Z180
+
+ ld b,0 ;high byte port adress
+ ld a,(hl) ;count
+ inc hl
+ or a
+ jr z,ioi_e
+ioi_1:
+ ld c,(hl) ;port address
+ inc hl
+ outi
+ inc b ;outi decrements b
+ dec a
+ jr nz,ioi_1
+
+ else
+ jr ioi_nxt
+ioi_l:
+ ld c,(hl) ;port address
+ inc hl
+ otir
+ioi_nxt:
+ ld b,(hl) ;count
+ inc hl
+ inc b
+ djnz ioi_l
+ endif
+ioi_e:
+ pop bc
+ ret
+
+ if CPU_Z180
+io.ini.m:
+ push bc
+ ld b,(hl)
+ inc hl
+ ld c,(hl)
+ inc hl
+ otimr
+ pop bc
+ ret
+ endif
+
+io.ini.l:
+;
+
+
+;----------------------------------------------------------------------
+;
+;return:
+; hl = hl + a
+; Flags undefined
+;
+
+add_hl_a:
+ add a,l
+ ld l,a
+ ret nc
+ inc h
+ ret
+
+; ---------------------------------------------------------
+
+sysramw:
+
+ .phase isvsw_loc
+topcodsys:
+
+; Trampoline for interrupt routines in banked ram.
+; Switch stack pointer to "system" stack in top ram
+
+; todo: z80 bank switch
+
+isv_sw: ;
+ ex (sp),hl ; save hl, return adr in hl
+ push de ;
+ push af ;
+ ex de,hl ;
+ ld hl,0 ;
+ add hl,sp ;
+ ld a,h ;
+ cp 0f8h ;
+ jr nc,isw_1 ;
+ ld sp,$stack ;
+isw_1:
+ push hl ;
+ ; save current bank
+; in0 h,(cbar) ;
+ push hl ;
+ ; switch to system bank
+; ld a,SYS$CBAR ;
+; out0 (cbar),a ;
+ ex de,hl ;
+ ld e,(hl) ;
+ inc hl ;
+ ld d,(hl) ;
+ ex de,hl ;
+ push bc ;
+ call jphl ;
+
+ pop bc ;
+ pop hl ; restore bank
+; out0 (cbar),h ;
+ pop hl ;
+ ld sp,hl ;
+ pop af ;
+ pop de ;
+ pop hl ;
+ ei ;
+ ret ;
+jphl:
+ jp (hl) ;
+
+; ---------------------------------------------------------
+
+sp.int0:
+ ld a,0d0h
+ jr sp.i.1
+sp.int.len equ $-sp.int0
+ ld a,0d1h
+ jr sp.i.1
+ ld a,0d2h
+ jr sp.i.1
+ ld a,0d3h
+ jr sp.i.1
+ ld a,0d4h
+ jr sp.i.1
+ ld a,0d5h
+ jr sp.i.1
+ ld a,0d6h
+ jr sp.i.1
+ ld a,0d7h
+ jr sp.i.1
+ ld a,0d8h
+sp.i.1:
+; out (80h),a
+ halt
+
+; ---------------------------------------------------------
+
+; Get IFF2
+; This routine may not be loaded in page zero
+;
+; return Carry clear, if INTs are enabled.
+;
+ global getiff
+getiff:
+ xor a ;clear accu and carry
+ push af ;stack bottom := 00xxh
+ pop af
+ ld a,i ;P flag := IFF2
+ ret pe ;exit carry clear, if enabled
+ dec sp
+ dec sp ;has stack bottom been overwritten?
+ pop af
+ and a ;if not 00xxh, INTs were
+ ret nz ;actually enabled
+ scf ;Otherwise, they really are disabled
+ ret
+
+;----------------------------------------------------------------------
+
+ global selbnk
+
+; a: bank (0..2)
+
+selbnk:
+ push bc
+ ld c,a
+ call getiff
+ push af
+
+ ld a,c
+ di
+ ld (@cbnk),a
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio0),a
+
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ pop af
+ pop bc
+ ret c ;INTs were disabled
+ ei
+ ret
+
+;----------------------------------------------------------------------
+
+; c: bank (0..2)
+
+ if 0
+
+selbnk:
+ ld a,(@cbnk)
+ xor c
+ and 3
+ ret z ;no change
+
+ call getiff
+ push af
+ ld a,c
+ di
+ ld (@cbnk),a
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio0),a
+
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ pop af
+ ret nc ;INTs were disabled
+ ei
+ ret
+
+ endif
+
+;----------------------------------------------------------------------
+
+ if 0
+ ex af,af'
+ push af
+ ex af,af'
+
+ rra
+ jr nc,stbk1
+ ex af,af'
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio1),a
+ ex af,af'
+
+stbk1:
+ rra
+ jr nc,stbk2
+ ex af,af'
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ ex af,af'
+
+stbk2:
+ endif
+
+ global @cbnk
+ global mm_sio0, mm_sio1
+
+@cbnk: db 0 ; current bank (0..2)
+mm_sio0:
+ ds 1
+mm_sio1:
+ ds 1
+
+;----------------------------------------------------------------------
+
+curph defl $
+ .dephase
+sysrame:
+ .phase curph
+tim_ms: db 0
+tim_s: dw 0
+ .dephase
+
+;-----------------------------------------------------
+
+ cseg
+
+ ;.phase 0ffc0h
+;ivtab equ 0ffc0h ; 0ffc0h ;int vector table
+ ;.dephase
+
+ ;.phase 0fffch
+mark_55AA equ 0fffch
+ ;ds 4 ; 0fffch
+ ;.dephase
+
+
+ end
+
diff --git a/z180/init.180 b/z180/init.180
new file mode 100644
index 0000000..05c24ff
--- /dev/null
+++ b/z180/init.180
@@ -0,0 +1,913 @@
+ page 255
+ .z80
+
+ extrn ddtz,bpent
+ extrn $stack
+ extrn charini,?const,?conin
+ extrn ?cono,?conos
+ extrn romend
+
+
+ global iobyte
+ global isv_sw
+
+ include config.inc
+ if CPU_Z180
+ include z180reg.inc
+ include z180.lib
+ endif
+
+
+
+
+;----------------------------------------------------------------------
+
+ cseg
+romstart equ $
+
+ org romstart+0
+ jp start
+
+iobyte: db 2
+
+; restart vectors
+
+rsti defl 1
+ rept 7
+ org 8*rsti + romstart
+ jp bpent
+rsti defl rsti+1
+ endm
+
+;----------------------------------------------------------------------
+; Config space
+;
+
+ org romstart+40h
+
+ dw 0
+ db 0
+
+
+ if ROMSYS
+$crom: defb c$rom ;
+ else
+ db 0 ;
+ endif
+
+INIWAITS defl CWAITIO
+ if ROMSYS
+INIWAITS defl INIWAITS+CWAITROM
+ endif
+
+;----------------------------------------------------------------------
+
+ org romstart+50h
+start:
+ jp cstart
+ jp wstart
+ jp ?const
+ jp ?conin
+ jp ?cono
+ jp ?conos
+ jp charini
+
+;----------------------------------------------------------------------
+
+hwini0:
+ if CPU_Z180
+ db ;count
+ db rcr,CREFSH ;configure DRAM refresh
+ db dcntl,INIWAITS ;wait states
+ db cbr,SYS$CBR
+ db cbar,SYS$CBAR
+ endif
+ db 0
+
+ if CPU_Z180
+dmclrt: ;clear ram per dma
+ db dmct_e-dmclrt-2 ;
+ db sar0l ;first port
+ dw nullbyte ;src (fixed)
+nullbyte:
+ db 000h ;src
+ dw romend ;dst (inc), start after "rom" code
+ db 00h ;dst
+ dw 0-romend ;count (64k)
+dmct_e:
+ db 0
+ endif
+
+
+cstart:
+ if CPU_Z180
+
+ push af
+ in0 a,(itc) ;Illegal opcode trap?
+ jp m,??st01
+ ld a,i ;I register == 0 ?
+ jr z,hw_reset ; yes, harware reset
+
+??st01:
+ ; TODO: SYS$CBR
+ ld a,(syscbr)
+ out0 (cbr),a
+ pop af ;restore registers
+ jp bpent ;
+
+hw_reset:
+ di ;0058
+ ld a,CREFSH
+ out0 (rcr),a ; configure DRAM refresh
+ ld a,CWAITIO
+ out0 (dcntl),a ; wait states
+
+ ld a,M_NCD ;No Clock Divide
+ out0 (ccr),a
+; ld a,M_X2CM ;X2 Clock Multiplier
+; out0 (cmr),a
+ else
+ di
+ xor a
+ ld (@cbnk),a
+ endif
+
+; check warm start mark
+
+ ld ix,mark_55AA ; top of common area
+ ld a,0aah ;
+ cp (ix+000h) ;
+ jr nz,kstart ;
+ cp (ix+002h) ;
+ jr nz,kstart ;
+ cpl ;
+ cp (ix+001h) ;
+ jr nz,kstart ;
+ cp (ix+003h) ;
+ jr nz,kstart ;
+ ld sp,$stack ; mark found, check
+ jp z,wstart ; check ok,
+
+; ram not ok, initialize -- kstart --
+
+kstart:
+ if CPU_Z180
+ ld a,SYS$CBR ;TODO:
+ out0 (cbr),a
+ ld a,SYS$CBAR
+ out0 (cbar),a
+ endif
+
+ ld sp,$stack ;01e1
+
+; Clear RAM using DMA0
+
+ if CPU_Z180
+ if 0
+
+ ld hl,dmclrt ;load DMA registers
+ call ioiniml
+ ld a,0cbh ;01ef dst +1, src fixed, burst
+ out0 (dmode),a ;01f1
+
+ ld b,512/64
+ ld a,062h ;01f4 enable dma0,
+??cl_1:
+ out0 (dstat),a ;01f9 clear (up to) 64k
+ djnz ??cl_1 ; end of RAM?
+
+ endif
+ endif
+
+ ld hl,055AAh ;set warm start mark
+ ld (mark_55AA),hl
+ ld (mark_55AA+2),hl
+
+; -- wstart --
+
+wstart:
+ call sysram_init
+ call ivtab_init
+ if CPU_Z180
+; call prt0_init
+ endif
+
+ call msginit
+ call charini
+
+ if CPU_Z80
+ ld a,0
+ call selbnk
+ endif
+
+ ld a,INIDONEVAL ;tell others (CP/M) that hardware and fifos
+ ld (INIDONE),a ; are allready initialized
+
+ im 2
+ ei
+
+ call ?const
+ call ?const
+ or a
+ call nz,?conin
+
+ if CPU_Z180
+ ld e,0 ;Sys$Bank
+ else
+; TODO:
+ endif
+ jp ddtz
+
+
+ if CPU_Z180
+; TODO: SYS$CBR
+syscbr: db 0
+ endif
+
+;
+;----------------------------------------------------------------------
+;
+
+ global bufinit
+
+bufinit:
+ ld (ix+o.in_idx),0 ;reset pointers (empty fifo)
+ ld (ix+o.out_idx),0
+ ld a,(ix+o.id)
+ ld hl,fifolst
+ ld e,a
+ ld d,0
+ add hl,de
+ add hl,de
+ push ix
+ pop de
+ cp 4
+ jr nc,bfi_skip
+
+ ld (hl),e
+ inc hl
+ ld (hl),d
+
+bfi_skip:
+ ex de,hl
+ call hwl2phy ;get phys. address of fifo
+ ld c,a
+ ld a,(ix+o.id) ;fifo id
+ or a ;test if fifo 0
+ ret z
+
+ ld b,a
+ push bc ;c: bank-addr, b: ignored
+ push hl ;address
+ ld c,0
+ push bc ;c: function, b:subf
+ ld b,5
+ ld h,c
+ ld l,c
+ add hl,sp
+ call msg.sm
+ pop hl
+ pop hl
+ pop hl
+ ret
+
+ public fifolst
+fifolst :
+ rept 4
+ dw 0
+ endm
+
+;----------------------------------------------------------------------
+
+ extrn msg.sm
+ extrn msginit,msg.sout
+ extrn mtx.fifo,mrx.fifo
+ extrn ff.init,co.fifo,ci.fifo
+
+
+fifoinit:
+ if CPU_Z180
+
+ ret
+
+ else ;CPU_Z180
+
+ call msginit
+
+ ld hl,buffers
+ ld b,buftablen
+bfi_1:
+ ld a,(hl)
+ inc hl
+ ld (bufdat+0),a
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ inc hl
+ ex de,hl
+
+ or a
+ jr nz,bfi_2
+
+ ld a,(@cbnk)
+ call bnk2phy
+
+ ld (40h+0),hl
+ ld (40h+2),a
+ out (AVRINT5),a
+ jr bfi_3
+bfi_2:
+
+ ld a,(@cbnk)
+ call bnk2phy
+
+ ld (bufdat+1),hl
+ ld (bufdat+3),a
+ ld hl,inimsg
+ call msg.sout
+bfi_3:
+ ex de,hl
+ djnz bfi_1
+ ret
+ endif
+
+
+
+
+;
+;----------------------------------------------------------------------
+;
+
+sysram_init:
+ ld hl,sysramw
+ ld de,topcodsys
+ ld bc,sysrame-sysramw
+ ldir
+
+ ret
+
+;----------------------------------------------------------------------
+
+ivtab_init:
+ ld hl,ivtab ;
+ ld a,h ;
+ ld i,a ;
+ if CPU_Z180
+ out0 (il),l ;
+ endif
+
+; Let all vectors point to spurious int routines.
+
+ ld d,high sp.int0
+ ld a,low sp.int0
+ ld b,9
+ivt_i1:
+ ld (hl),a
+ inc l
+ ld (hl),d
+ inc l
+ add a,sp.int.len
+ djnz ivt_i1
+ ret
+
+;----------------------------------------------------------------------
+
+; Reload value for 10 ms Int. (0.1KHz):
+; tc10ms = phi/prescale/0.1KHz = phi / (prescale/10)
+
+PRT_TC10MS equ 18432 / (PRT_PRE/10)
+
+
+ if CPU_Z180
+prt0_init:
+ ld a,i
+ ld h,a
+ in0 a,(il)
+ and 0E0h
+ or IV$PRT0
+ ld l,a
+ ld (hl),low iprt0
+ inc hl
+ ld (hl),high iprt0
+ ld hl,prt0itab
+ call ioiniml
+ ret
+
+prt0itab:
+ db prt0it_e-prt0itab-2
+ db tmdr0l
+ dw PRT_TC10MS
+ dw PRT_TC10MS
+ db M_TIE0+M_TDE0 ;enable timer 0 interrupt and down count.
+prt0it_e:
+ db 0
+ endif
+
+
+;
+;----------------------------------------------------------------------
+;
+
+ if CPU_Z180
+io.ini:
+ if 0
+ push bc
+ ld b,0 ;high byte port adress
+ioi_nxt:
+ ld a,(hl) ;count
+ inc hl
+ or a
+ jr z,ioi_e
+
+ ld c,(hl) ;port address
+ inc hl
+ioi_r:
+ outi
+ inc b ;outi decrements b
+ dec a
+ jr nz,ioi_r
+ jr ioi_nxt
+ioi_e:
+ pop bc
+ ret
+
+ else ;(if 1/0)
+
+ push bc
+ jr ioi_nxt
+ioi_l:
+ ld c,(hl) ;port address
+ inc hl
+ inc c
+ioi_r:
+ dec c ;otim increments c
+ otim
+ jr z,ioi_r
+ioi_nxt:
+ ld b,(hl) ;count
+ inc hl
+ inc b ;stop if count == 0
+ djnz ioi_l
+ pop bc
+ ret
+
+ endif ;(1/0)
+
+ else
+
+io.ini:
+ push bc
+ jr ioi_nxt
+ioi_l:
+ ld c,(hl) ;port address
+ inc hl
+ otir
+ioi_nxt:
+ ld b,(hl) ;count
+ inc hl
+ inc b
+ djnz ioi_l
+ endif
+ pop bc
+ ret
+
+;----------------------------------------------------------------------
+
+ if CPU_Z180
+
+ global ioiniml
+
+ioiniml:
+ push bc
+ xor a
+ioml_lp:
+ ld b,(hl)
+ inc hl
+ cp b
+ jr z,ioml_e
+
+ ld c,(hl)
+ inc hl
+ otimr
+ jr ioml_lp
+ioml_e:
+ pop bc
+ ret z
+ endif
+
+io.ini.l:
+;
+
+
+
+;----------------------------------------------------------------------
+;
+ if CPU_Z180
+
+;--------------------------------------------------------------------
+; Return the BBR value for the given bank number
+;
+; in a: Bank number
+; out a: bbr value
+
+bnk2log:
+ or a ;
+ ret z ; Bank 0 is at physical address 0
+
+ push bc ;
+ ld b,a ;
+ ld c,CA ;
+ mlt bc ;
+ ld a,c ;
+ add a,10h ;
+ pop bc ;
+ ret ;
+
+;--------------------------------------------------------------
+
+;in hl: Log. Address
+; a: Bank number
+;
+;out ahl: Phys. (linear) Address
+
+
+bnk2phy:
+ call bnk2log
+ ; fall thru
+
+;--------------------------------------------------------------
+;
+; hl: Log. Address
+; a: Bank base (bbr)
+;
+; 2 0 0
+; 0 6 8 0
+; hl hhhhhhhhllllllll
+; a + bbbbbbbb
+;
+; OP: ahl = (a<<12) + (h<<8) + l
+;
+;out ahl: Phys. (linear) Address
+
+log2phy:
+ push bc ;
+l2p_i:
+ ld c,a ;
+ ld b,16 ;
+ mlt bc ; bc = a<<4
+ ld a,c ;
+ add a,h ;
+ ld h,a ;
+ ld a,b ;
+ adc a,0 ;
+ pop bc ;
+ ret ;
+
+;--------------------------------------------------------------
+;
+; hl: Log. Address
+;
+;
+; OP: ahl = (bankbase<<12) + (d<<8) + e
+;
+;out ahl: Phys. (linear) Address
+
+ public hwl2phy
+
+hwl2phy:
+ push bc ;
+ in0 c,(cbar) ;
+ ld a,h ;
+ or 00fh ; log. addr in common1?
+ cp c
+ jr c,hlp_1
+
+ in0 a,(cbr) ; yes, cbr is address base
+ jr hl2p_x
+hlp_1:
+ ld b,16 ; log. address in baked area?
+ mlt bc
+ ld a,h
+ cp c
+ jr c,hlp_2
+ in0 a,(bbr) ; yes, bbr is address base
+ jr hl2p_x
+hlp_2:
+ xor a ; common1
+hl2p_x:
+ jr nz,l2p_i
+
+ pop bc ; bank part is 0, no translation
+ ret ;
+
+
+
+ else ;CPU_Z180
+
+;----------------------------------------------------------------------
+;
+
+bnk2phy:
+ sla h
+ jr nc,b2p_1 ;A15=1 --> common
+ ld a,3
+b2p_1:
+ srl a
+ rr h
+ ret
+
+ endif
+
+;--------------------------------------------------------------
+;
+;return:
+; hl = hl + a
+; Flags undefined
+;
+
+add_hl_a:
+ add a,l
+ ld l,a
+ ret nc
+ inc h
+ ret
+
+; ---------------------------------------------------------
+
+sysramw:
+
+ .phase isvsw_loc
+topcodsys:
+
+; Trampoline for interrupt routines in banked ram.
+; Switch stack pointer to "system" stack in top ram
+; Save cbar
+
+isv_sw: ;
+ ex (sp),hl ;save hl, 'return adr' in hl
+ push de ;
+ push af ;
+ ex de,hl ;'return address' in de
+ ld hl,0 ;
+ add hl,sp ;
+ ld a,h ;
+ cp 0f8h ;
+ jr nc,isw_1 ;stack allready in top ram
+ ld sp,$stack ;
+isw_1:
+ push hl ;save user stack pointer
+ in0 h,(cbar) ;
+ push hl ;
+ ld a,SYS$CBAR ;
+ out0 (cbar),a ;
+ ex de,hl ;
+ ld e,(hl) ;
+ inc hl ;
+ ld d,(hl) ;
+ ex de,hl ;
+ push bc ;
+ call jphl ;
+
+ pop bc ;
+ pop hl ;
+ out0 (cbar),h ;
+ pop hl ;
+ ld sp,hl ;
+ pop af ;
+ pop de ;
+ pop hl ;
+ ei ;
+ ret ;
+jphl:
+ jp (hl) ;
+
+; ---------------------------------------------------------
+
+ if CPU_Z180
+
+iprt0:
+ push af
+ push hl
+ in0 a,(tcr)
+ in0 a,(tmdr0l)
+ in0 a,(tmdr0h)
+ ld a,(tim_ms)
+ inc a
+ cp 100
+ jr nz,iprt_1
+ xor a
+ ld hl,(tim_s)
+ inc hl
+ ld (tim_s),hl
+iprt_1:
+ ld (tim_ms),a
+ pop hl
+ pop af
+ ei
+ ret
+
+ endif
+
+; ---------------------------------------------------------
+
+sp.int0:
+ ld a,0d0h
+ jr sp.i.1
+sp.int.len equ $-sp.int0
+ ld a,0d1h
+ jr sp.i.1
+ ld a,0d2h
+ jr sp.i.1
+ ld a,0d3h
+ jr sp.i.1
+ ld a,0d4h
+ jr sp.i.1
+ ld a,0d5h
+ jr sp.i.1
+ ld a,0d6h
+ jr sp.i.1
+ ld a,0d7h
+ jr sp.i.1
+ ld a,0d8h
+sp.i.1:
+; out (80h),a
+ halt
+
+; ---------------------------------------------------------
+
+ if CPU_Z80
+
+; Get IFF2
+; This routine may not be loaded in page zero
+;
+; return Carry clear, if INTs are enabled.
+;
+ global getiff
+getiff:
+ xor a ;clear accu and carry
+ push af ;stack bottom := 00xxh
+ pop af
+ ld a,i ;P flag := IFF2
+ ret pe ;exit carry clear, if enabled
+ dec sp
+ dec sp ;has stack bottom been overwritten?
+ pop af
+ and a ;if not 00xxh, INTs were
+ ret nz ;actually enabled
+ scf ;Otherwise, they really are disabled
+ ret
+
+;----------------------------------------------------------------------
+
+ global selbnk
+
+; a: bank (0..2)
+
+selbnk:
+ push bc
+ ld c,a
+ call getiff
+ push af
+
+ ld a,c
+ di
+ ld (@cbnk),a
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio0),a
+
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ pop af
+ pop bc
+ ret c ;INTs were disabled
+ ei
+ ret
+
+;----------------------------------------------------------------------
+
+; c: bank (0..2)
+
+ if 0
+
+selbnk:
+ ld a,(@cbnk)
+ xor c
+ and 3
+ ret z ;no change
+
+ call getiff
+ push af
+ ld a,c
+ di
+ ld (@cbnk),a
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio0),a
+
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ pop af
+ ret nc ;INTs were disabled
+ ei
+ ret
+
+ endif
+
+;----------------------------------------------------------------------
+
+ if 0
+ ex af,af'
+ push af
+ ex af,af'
+
+ rra
+ jr nc,stbk1
+ ex af,af'
+ ld a,5
+ out (SIOAC),a
+ ld a,(mm_sio0)
+ rla
+ srl c
+ rra
+ out (SIOAC),a
+ ld (mm_sio1),a
+ ex af,af'
+
+stbk1:
+ rra
+ jr nc,stbk2
+ ex af,af'
+ ld a,5
+ out (SIOBC),a
+ ld a,(mm_sio1)
+ rla
+ srl c
+ rra
+ out (SIOBC),a
+ ld (mm_sio1),a
+ ex af,af'
+
+stbk2:
+ endif
+
+ global @cbnk
+ global mm_sio0, mm_sio1
+
+@cbnk: db 0 ; current bank (0..2)
+mm_sio0:
+ ds 1
+mm_sio1:
+ ds 1
+
+
+ endif
+
+;----------------------------------------------------------------------
+
+curph defl $
+ .dephase
+sysrame:
+ .phase curph
+tim_ms: db 0
+tim_s: dw 0
+ .dephase
+
+;-----------------------------------------------------
+
+
+ cseg
+
+ ;.phase 0ffc0h
+;ivtab equ 0ffc0h ; 0ffc0h ;int vector table
+ ;.dephase
+
+ ;.phase 0fffah
+mark_55AA equ 0 - 2 - 4 ;2 byte for trap stack
+ ;ds 4
+ ;.dephase
+
+
+ end
diff --git a/z180/msgbuf-a.180 b/z180/msgbuf-a.180
index 36e0871..3575569 100644
--- a/z180/msgbuf-a.180
+++ b/z180/msgbuf-a.180
@@ -1,22 +1,25 @@
page 255
.z80
-
- global mrx.fifo,mtx.fifo
- global msginit,msgi.st,msg.in,msgo.st,msg.out
- global msg.sout
-
- extrn buf.init
+ public mrx.fifo,mtx.fifo
+
+ public msginit,msgi.st,msg.in,msgo.st
+ public msg.sm,msg.sout
+
+ extrn bufinit,hwl2phy
+ extrn fifolst
include config.inc
+ if CPU_Z180
include z180reg.inc
+ endif
;--------------------------------------------------------------
dseg
- mkbuf mrx.fifo,mrx.fifo_len
- mkbuf mtx.fifo,mtx.fifo_len
+ mkbuf mtx.fifo_id, mtx.fifo, mtx.fifo_len
+ mkbuf mrx.fifo_id, mrx.fifo, mrx.fifo_len
;--------------------------------------------------------------
@@ -25,14 +28,27 @@
;
; Init buffer
;
-
+
msginit:
- ld ix,mrx.fifo
- ld a,mrx.fifo.mask
- call buf.init
+ ld a,(043h)
+;TODO: value should be 0
ld ix,mtx.fifo
- ld a,mtx.fifo.mask
- jp buf.init
+ call bufinit
+ push ix
+ pop hl
+ call hwl2phy
+ ld (040h),hl
+ ld (040h+2),a
+ ld a,0ffh
+ ld (043h),a
+ out (AVRINT5),a
+wait:
+ ld a,(043h)
+ or a
+ jr nz,wait
+
+ ld ix,mrx.fifo
+ jp bufinit
;--------------------------------------------------------------
@@ -47,7 +63,7 @@ buf.empty:
ret z
or 0ffh
ret
-
+
;--------------------------------------------------------------
msg.in:
@@ -69,12 +85,12 @@ bg.wait:
inc h
bg.nc:
ld l,(hl)
-
+
ld a,(ix+o.out_idx) ;
inc a
and (ix+o.mask)
ld (ix+o.out_idx),a
-
+
ld a,l
pop hl
pop ix
@@ -98,6 +114,8 @@ buf.full:
;--------------------------------------------------------------
+ if 0
+
msg.out:
push ix
ld ix,mtx.fifo ;
@@ -120,58 +138,192 @@ bp.wait:
jr z,bp.wait
ld (hl),b
ld (ix+o.in_idx),a
-
+
ld a,b
- out0 (AVRINT5),a
+ out (AVRINT5),a
pop bc
pop hl
pop ix
ret
+ endif
;--------------------------------------------------------------
-;
-; (hl): data
-msg.sout:
+ if 0
+
+msg.out:
push ix
ld ix,mtx.fifo ;
+buf.put:
push bc
- push de
- ld b,(hl) ;
- inc hl
- ex de,hl
-
-ms.ol:
- push ix
- pop hl
ld c,(ix+o.in_idx) ;
- ld a,c
- add l
- ld l,a
- jr nc,ms.on
- inc h
-ms.on:
+ ld b,0
+ push ix ;14
+ add ix,bc ;10
+ ld (ix+0),a ;15
+ pop ix ;12 / 51
+ ld b,a ; 4
ld a,c ;
- inc a
- and (ix+o.mask)
-ms.wait:
+ inc a ;
+ and (ix+o.mask) ;
+bp.wait:
cp (ix+o.out_idx) ;
- jr z,ms.wait
- ld c,a
- ld a,(de)
- inc de
- ld (hl),a
- ld (ix+o.in_idx),c
- djnz ms.ol
- out0 (AVRINT5),a
- ex de,hl
- pop de
+ jr z,bp.wait ;
+ ld (ix+o.in_idx),a ;
+
+ ld a,b
+ out (AVRINT5),a
pop bc
pop ix
ret
+ endif
+
+;----------------------------------------------------------------------
+;
+; Put char in message buffer:
+; ix: buffer to put into
+; c: char
+
+buf.put:
+ push ix ;15
+ push bc ;11
+ ld a,(ix+o.in_idx) ;19
+ ld c,a ;4
+ ld b,0 ;7
+ add ix,bc ;11
+ pop bc ;10
+ ld (ix),c ;7
+ pop ix ;14
+
+ inc a ;4
+ and (ix+o.mask) ;19 =121
+bufp.wait:
+ cp (ix+o.out_idx) ;19
+ jr z,bufp.wait ;12/7
+ ld (ix+o.in_idx),a ;19
+
+ out (AVRINT5),a ;11
+ ld a,c ;4
+ ret ;10 =191
+
+
+;--------------------------------------------------------------
+
+ if 0
+ ; Works only, if buffer size < (128 - 3)
+ ; --> mask must be 03fh or less
+
+msg.out:
+ push ix
+ ld ix,mtx.fifo ;
+
+buf.put:
+ push bc
+ ld b,a ; 4
+ ld a,(ix+o.in_idx) ;14
+ ld ($ + 3 + 2),a ;15
+ ld (ix+0),b ;15
+ inc a ;
+ and (ix+o.mask) ;
+bp.wait:
+ cp (ix+o.out_idx) ;
+ jr z,bp.wait ;
+ ld (ix+o.in_idx),a ;
+
+ ld a,b
+ out (AVRINT5),a
+ pop bc
+ pop ix
+ ret
+
+ endif
+
+;--------------------------------------------------------------
+;
+; (hl): data
+
+msg.sout:
+ push ix ;14
+ ld ix,mtx.fifo ;12
+ push bc ;11
+ push de ;11
+ ld c,(hl) ; 6
+ ld b,0 ; 6
+ inc hl ; 7
+ms.ol: ; \
+ ld a,low mtx.fifo ; 6
+ add a,(ix+o.in_idx) ;14
+ ld e,a ; 4
+ ld a,high mtx.fifo ; 6
+ adc a,b ; 4
+ ld d,a ; 4
+
+ ld a,(ix+o.in_idx) ;14
+ inc a ; 4
+ and (ix+o.mask) ;14
+ms.wait:
+ cp (ix+o.out_idx) ;14
+ jr z,ms.wait ; 6/8
+
+ ldi ;12
+ ld (ix+o.in_idx),a ;15
+ jp pe,ms.ol ; 6/9 -- 126
+
+ out (AVRINT5),a ;10
+ pop de ; 9
+ pop bc ; 9
+ pop ix ;12
+ ret ; 9
+
+;--------------------------------------------------------------
+;
+; (hl): data
+
+ if 0
+
+msg.sout:
+ push ix ;14
+ ld ix,mtx.fifo ;12
+ push bc ;11
+ push de ;11
+ ld b,(hl) ; 6
+ inc hl ; 4
+ ex de,hl ; 3
+ms.ol: ; \
+ push ix ;14
+ pop hl ; 9
+ ld c,(ix+o.in_idx) ;14
+ ld a,c ; 4
+ add l ; 4
+ ld l,a ; 4
+ jr nc,ms.on ; 6/8
+ inc h ; 4
+ms.on:
+ ld a,c ; 4
+ inc a ; 4
+ and (ix+o.mask) ;14
+ms.wait:
+ cp (ix+o.out_idx) ;14
+ jr z,ms.wait ; 6/8
+ ld c,a ; 4
+ ld a,(de) ; 6
+ inc de ; 4
+ ld (hl),a ; 7
+ ld (ix+o.in_idx),c ;15
+ djnz ms.ol ; 7/9 -- 130
+
+ out (AVRINT5),a ;10
+ ex de,hl ; 3
+ pop de ; 9
+ pop bc ; 9
+ pop ix ;12
+ ret ; 9
+
+ endif
+
;--------------------------------------------------------------
msg.co:
@@ -183,8 +335,8 @@ msg.co:
pop hl
pop af
ret
-
-
+
+
buf:
db buf_end - $ - 1 ;output string length
db 0AEh ; message start token
@@ -197,5 +349,26 @@ buf_end:
;----------------------------------------------------------------------
- end
+;----------------------------------------------------------------------
+; Send message MEMORY
+;
+; hl: pointer to message (netto)
+; b: msg length
+msg.sm:
+ push ix
+ ld ix,mtx.fifo
+ ld c,0AEh
+ call buf.put
+ ld c,b
+ call buf.put
+msm_l:
+ ld c,(hl)
+ inc hl
+ call buf.put
+ djnz msm_l
+ pop ix
+ ret
+
+
+ end
diff --git a/z180/msgfifo.180 b/z180/msgfifo.180
index 582c219..cf1ae2a 100644
--- a/z180/msgfifo.180
+++ b/z180/msgfifo.180
@@ -1,11 +1,11 @@
page 255
.z80
-
+
global msg_rx_fifo,msg_tx_fifo
global msginit,msgi.st,msg.in,msgo.st,msg.out
global msg.sout,msg.co
-
+
extrn buf.init
include config.inc
@@ -15,8 +15,8 @@
dseg
- mkbuf msg_rx_fifo,msg_rx_fifo_len
- mkbuf msg_tx_fifo,msg_tx_fifo_len
+ mkbuf mtx.fifo_id, msg_tx_fifo, msg_tx_fifo_len
+ mkbuf mrx.fifo_id, msg_rx_fifo, msg_rx_fifo_len
@@ -27,7 +27,7 @@
;
; Init buffer
;
-
+
msginit:
ld ix,msg_rx_fifo
ld a,msg_rx_fifo.mask
@@ -49,7 +49,7 @@ buf.empty:
ret z
or 0ffh
ret
-
+
;--------------------------------------------------------------
msg.in:
@@ -71,12 +71,12 @@ bg.wait:
inc h
bg.nc:
ld l,(hl)
-
+
ld a,(ix+o.out_idx) ;
inc a
and (ix+o.mask)
ld (ix+o.out_idx),a
-
+
ld a,l
pop hl
pop ix
@@ -122,7 +122,7 @@ bp.wait:
jr z,bp.wait
ld (hl),b
ld (ix+o.in_idx),a
-
+
ld a,b
out0 (AVRINT5),a
pop bc
@@ -152,7 +152,7 @@ bp.wait:
ld a,b
out (PMSG),a
ld (ix+o.in_idx),c
-
+
pop bc
pop ix
ret
@@ -171,7 +171,7 @@ msg.sout:
ld b,(hl) ;
inc hl
ex de,hl
-
+
ms.ol:
push ix
pop hl
@@ -242,8 +242,8 @@ msg.co:
pop hl
pop af
ret
-
-
+
+
buf:
db buf_end - $ - 1 ;output string length
db 081h ; message start token
@@ -257,4 +257,3 @@ buf_end:
;----------------------------------------------------------------------
end
-
diff --git a/z180/r3init.180 b/z180/r3init.180
deleted file mode 100644
index 9edeaf2..0000000
--- a/z180/r3init.180
+++ /dev/null
@@ -1,957 +0,0 @@
- page 255
- .z80
-
- extrn ddtz,bpent
- extrn $stack
- extrn charini,?const,?conin
-
- extrn romend
-
-
- global isv_sw
-
- include config.inc
- include z180reg.inc
- include z180.lib
-
-;CR equ 0dh
-
-
-
-;----------------------------------------------------------------------
-
- cseg
-
- jp start
-
-; restart vectors
-
-rsti defl 1
- rept 7
- db 0, 0, 0, 0, 0
- jp bpent
-rsti defl rsti+1
- endm
- db 0, 0, 0, 0, 0
-
-;----------------------------------------------------------------------
-
- ;org 40h
-
- dw 0
- db 0
-
-
- if ROMSYS
-$crom: defb c$rom ;
- else
- db 0 ;
- endif
-
-dmclrt: ;clear ram per dma
- db dmct_e-dmclrt-2 ;
- db sar0l ;first port
- dw nullbyte ;src (fixed)
-nullbyte:
- db 000h ;src
- dw romend ;dst (inc), start after "rom" code
- db 00h ;dst
- dw 0-romend ;count (64k)
-dmct_e:
-
-INIWAITS defl CWAITIO
- if ROMSYS
-INIWAITS defl INIWAITS+CWAITROM
- endif
-
-hwini0:
- db 3 ;count
- db rcr,CREFSH ;configure DRAM refresh
- db dcntl,INIWAITS ;wait states
- db cbar,SYS$CBAR
-
-;----------------------------------------------------------------------
-
-start:
- ld (tmpstack),sp
- ld sp,tmpstack
- push af
- in0 a,(itc) ;Illegal opcode trap?
- jp m,??st01
- ld a,i ;I register == 0 ?
- jr z,??st02 ; yes, harware reset
-
-??st01:
- ld a,(syscbr)
- out0 (cbr),a
- pop af ;restore registers
- ld sp,(tmpstack) ;
- jp bpent ;
-
-??st02:
- di ;0058
- ld a,CREFSH
- out0 (rcr),a ; configure DRAM refresh
- ld a,CWAITIO
- out0 (dcntl),a ; wait states
-
- ld a,M_NCD ;No Clock Divide
- out0 (ccr),a
-; ld a,M_X2CM ;X2 Clock Multiplier
-; out0 (cmr),a
-
-; search warm start mark
-
- ld ix,mark_55AA ;00b8 ; top of common area
- ld a,SYS$CBAR ;
- out0 (cbar),a ;
- ld a,071h ;00bc
- ex af,af' ;00be ;for cbr = 0x70 downto 0x40
-swsm_l:
- ex af,af' ;00bf
- dec a ;00c0
- cp 03fh ;00c1
- jr z,kstart ;00c3 ; break (mark not found)
- out0 (cbr),a ;00c5
- ex af,af' ;00c8
- ld a,0aah ;00c9
- cp (ix+000h) ;00cb
- jr nz,swsm_l ;00ce
- cp (ix+002h) ;00d0
- jr nz,swsm_l ;00d3
- cpl ;00d5
- cp (ix+001h) ;00d6
- jr nz,swsm_l ;00d9
- cp (ix+003h) ;00db
- jr nz,swsm_l ;00de
- ld sp,$stack ;00e0 mark found, check
- call checkcrc_alv ;00e3
- jp z,wstart ;00e6 check ok,
-
-;
-; ram not ok, initialize -- kstart --
-
-kstart:
-
- ld a,088h ;00e9 0000-7fff: common 0
- out0 (cbar),a ;00eb 8000-ffff: common 1
- ld ix,08000h ;00f3
- ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
-??f_0:
- out0 (cbr),a ;00f9
-
- ld (ix+0),a ;0103
- cpl
- ld (ix+1),a ;0103
- cpl
- add a,8 ;010a next 'bank'
- cp 078h ;010c stop at 078000
- jr nz,??f_0 ;010e
-
- ld de,8000h ;0114 first block not tested, but mark as ok
- ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
-??cp_0:
- out0 (cbr),a ;011c
- ld c,a
- xor (ix+0)
- ld b,a
- ld a,c
- cpl
- xor (ix+1)
- or b
- jr nz,??cp_1
- scf
-??cp_1:
- rr d
- rr e
- ld a,c
- add a,8
- cp 078h ; stop at 078000
- jr nz,??cp_0
-
-;
-; ram test found 1 or more error free blocks (32k)
-;
-
-ramok:
- ld a,SYS$CBAR ;01c8
- out0 (cbar),a ;01ca
- ld h,d
- ld l,e
- ld c,070h ;01ce highest block
- ld b,15 ;01d0
-??sr_1:
- add hl,hl
- jr c,alloc ;01d4 highest "error free" block
- ld a,c ;01d6
- sub 008h ;01d7
- ld c,a ;01d9
- djnz ??sr_1 ;01da
-
- slp ;01dc should never be reached
-
-alloc:
- out0 (cbr),c ;01de
- ld a,c
- ld (syscbr),a
- ld sp,$stack ;01e1
-
-; Clear RAM using DMA0
-
- ld hl,dmclrt ;load DMA registers
- call io.ini.m
- ld a,0cbh ;01ef dst +1, src fixed, burst
- out0 (dmode),a ;01f1
-
- ld b,512/64
- ld a,062h ;01f4 enable dma0,
-??cl_1:
- out0 (dstat),a ;01f9 clear (up to) 64k
- djnz ??cl_1 ; end of RAM?
-
-; Init bank manager
-
- ld hl,banktabsys ;020f
- ld (hl),c ; Common area
- inc hl ;0213
- ld (hl),c ; System work area
- inc hl ;0215 Point to bank 0 entry
- ld b,BANKS ;0216
-l0218h:
- ld (hl),0ffh ;0218 Mark all banks as unassigned
- inc hl ;021a
- djnz l0218h ;021b
-
- ld hl,memalv ;
- ld b,8 ; 8*4k ie. first 32k
-??a_0:
- ld (hl),0e0h ; mark as sys ("rom"/monitor)
- inc hl
- djnz ??a_0
-
- rr d ; shift out bit for block 0
- rr e ;
- ld c,15 ;022c 15*32k remaining blocks
-l022eh:
- ld a,0feh ; 0xfe == block with error(s)
- rr d ;
- rr e
- adc a,0 ; ==> 0xff : block ok
- ld b,32/4 ; 32k == 8 * 4k
-l0236h:
- ld (hl),a ;
- inc hl ;
- djnz l0236h ;
- dec c ;
- jr nz,l022eh ;next 32k block
-
- ld hl,memalv+0ch ;memalv+0ch
- ld a,(banktabsys) ;
- call add_hl_a
- ld b,3 ;
-l024ah:
- ld (hl),0ech ;alloc system ram
- inc hl ;
- djnz l024ah ;
- ld (hl),0efh ;alloc common
- call gencrc_alv
-
- ld hl,0000h ;bank #
- ld bc,0f0fh ; size (?) (4k blocks)
- xor a ;
- call sub_0420h ;alloc mem for bank 0
- ld c,l ;
- or a ;
- call z,sub_04b5h ;
-
- ld hl,0101h ;
- ld bc,0f0fh ;
- xor a ;
- call sub_0420h ;
- ld c,l ;
- or a ;
- call z,sub_04b5h ;
-
- ld hl,055AAh ;set warm start mark
- ld (mark_55AA),hl ;
- ld (mark_55AA+2),hl;
-
-;
-; crc ok -- wstart --
-;
-wstart:
- call sysram_init ;027f
- call ivtab_init
-
- call prt0_init
-
- call charini
-
- call bufferinit
-
-
-
- im 2 ;?030e
- ei ;0282
-
- call ?const ;0284
- call ?const ;0287
- or a ;028a
- call nz,?conin ;028d
-
- ld a,(banktab) ;
- ld e,a ;
- jp ddtz ;0290
-
-
- ds 8
-tmpstack:
- dw 2
-syscbr: db 1
-
-;
-;----------------------------------------------------------------------
-;
-
-;TODO: Make a ringbuffer module.
-
- global buf.init
-
-buf.init:
- ld (ix+o.in_idx),0
- ld (ix+o.out_idx),0
- ld (ix+o.mask),a
- ret
-
-;----------------------------------------------------------------------
-if 0
- extrn msginit,msg_tx_fifo,msg_rx_fifo
- extrn msg.sout
-
-bufferinit:
-
- ld de,msg_tx_fifo
- in0 a,cbr
- call log2phys
- ld (40h+0),hl
- ld (40h+2),a
-
-; ld (bufdat+1),hl
-; ld (bufdat+3),a
-; ld a,1
-; ld (bufdat+0),a
-; ld hl,inimsg
-; call msg.sout
-
- ld de,msg_rx_fifo
- in0 a,cbr
- call log2phys
- ld (bufdat+1),hl
- ld (bufdat+3),a
- ld a,2
- ld (bufdat+0),a
- ld hl,inimsg
- call msg.sout
-
- ret
-
-inimsg:
- db inimsg_e - $ - 1
- db 0AEh
- db inimsg_e - $ - 1
- db 0
-bufdat:
- db 0
- dw 0
- db 0
-inimsg_e:
-
-endif
-;----------------------------------------------------------------------
-;
-
- extrn msginit,msg.sout
- extrn mtx.fifo,mrx.fifo
- extrn co.fifo,ci.fifo
-
-
-bufferinit:
- call msginit
-
- ld hl,buffers
- ld b,buftablen
-bfi_1:
- ld a,(hl)
- inc hl
- ld (bufdat+0),a
- ld e,(hl)
- inc hl
- ld d,(hl)
- inc hl
- push hl
-
- or a
- jr nz,bfi_2
- in0 a,cbr
- call log2phys
- ld (40h+0),hl
- ld (40h+2),a
- out0 (AVRINT5),a
- jr bfi_3
-bfi_2:
- in0 a,cbr
- call log2phys
- ld (bufdat+1),hl
- ld (bufdat+3),a
- ld hl,inimsg
- call msg.sout
-bfi_3:
- pop hl
- djnz bfi_1
- ret
-
-buffers:
- db 0
- dw mtx.fifo
- db 1
- dw mrx.fifo
- db 2
- dw co.fifo
- db 3
- dw ci.fifo
-buftablen equ ($ - buffers)/3
-
-inimsg:
- db inimsg_e - $ -1
- db 0AEh
- db inimsg_e - $ -1
- db 0
-bufdat:
- db 0
- dw 0
- db 0
-inimsg_e:
-
-
-;
-;----------------------------------------------------------------------
-;
-
-sysram_init:
- ld hl,sysramw
- ld de,topcodsys
- ld bc,sysrame-sysramw
- ldir
-
- ret
-
-;----------------------------------------------------------------------
-
-ivtab_init:
- ld hl,ivtab ;
- ld a,h ;
- ld i,a ;
- out0 (il),l ;
-
-; Let all vectors point to spurious int routines.
-
- ld d,high sp.int0
- ld a,low sp.int0
- ld b,9
-ivt_i1:
- ld (hl),a
- inc l
- ld (hl),d
- inc l
- add a,sp.int.len
- djnz ivt_i1
- ret
-
-;----------------------------------------------------------------------
-
-prt0_init:
- ld a,i
- ld h,a
- in0 a,(il)
- and 0E0h
- or IV$PRT0
- ld l,a
- ld (hl),low iprt0
- inc hl
- ld (hl),high iprt0
- ld hl,prt0itab
- call io.ini.m
- ret
-
-prt0itab:
- db prt0it_e-prt0itab-2
- db tmdr0l
- dw PRT_TC10MS
- dw PRT_TC10MS
- db M_TIE0+M_TDE0 ;enable timer 0 interrupt and down count.
-prt0it_e:
-
-
-;
-;----------------------------------------------------------------------
-;
-
-io.ini:
- push bc
- ld b,0 ;high byte port adress
- ld a,(hl) ;count
- inc hl
-ioi_1:
- ld c,(hl) ;port address
- inc hl
- outi
- inc b ;outi decrements b
- dec a
- jr nz,ioi_1
- pop bc
- ret
-
-io.ini.m:
- push bc
- ld b,(hl)
- inc hl
- ld c,(hl)
- inc hl
- otimr
- pop bc
- ret
-
-io.ini.l:
-;
-
-;----------------------------------------------------------------------
-;
-
-; compute crc
-; hl: start adr
-; bc: len
-; bc returns crc val
-
-do_crc16:
- ld de,0FFFFh
-crc1:
- ld a,(hl)
- xor e
- ld e,a
- rrca
- rrca
- rrca
- rrca
- and 0Fh
- xor e
- ld e,a
- rrca
- rrca
- rrca
- push af
- and 1Fh
- xor d
- ld d,a
- pop af
- push af
- rrca
- and 0F0h
- xor d
- ld d,a
- pop af
- and 0E0h
- xor e
- ld e,d
- ld d,a
- cpi
- jp pe,crc1
- or e ;z-flag
- ret
-
-
-gencrc_alv:
- push hl ;03f6
- push de ;03f7
- push bc
- push af ;03f8
- ld hl,banktabsys ;03f9
- ld bc,crc_len ;03fc
- call do_crc16 ;03ff
- ld (hl),e
- inc hl
- ld (hl),d
- pop af ;0406
- pop bc
- pop de ;0407
- pop hl ;0408
- ret ;0409
-
-checkcrc_alv:
- push hl ;040a
- push de
- push bc ;040b
- ld hl,banktabsys ;040d
- ld bc,crc_len+2 ;0410
- call do_crc16 ;0413
- pop bc ;041d
- pop de
- pop hl ;041e
- ret ;041f
-
-;----------------------------------------------------------------------
-
-;
-; alloc
-;
-; h: max bank #
-; l: min bank #
-; b: max size
-; c: min size
-;
-; ret:
-; a: 0 == ok
-; 1 ==
-; 2 == no bank # in requested range
-; ff == crc error
-;
-
-sub_0420h:
- call checkcrc_alv ;0420
- jr nz,l049ch ;0424 crc error, tables corrupt
-
- call sub_049dh ;0427 bank # in req. range available?
- jr c,l0499h ;042a
- push ix ;042c
- push iy ;042e
- push de ;0430
- push hl ;0431
- push bc ;0432
- ld c,b ;0433
- ld b,alv_len+1 ;0434
- ld d,0 ;0436
- ld hl,memalv-1 ;0438
- jr l0441h ;043b
-
-; find free blocks
-
-l043dh:
- ld a,(hl) ;043d
- inc a ;043e free blocks are marked 0ffh
- jr z,l0446h ;043f
-l0441h:
- inc hl ;0441
- djnz l043dh ;0442
- jr l0464h ;0444
-l0446h:
- push hl ;0446
- pop ix ;0447 free blocks start here
- ld e,000h ;0449
- jr l0451h ;044b
-l044dh: ; count free blocks
- ld a,(hl) ;044d
- inc a ;044e
- jr nz,l0457h ;044f
-l0451h:
- inc e ;0451
- inc hl ;0452
- djnz l044dh ;0453
- jr l0464h ;0455
-
-; end of free blocks run.
-
-l0457h:
- ld a,d ;0457
- cp e ;0458 nr of blocks >= requested ?
- jr nc,l0441h ;0459
-
- ld d,e ;045b
- push ix ;045c
- pop iy ;045e
- ld a,d ;0460
- cp c ;0461
- jr c,l0441h ;0462
-l0464h:
- pop bc ;0464
- ld a,d ;0465
- cp b ;0466
- jr c,l046ch ;0467
- ld d,b ;0469
- jr l0471h ;046a
-l046ch:
- cp c ;046c
- jr nc,l0471h ;046d
- ld d,000h ;046f
-l0471h:
- ld a,d ;0471
- push iy ;0472
- pop hl ;0474
- ld de,memalv ;0475
- or a ;0478
- sbc hl,de ;0479
- ld b,l ;047b
- ld c,a ;047c
- pop hl ;047d
-l047eh:
- or a ;047e
- jr z,l0489h ;047f
- ld (iy+0),l ;0481
- inc iy ;0484
- dec a ;0486
- jr l047eh ;0487
-l0489h:
- pop de ;0489
- pop iy ;048a
- pop ix ;048c
- call gencrc_alv ;048e
- ld a,c ;0491
- or a ;0492
- ld a,000h ;0493
- ret nz ;0495
- or 001h ;0496
- ret ;0498
-
-l0499h:
- ld a,2 ;0499
-l049ch:
- or a
- ret ;049c
-
-
-; search a free bank number in range
-; h: max #
-; l: min #
-; ret:
-; l: bank number available
-; nc, if found, bank nr. in l
-; cy, if none found
-
-sub_049dh:
- push de ;049d
- push bc ;049e
- ex de,hl ;049f
- dec e ;04a0
-l04a1h:
- inc e ;04a1 test next #
- ld a,d ;04a2
- cp e ;04a3
- jr c,l04b1h ;04a4
- ld a,e ;04a6
- ld hl,memalv ;04a7
- ld bc,alv_len ;04aa
- cpir ;04ad bank# allready allocated?
- jr z,l04a1h ;04af if yes, search for next
-l04b1h:
- ex de,hl ;04b1
- pop bc ;04b2
- pop de ;04b3
- ret ;04b4
-
-
-sub_04b5h:
- ld a,l ;04b5
- cp 012h ;04b6
- ccf ;04b8
- ret c ;04b9
- push hl ;04ba
- ld hl,banktab ;04bb
- call add_hl_a
- ld (hl),b ;04c3
- call gencrc_alv ;04c4
- pop hl ;04c7
- or a ;04c8 clear carry
- ret ;04c9
-
-
-;--------------------------------------------------------------
-;
-; de: Log. Address
-; a: Bank number
-;
-;out ahl: Phys. (linear) Address
-
-
-bnk2phys:
- push hl
- ld hl,banktab
- call add_hl_a
- ld a,(hl)
- pop hl
-
- ; fall thru
-;--------------------------------------------------------------
-;
-; de: Log. Address
-; a: Bank (bbr)
-;
-; OP: ahl = (a<<12) + (d<<8) + e
-;
-;out ahl: Phys. (linear) Address
-
-
-log2phys:
- push bc ;
- ld c,a ;
- ld b,16 ;
- mlt bc ;bc = a<<4
- ld l,d ;
- ld h,0 ;
- add hl,bc ;bc + d == a<<4 + d
- ld a,h ;
- ld h,l ;
- ld l,e ;
- pop bc ;
- ret ;
-
-
-;--------------------------------------------------------------
-;
-;return:
-; hl = hl + a
-; Flags undefined
-;
-
-add_hl_a:
- add a,l
- ld l,a
- ret nc
- inc h
- ret
-
-; ---------------------------------------------------------
-
-sysramw:
-
- .phase isvsw_loc
-topcodsys:
-
-; Trampoline for interrupt routines in banked ram.
-; Switch stack pointer to "system" stack in top ram
-; Save cbar
-
-isv_sw: ;
- ex (sp),hl ; save hl, return adr in hl
- push de ;
- push af ;
- ex de,hl ;
- ld hl,0 ;
- add hl,sp ;
- ld a,h ;
- cp 0f8h ;
- jr nc,isw_1 ;
- ld sp,$stack ;
-isw_1:
- push hl ;
- in0 h,(cbar) ;
- push hl ;
- ld a,SYS$CBAR ;
- out0 (cbar),a ;
- ex de,hl ;
- ld e,(hl) ;
- inc hl ;
- ld d,(hl) ;
- ex de,hl ;
- push bc ;
- call jphl ;
-
- pop bc ;
- pop hl ;
- out0 (cbar),h ;
- pop hl ;
- ld sp,hl ;
- pop af ;
- pop de ;
- pop hl ;
- ei ;
- ret ;
-jphl:
- jp (hl) ;
-
-; ---------------------------------------------------------
-
-
-iprt0:
- push af
- push hl
- in0 a,(tcr)
- in0 a,(tmdr0l)
- in0 a,(tmdr0h)
- ld a,(tim_ms)
- inc a
- cp 100
- jr nz,iprt_1
- xor a
- ld hl,(tim_s)
- inc hl
- ld (tim_s),hl
-iprt_1:
- ld (tim_ms),a
- pop hl
- pop af
- ei
- ret
-
-; ---------------------------------------------------------
-
-sp.int0:
- ld a,0d0h
- jr sp.i.1
-sp.int.len equ $-sp.int0
- ld a,0d1h
- jr sp.i.1
- ld a,0d2h
- jr sp.i.1
- ld a,0d3h
- jr sp.i.1
- ld a,0d4h
- jr sp.i.1
- ld a,0d5h
- jr sp.i.1
- ld a,0d6h
- jr sp.i.1
- ld a,0d7h
- jr sp.i.1
- ld a,0d8h
-sp.i.1:
-; out (80h),a
- halt
-
-curph defl $
- .dephase
-sysrame:
- .phase curph
-tim_ms: db 0
-tim_s: dw 0
- .dephase
-
-;-----------------------------------------------------
-
- dseg
-
- ds 1
-banktabsys:
- ds 1 ;0c001h
- ds 1 ;0c002h
-banktab:
- ds BANKS ;0c003h
-memalv:
- ds 512/4 ;Number of 4k blocks
-alv_len equ $-memalv
-crc_len equ $-banktabsys
-
-crc_memalv:
- ds 2 ;
-
- cseg
-
- ;.phase 0ffc0h
-;ivtab equ 0ffc0h ; 0ffc0h ;int vector table
- ;.dephase
-
- ;.phase 0fffch
-mark_55AA equ 0fffch
- ;ds 4 ; 0fffch
- ;.dephase
-
-
- end
-
diff --git a/z180/z180reg.inc b/z180/z180reg.inc
index 5bbd088..2666867 100644
--- a/z180/z180reg.inc
+++ b/z180/z180reg.inc
@@ -24,7 +24,7 @@ cntla1 equ IOBASE+01h ;ASCI Control Register A Channel 1
b2m MPBR, 3 ;Multiprocessor Bit Receive (Read)
b2m EFR, 3 ;Error Flag Reset (Write)
b2m MOD2, 2 ;Data Format Mode 1 = 8-Bit data
- b2m NOD1, 1 ;1 = Parity enabled
+ b2m MOD1, 1 ;1 = Parity enabled
b2m MOD0, 0 ;1 = 2 stop bits
cntlb0 equ IOBASE+02h ;ASCI Control Register B Channel 0
@@ -76,6 +76,13 @@ tcr equ IOBASE+10h ;Timer Control Register
asext0 equ IOBASE+12h ;ASCI Extension Control Register
asext1 equ IOBASE+13h ;ASCI Extension Control Register
+ b2m DCD0DIS,6 ;DCD0 Disable
+ b2m CTS0DIS,5 ;CTS0 Disable
+ b2m X1,4 ;CKA * 1 Clock/Samle Rate Divider
+ b2m BRGMOD,3 ;BRG Mode (Baud rate generator)
+ b2m BREAKEN,2 ;Break Enable
+ b2m BREAK,1 ;Break detected
+ b2m SENDBREAK,0 ;Send Break
tmdr1l equ IOBASE+14h ;Timer Data Register Channel 1
tmdr1h equ IOBASE+15h ;
@@ -123,8 +130,8 @@ bcr1h equ IOBASE+2Fh ;
dstat equ IOBASE+30h ;DMA Status Register
b2m DE1,7 ;DMA enable ch 1,0
b2m DE0,6 ;
- b2m DWE1,5 ;DMA Enable Bit Write Enable 1,0
- b2m DWE0,4 ;
+ b2m NDWE1,5 ;DMA Enable Bit Write Enable 1,0
+ b2m NDWE0,4 ;
b2m DIE1,3 ;DMA Interrupt Enable 1,0
b2m DIE0,2 ;
b2m DME,0 ;DMA Master enable
@@ -188,4 +195,3 @@ IV$ASCI0 equ 14 ;ASCI channel 0
IV$ASCI1 equ 16 ;ASCI channel 1 (lowest priority)
.list
-