Compare commits

...

171 Commits

Author SHA1 Message Date
Antonio Niño Díaz
83348100f3 Improve MinGW target of Makefile
It works now with an install of MinGW for both Win32 and Win64. It needs
libpng and zlib.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-17 17:28:07 +01:00
Antonio Niño Díaz
57bf32f35a Point at the documentation from README
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-17 14:49:57 +01:00
Antonio Niño Díaz
0030e0371a Rename object file format description man page
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-17 14:15:46 +01:00
Antonio Niño Díaz
42400ec6a0 Fix links in HTML documentation
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 23:08:33 +01:00
Antonio Niño Díaz
2e793fb7dc Clean wwwman target of Makefile
The substitution of OpenBSD by General is not portable.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 22:52:10 +01:00
Antonio Niño Díaz
ac69e9863e Fix documentation in HTML format
For some reason, `No` looks weird in the HTML version of the docs.

Some other random fixes.

Tables in src/asm/rgbasm.5 are still broken in the HTML docs.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 22:50:54 +01:00
Antonio Niño Díaz
59c065cf31 Merge pull request #165 from AntonioND/an/rgbasm-manual
Add documentation of rgbds to man pages and cleanup code

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 20:13:49 +01:00
Antonio Niño Díaz
729683fb1f Remove RPN_RANGECHECK
Leftover code from ASMotor.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 19:55:00 +01:00
Antonio Niño Díaz
ed6e4c4769 Clean object file format code and documentation
Remove unused code.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 19:54:58 +01:00
Antonio Niño Díaz
d92c284b85 Add documentation about the object file format
Copied from the HTML documentation and updated.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 19:54:55 +01:00
Antonio Niño Díaz
26af7fcffe Add complete documentation of rgbds to man pages
Copied from the old html documentation and fixed where it was needed.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-16 19:54:50 +01:00
Antonio Niño Díaz
f7f697c267 Fix parsing of first line of included linkerscripts
When including a linkerscript from a parent one, the lexer didn't
include a newline character because the INCLUDE command was handled
before reaching the newline. This behaviour is needed to parse the last
line of a linkerscript correctly (it doesn't have a newline character).

However, this meant that when the included file was being parsed, the
first line was considered a continuation of the last line of the parent
script (the INCLUDE command), which means that the first line of an
included linkerscript could only contain a comment (or nothing at all).

This patch adds a newline character to the buffer used by the lexer so
that the parser will receive a newline and it will handle the first line
of the included file as expected.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-14 17:07:01 +01:00
Antonio Niño Díaz
554b5292de Rename ISO 8601 timestamp defines
The previous names were ridiculously long.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-12 22:19:53 +01:00
Antonio Niño Díaz
a7393d7e45 Merge pull request #163 from AntonioND/an/iso-8601
Add equates with ISO 8601 date and time

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 23:34:12 +01:00
Antonio Niño Díaz
fe9e4f0583 Merge pull request #169 from AntonioND/an/travis-test
Add Travis CI configuration file

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 22:59:10 +01:00
Antonio Niño Díaz
362aea22bd Fix conflict in yacc
`LD HL,n16` and `LD SP,n16` are handled in a different rule as
`LD r16,n16`, but they are also part of that rule.

This patch converts the `LD r16,n16` rule into two rules, one for doing
`LD BC,n16` and other one for `LD DE,n16`.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 22:57:05 +01:00
Antonio Niño Díaz
9bc6083e49 Add Travis CI configuration file
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 22:10:26 +01:00
Antonio Niño Díaz
2b5ad9dc38 Make test scripts return error code
Make them executable.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 22:10:10 +01:00
Antonio Niño Díaz
5679c7066b Restore behaviour of option -w and add option -d
rgblink option -w has been restored to its previous behaviour: make WRAM
a continous section instead of spliting it into WRAM0 and WRAMX.

To enable DMG mode, option -d has to be used instead. This option
automatically enables -w.

Update tests.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 20:03:52 +01:00
Antonio Niño Díaz
4395ed893a Merge pull request #168 from Ben10do/fix-implicit-yyparse
Fix implicit declaration of yyparse()

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-10 19:51:28 +01:00
Ben10do
0d80f60fcc Fix implicit declaration of yyparse()
This was causing compilation errors, as yyparse() hadn’t been defined in lexer.l.
2017-04-10 10:44:31 +01:00
Antonio Niño Díaz
7097b9885e Fix clean target of the Makefile
Two html documentation files weren't cleaned as expected.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 22:06:49 +01:00
Antonio Niño Díaz
f2c207cb44 Remove EX instruction
This is leftover code from ASMotor.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 21:51:30 +01:00
Antonio Niño Díaz
be50f2d302 Remove unused patch enum element
If the next release is going to break compatibility with older object
file formats it doesn't make sense to keep this.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 21:25:20 +01:00
Antonio Niño Díaz
fa767f3228 Merge pull request #161 from AntonioND/an/linkerscript-include
Add support for including files in linkerscript

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 17:19:13 +01:00
Antonio Niño Díaz
5cfa15f963 Add equates with ISO 8601 date and time
Added `__TIMESTAMP_ISO_8601_LOCAL__` and `__TIMESTAMP_ISO_8601_UTC__`,
with the correct ISO 8601 representation of time and date from years to
seconds (including local timezone in the local time string).

Also, if the current time cannot be obtained from the OS, it will output
a warning and the time strings will be filled with '?' instead of
numbers and characters.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 16:49:34 +01:00
Antonio Niño Díaz
23584a584f Fix __FILE__, __TIME__ and __DATE__
If they don't have quotes when passed to sym_AddString() they can't be
used at all by the assembler. I suppose nobody actually used them, they
seem to have been broken forever.

Added a comment to the function to say how to use it correctly for
strings.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-09 15:40:06 +01:00
Antonio Niño Díaz
53fa608161 Deprecate IMPORT keyword
IMPORT is simply useless, any symbol that isn't found in the current
file is automatically flagged as imported symbol.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:47:10 +01:00
Antonio Niño Díaz
1154a173cc Merge pull request #153 from AntonioND/an/opcode-ref
Add GBZ80 opcode reference man page

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:43:21 +01:00
Antonio Niño Díaz
ca3e55cc45 Update remaining dates in man pages
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:18:59 +01:00
Antonio Niño Díaz
206275df57 Add support for including files in linkerscript
Files can now be included with the following syntax:

    INCLUDE "path.link"

The maximum include depth is 5.

Fixed linkerscript parser and lexer error messages so that they are more
informative (show file and line of the error).

Man page updated.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:10:24 +01:00
Antonio Niño Díaz
3d8396b86f Remove progname variable
The error message shouldn't specify the name of the binary, that's
supposed to be known by the caller.

Update test reference outputs.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:10:14 +01:00
Antonio Niño Díaz
77546e9c58 Make WARN output a warning instead of an error
This is the expected behaviour.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:09:02 +01:00
Antonio Niño Díaz
540f8597d4 Update history in man pages
Fix format in LICENSE file.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:08:57 +01:00
Antonio Niño Díaz
e3109af2f8 Rename OPT_CONTWRAM to OPT_DMG_MODE
Now, it will also make sure that VRAM bank 1 isn't used.

Man page updated.

Tests added.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 18:08:51 +01:00
Antonio Niño Díaz
cf99f33dd6 Fix reference list of hex codes
Fix tabulations.

Add missing byte to STOP.

Add comments about where HL+ and HL- are used.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 17:43:06 +01:00
Antonio Niño Díaz
0b6438ae0a Add GBZ80 opcode reference man page
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-08 17:38:04 +01:00
AntonioND
928b347dfc Merge pull request #158 from Ben10do/remove-legacy-object-files
Remove support for legacy object files
2017-04-08 13:30:15 +01:00
AntonioND
ce21cfad4e Merge pull request #160 from AntonioND/an/high-low
Implement HIGH() and LOW() operators
2017-04-08 13:30:10 +01:00
Antonio Niño Díaz
dda3a066be Add test for HIGH() and LOW()
It compares the results of the operators with the expected result if
doing the same thing manually.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-06 22:40:38 +01:00
Antonio Niño Díaz
a6a47ff66d Implement HIGH() and LOW() operators
They work with the 16-bit registers BC, DE and HL, returning the
corresponding 8-bit register. HIGH() works with AF as well, returning A.

They also work with any kind of constant or symbol, generating a RPN
patch in the object file if the value is not defined at assembly time.

They work with macro arguments as well.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-06 22:40:34 +01:00
Daniel Hauck
bfcef01211 Add DESTDIR to Makefile
Allow separate definition of binary and manpage directory.

Document Makefile changes in README.
2017-04-06 20:47:14 +01:00
AntonioND
07861b3b4a Output warning with deprecated section types
Code that uses keywords HOME, DATA, CODE or BSS generates warnings.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-06 20:30:21 +01:00
AntonioND
24439003f3 Remove newlines from warning message strings
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-06 20:30:21 +01:00
AntonioND
3c43cc14d9 Remove unused code
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-06 20:30:21 +01:00
AntonioND
52081f32f0 Add flag -w to rgbasm to disable warnings
A lot of warnings are being added (and more will come) so it makes sense
to be able to disable them in legacy source that generates warnings but
is otherwise correct.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-06 20:30:21 +01:00
Ben10do
6e5a28226b Include object file version in error message
When an unsupported object file version is encountered, the version number is now printed in the displayed error message.
2017-04-06 08:02:28 +01:00
Antonio Niño Díaz
2783a36b17 Add missing license header to man page
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2017-04-06 00:00:56 +01:00
Anthony J. Bentley
2c3afc833f Add license information to manpages. 2017-04-05 23:39:42 +01:00
AntonioND
0f3b708dce Merge pull request #157 from AntonioND/an/error-undef-diff
Output error message if diff of labels not defined
2017-04-05 23:08:37 +01:00
AntonioND
7eb9101d43 Update README and LICENSE files
Add history of RGBDS and original license.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-05 01:24:36 +01:00
Ben10do
032e698f46 Update the object file documentation
Updates the object file documentation in mylink.h to match the newest object file format.
2017-04-05 01:10:00 +01:00
Ben10do
63103c050d Remove support for old object files
Remove support for RGB0 and RGB1-2 object files, reducing the amount of duplicate work that needs doing when maintaining the linker in the future.

A new error message has also been implemented if an unsupported object file version has been encounted, which informs the user that they should reassemble.
2017-04-05 01:09:51 +01:00
AntonioND
7e107ab41a Update references of linker tests
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-04 23:13:42 +01:00
AntonioND
a009a372c5 Remove noyywrap from src/link/lexer.l
Workaround for flex version 2.6.3.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-04 23:13:36 +01:00
AntonioND
5f299bfe6c Fix whitespace
Replace spaces by tabs for consistency. The rest of the codebase uses
tabs, so the linkerscript parser has to change.

Removed trailing tabs in all codebase.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-04 22:14:46 +01:00
AntonioND
07cc4fb8fd Remove warnings when calculating banks
getsymbank() is used for more things than just when the code explicitly
has a BANK() operator, which causes a lot of noise when building code
that has more than one object file and places variables on HRAM or OAM.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-04 21:56:22 +01:00
AntonioND
720ae59af8 Merge pull request #154 from AntonioND/an/tiny-contwram
Make the options -t and -w of rgblink consistent
2017-04-04 21:42:20 +01:00
AntonioND
e63e801e9c Output error message if diff of labels not defined
When calculating the difference of addresses between two labels, for it
to be defined, either:

- Both of them must have their absolute address defined.
- They belong to the same section, so their relative addresses are
  compatible.

This patch adds a check to make sure that any other case is detected so
that the programmer can correct the code.

This applies to rgbasm. The difference of labels can be used, for
example, as argument of DS. The linker can't resize sections, which
means that the final value must be defined when creating the object
file.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-04 21:40:59 +01:00
AntonioND
2abdc9c59d Add whitespace to error and warning messages
Test reference output updated.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 23:46:19 +01:00
AntonioND
be200593d6 Fix typo in README
This is the correct name since 2016.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 23:43:32 +01:00
AntonioND
43228f16f0 Improve README
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 22:17:20 +01:00
AntonioND
f14b061ea7 Add script to update references of rgbasm tests
Update test references.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:36:42 +01:00
AntonioND
f431b384a2 Add tests for rgblink options -t and -w
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:29:22 +01:00
AntonioND
7e3720b627 Make options -t and -w consistent
Instead of converting from ROMX to ROM0 with -t and preventing the use
of WRAMX at all with -w, make each option prohibit the type of section
they affect.

This is a good idea because it can prevent a developer from making
mistakes when switching from using the options to not using them.
Generally, a change from using one single bank to multiple banks is
something that will take a lot of effort, and forgetting sections in
ROM0 or WRAM0 will only make the free space of those areas to be
reduced (and maybe prevent compilation), but it won't cause any problems
because of a forgotten bank swap in the code.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:22:16 +01:00
AntonioND
e9ed81074b Rename OPT_SMALL to OPT_TINY
This way it is easier to identify the flag passed to the binary (-t).

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:22:16 +01:00
AntonioND
e16af28676 Automate and improve rgblink test
Check all sections when testing BANK().

Add scripts to verify the tests and update the reference if needed.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:19:39 +01:00
AntonioND
25be5c6561 Improve error and warning output
Improve error messages generated by `errx()`, `warnx()` and similar.

Set `progname` to a static string with the name of the program so that
the path of the binary isn't included in error messages.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:16:43 +01:00
AntonioND
e4b4e427f1 Return bank 0 for labels in HRAM
Instead of returning the internal representation of the linker, return
0 when using BANK() on a label in HRAM.

Also, generate a warning when calculating the bank of labels in OAM
and HRAM, as there is no valid reason for doing it, so it's likely a
programming mistake.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-03 21:15:14 +01:00
AntonioND
2138bb46fd Fix generation of html man page in Makefile
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 21:08:53 +01:00
AntonioND
ec5eb4f9ff Merge pull request #152 from Ben10do/update-readme-for-mac
Update the README’s Mac-specific instructions
2017-04-02 18:08:47 +01:00
Ben10do
b31632b51d Update the README’s Mac-specific instructions
- Rename the “Installing RGBDS (UNIX)” section to “Building RGBDS”, as that’s what we’re doing, regardless of platform.
- Update references of Mac OS X to macOS.
- State that only libpng and pkg-config need to be downloaded with Homebrew; the others are pre-installed along with Xcode.
- State that RGBDS itself is available through Homebrew.
2017-04-02 17:57:51 +01:00
AntonioND
e50e3e5a23 Remove trailing whitespace
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 17:46:14 +01:00
AntonioND
f63339472e Update reference output of tests
Due to recent changes, lots of tests generated a slightly different
error output.

- bank-noexist : This test doesn't generate any error output now as
  unknown labels are left for the linker to resolve.

- null-in-macro : This test used to crash. Now, the parser verifies that
  a MACRO ends in ENDM, generating an error message if not.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 17:18:08 +01:00
AntonioND
43fd1ee024 Fix some signed/unsigned comparison warnings
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 17:08:12 +01:00
AntonioND
d61a0a8a8f Cleanup Makefile
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 17:07:40 +01:00
AntonioND
ec44b554e8 Merge pull request #150 from Ben10do/deprecation-positions
Add a warning() function, similiar to other error handlers
2017-04-02 17:03:03 +01:00
AntonioND
01a710a47d Remove Zero Page linker patch RPN_PCEZP
This patch isn't used because it's meant to be an optimization for
labels in the memory region 0x2000-0x20FF. That memory region doesn't
have anything special on the Game Boy, and there are no instructions
optimized to read or write from there, so it was probably meant for
another hardware that was supported by ASMotor in the past.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 16:19:45 +01:00
Ben10do
ff2ba7290c Add a warning() function, similiar to yyerror()
This function produces a similar output to the other error handlers, including printing to stderr, and including a stack trace. However, ‘warning’ is displayed instead of ‘ERROR’, and the compilation does not fail.

This function is now used for the deprecation warnings, ensuring that these errors can be found.
2017-04-02 13:18:29 +01:00
AntonioND
53842cd07d Create man5 folder when installing
`make install` would blindly try to copy `rgblink.5` even if the
destination folder didn't exist.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 00:40:35 +01:00
AntonioND
85ff75d2d3 Merge pull request #146 from AntonioND/an/same-name
Prohibit sections from having the same name
2017-04-02 00:36:28 +01:00
AntonioND
adef2e18cc Fix bank assignments from linkerscript
Even though the bank number was read from the linkerscript and the
linker verified that each section could be mapped in the final rom, the
bank number was never actually set by the linkerscript parser.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-02 00:22:37 +01:00
AntonioND
5ba8405dfa Prohibit sections from having the same name
To make the behaviour of the linkerscript consistent, every section read
from an object file must have an unique name. This is needed as the
linkerscript uses the name of sections to place them and it expects
every section to have a different name.

This doesn't break compatibility with the old behaviour that allowed to
continue sections if they had the same name, bank number and starting
address. That's still allowed because `rgbasm` outputs a single section
if this functionality is used, it is transparent to `rgblink`.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-04-01 15:33:17 +01:00
AntonioND
f0d4750ebc Fix rgblink.5 man page installation path
The man page rgblink.5 was installed in the `man1` folder instead of
`man5` as expected.
2017-04-01 15:06:26 +01:00
AntonioND
eed098ac8e Merge pull request #140 from AntonioND/an/linkerscript
Implement linkerscript
2017-04-01 10:33:49 +01:00
AntonioND
64dbcc0912 Update README.md
Inform about the actual dependencies.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-28 22:19:50 +01:00
AntonioND
5947ca10dc Document linkerscript format in manpage
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-28 22:19:50 +01:00
AntonioND
d1ed4fbded Use linkerscript parser in rgblink
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-28 22:19:50 +01:00
AntonioND
22d4a10cb6 Implement linkerscript parser
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-28 22:19:45 +01:00
AntonioND
dfb99618f5 Document missing build options
Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-28 19:37:18 +01:00
AntonioND
6b21e02c95 Merge pull request #143 from Sanqui/parametrize-makefile
Parametrize install arguments in Makefile
2017-03-28 12:49:23 +01:00
Sanqui
011c2c953b Parametrize install arguments in Makefile 2017-03-28 13:22:33 +02:00
AntonioND
8eb1a42e31 Merge pull request #141 from AntonioND/an/deprecate-jp-hl
Declare some opcodes obsolete
2017-03-24 23:23:43 +00:00
AntonioND
c51aac0c20 Declare some opcodes obsolete
They are still working, they just output a warning.

`jp [hl]` is confusing as it may be thought that the CPU reads the value
pointed by hl and jumps to it.

`ldi a,hl` and `ldd a,hl` are also confusing as they load from the
address pointed by `hl`, the correct mnemonic should say `[hl]`.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-24 23:22:30 +00:00
AntonioND
6feaba2343 Document -w option of rgblink
This option hadn't been added to the manpage.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-23 22:12:06 +00:00
AntonioND
0867476bde Allow ',' to be escaped in string literals
It should only be needed for macro arguments, added to string parsing
function as well for consistency.
2017-03-19 00:05:50 +00:00
AntonioND
fa962b9470 Merge pull request #139 from chastai/escape-cb
Allow { and } to be escaped in string literals
2017-03-18 23:54:59 +00:00
Christophe Staïesse
b8642bf3af Allow { and } to be escaped in string literals
As stated in the documentation but that was not actually implemented.
2017-03-18 16:23:41 +01:00
AntonioND
317b206fa8 Improve map file output
Print the name of each section along with the size, base and end
addresses. If a section is empty, don't print the end address, as it
can overflow if the base address is 0.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
2017-03-15 23:52:56 +00:00
AntonioND
469e3e7c86 Merge branch 'contiguous-wram' of git://github.com/TwitchPlaysPokemon/rgbds into TwitchPlaysPokemon-contiguous-wram 2017-03-15 21:00:06 +00:00
AntonioND
9193710ff9 Merge pull request #131 from Sanqui/overlay
Add overlay to rgblink
2017-03-15 20:42:32 +00:00
Sanqui
263c9222ab Require all sections to be fixed when using overlay 2017-03-13 17:08:27 +01:00
AntonioND
947d767c64 Merge pull request #135 from Ben10do/improve-assign-error-messages
Improve assignment error messages
2017-03-12 17:06:54 +00:00
AntonioND
82cf3eb48f Merge pull request #134 from Ben10do/oam-sections
Add support for OAM Sections
2017-03-11 12:18:40 +00:00
Ben10do
a75c15ec46 Improve assignment error messages
Make the error messages in assign.c more descriptive, including the name of the section that caused the error, and its alignment.
2017-03-10 23:21:59 +00:00
Ben10do
3dcfe2b9f6 Add support for OAM Sections
Allows sections (and labels within) to be defined that correspond to the Game Boy’s Object Attributes Memory.
2017-03-10 22:18:14 +00:00
Ben10do
523b7538f0 Replace magic numbers with BANK_COUNT_* constants
Previously, some instances of the number of banks for each section remained hardcoded. These have been replaced with BANK_COUNT_* constants.

As a side-effect, this could fix a theoretical bug when using BANK(label) when the label is in a high SRAM bank (≥ 4).
2017-03-10 19:24:54 +00:00
Sanqui
bc2f885d29 Also require ROM0 sections to be fixed when using overlay 2017-03-02 23:02:56 +01:00
Sanqui
bd00b9ab59 Merge branch 'master' of github.com:rednex/rgbds into overlay 2017-03-02 22:46:19 +01:00
AntonioND
4f86a12539 Merge pull request #125 from Ben10do/section-alignment
Implement byte alignment for data
2017-03-02 09:17:46 +00:00
Ben
7e2457c9be Re-allow alignment of 0 bits 2017-03-02 08:29:28 +00:00
Ben10do
7993d3455d Update alignment error handling
Ensure (in rgbasm) that the alignment value is between 1-16. Replaces the previous “alignment must not be negative” check.
2017-03-02 08:02:05 +00:00
Sanqui
c9daf80f11 Merge github.com:rednex/rgbds into overlay 2017-02-28 18:58:58 +01:00
Sanqui
5a7faa7dff Add overlay to rgblink manpage 2017-02-28 18:48:09 +01:00
AntonioND
7b8d4de35c Merge pull request #16 from yenatch/eval-rpn-bank
rgbasm: Evaluate BANK() arguments to verify they exist.
2017-02-27 21:21:45 +00:00
AntonioND
c7fe281c86 Merge pull request #114 from Ben10do/fix-asm-tests
Fix issues in rgbasm raised by the tests
2017-02-27 21:09:04 +00:00
AntonioND
fa8f25a4de Merge pull request #123 from Ben10do/deduplicate-e-doc
Remove duplicate documentation of -E
2017-02-27 20:35:13 +00:00
AntonioND
7c2cae7a32 Merge pull request #127 from rogersachan/patch-1
Convert README to markdown
2017-02-26 22:28:10 +00:00
AntonioND
92b81b1d5a Merge pull request #79 from yenatch/longer-charmap
Increase the length of charmaps.
2017-02-26 22:04:26 +00:00
AntonioND
42b5be24b4 Merge pull request #120 from TwitchPlaysPokemon/extra-sram
16-bank SRAM
2017-02-26 21:53:57 +00:00
AntonioND
14fea5f659 Merge pull request #119 from Ben10do/add-end-checks
Verify that IFs, REPTs and MACROs are terminated
2017-02-26 21:49:22 +00:00
AntonioND
1e16a0ff85 Merge pull request #121 from TwitchPlaysPokemon/master
Fix WRAM0 symbols returning bank 512 to BANK() expression in linker
2017-02-26 21:45:53 +00:00
Roger
7adf1dd502 Convert README to markdown 2017-02-25 16:15:05 -05:00
Anthony J. Bentley
0588e42520 Link to HTML documentation from the manpage. 2017-02-23 21:09:32 -07:00
Anthony J. Bentley
2eb748278b Move HTML docs to a different repo. 2017-02-23 21:07:11 -07:00
Ben10do
1ab93a194e Implement ALIGN keyword in rgbasm
The ALIGN keyword specifies the number of bits that should be zero at the start of a section. It works in a simliar fashion to BANK.
2017-02-23 15:00:57 +00:00
Ben10do
1b05c43b97 Implement byte alignment in section assingment
Yay, more refactoring of the section assignment… This version of the linker will allocate sections by their alignment, and then by their size (largest first, in both cases).

In future, this may be improved by using dense packing (as suggested by #83).
2017-02-19 22:43:45 +00:00
Ben10do
e4cbf773f6 Add alignment of sections to objects
Aligned sections can now be created with out_NewAlignedSection(). This information is stored in created object files, and read by the linker.

The names of each section are also included in the object file, enabling potential improvements to error messages in the future.
2017-02-19 22:35:32 +00:00
Ben10do
b07c04cd74 Implement a malloc-based readasciiz()
Instead of reading into a pre-sized buffer, this function now uses malloc to create a buffer, and resizes it if necessary.

This reduces the risk of memory issues if a long string (< 255 chars) was encountered.
2017-02-19 22:20:21 +00:00
Ben10do
9be7c4c849 Remove duplicate documentation of -E
Remove Sanqui’s documentation of the -E argument to rgbasm, in favour of bentley’s better-worded one.
2017-02-07 11:05:35 +00:00
scnorton
6d1c60b0a6 Contiguous WRAM 2017-02-06 16:31:57 -05:00
PikalaxALT
c485ad94f2 Fix WRAM0 symbols returning bank 512 to BANK() expression in linker 2017-02-06 08:38:07 -05:00
PikalaxALT
998cfe1bdd 16-bank SRAM 2017-02-06 08:27:32 -05:00
Anthony J. Bentley
5ee058f217 Merge branch 'linker-refactor-assign' of https://github.com/Ben10do/rgbds 2017-02-05 23:24:13 -07:00
Ben10do
38372c59ed Verify that IFs, REPTs and MACROs are terminated
Ensure that IF constructs, REPT blocks, and MACRO defintions are terminated with ENDC, ENDR, or ENDM respectively. If they are not, print an error and stop assembly.

As well as aiding a forgetful programmer, this reduces the risk of memory problems if the file ends less than four bytes after the block starts.
2017-02-02 16:27:53 +00:00
Ben10do
420ea638a7 Refactor section assignment in linker
Deduplicates and generalises a lot of code in assign.c:

- Replace area_AllocAbs*AnyBank() with area_AllocAbsAnyBank() function
that accepts a section type parameter
- Replace area_Alloc*AnyBank() with area_AllocAnyBank()
- Replace FindLargest*() with FindLargestSection()
- Replace Assign*Sections() with AssignBankedSections()
- Add VerifyAndSetBank(), which enables bank checks (and addition with
BANK_*) to be centralised
- Refactor the initialisation of AssignSections(), removing some magic
numbers and only setting MaxAvail[i] once
- Overhaul the duplicated cases throughout AssignSections()
2017-01-27 08:56:36 +00:00
Ben10do
951c9b66f4 Don't segfault on null bytes in REPTs and MACROs
Previously, the copyrept() and copymacro() functions would halt their
first loop (in which they determine the length of the block)
prematurely,  causing an underflow when setting len, eventually causing
memory issues.

Whilst this doesn’t solve the len underflow entirely (e.g. if the file
ends immediately without an ENDR/ENDM), it should help with this exact
scenario of null bytes (as #50).
2017-01-26 22:01:03 +00:00
Ben10do
0a66e14307 Fix division by zero crashes in instructions
Previously, rgbasm could crash with a floating point exception if an
instruction includes a division or modulo by 0. Fixes #49.
2017-01-26 21:32:06 +00:00
Ben10do
b40c567aee Add ldi a, [hl] and ldd a, [hl] instructions
These are equivalent to ld a, [hl+] and ld a, [hl-] respectively.
2017-01-26 16:55:00 +00:00
Anthony J. Bentley
547abfefc1 Merge branch 'fatal-error-noreturn' of https://github.com/Ben10do/rgbds 2017-01-25 00:47:25 -07:00
Ben10do
06f0472f81 Emit a single error when using BANK incorrectly
Previously, if BANK is used when defining a section that’s not ROMX,
WRMAX, SRAM or VRAM, a second error message would appear, e.g. “(null)
bank value $1 out of range $5d to $0”.

This would appear due to the usage of uninitialised variables. This
change ensures that the uninitialised variables are not accessed when
using an invalid section.

This also silences compiler warnings about usage of uninitialised
variables.
2017-01-24 11:50:18 +00:00
Ben10do
defd4f589e Add noreturn attribute to fatalerror()
Should silence compiler warnings that expect fatalerror() to return.
2017-01-24 11:38:26 +00:00
Anthony J. Bentley
dc4a98048d Simplify string copy by using strlcpy(). 2017-01-24 01:26:55 -07:00
Anthony J. Bentley
efaa6d9ff7 Add .gitignore. 2017-01-24 01:19:16 -07:00
Anthony J. Bentley
ab19dab899 Merge branch 'include-cli' of https://github.com/AntonioND/rgbds 2017-01-24 01:18:28 -07:00
Ben10do
e86a70d2cb Fix the name of the GNUmakefile
GNU make actually looks for ‘GNUmakefile’, not ‘GNUMakefile’.

Consequently, GNU make would erroneously attempt to use the standard
makefile, instead of the GNU-specific one. This would cause an error
when attempting to import png.h, due to PNGFLAGS not being correctly
set.
2017-01-23 23:46:44 +00:00
AntonioND
a91187d8dc Increase number of include paths through CLI
Increase number of include paths that can be passed through the
command line interface. The previous number, 16, is only good enough
for small projects. 128 is still an arbitrary number, but it is harder
to reach.
2017-01-22 23:08:10 +00:00
AntonioND
0b5e074591 Output error messages for command line includes
The code that adds an include path to the array of paths doesn't check
the lenght of the path (which can cause overflows because of strcpy).

It doesn't check if the max number of paths has been reached, either.

This patch adds error messages for such cases, giving the user more
information than before and crashing the assembly instead of
continuing and failing when it can't find a file to include.
2017-01-22 23:04:50 +00:00
Anthony J. Bentley
f8531ed410 Add a thin wrapper makefile for GNU Make.
GNU Make 3.x doesn't support the "!=" syntax for shell assignment,
although 4.x does, BSD Makes do, and it has been submitted to POSIX
for possible inclusion in the standard. Unfortunately, GNU Make 3.x
is still in common use, so provide an alternative makefile (GNU Make
reads "GNUmakefile" instead of "Makefile" by default) that sets the
variables and then reuses the rest of the default Makefile.
2016-12-16 23:23:37 -07:00
Francisco Requena
0a8401741d Fixes rgbgfx linkage issues with old libpng (pre 1.4.2) 2016-12-17 04:04:45 +01:00
Anthony J. Bentley
a079a69b7c Add a note about installing libpng. 2016-10-22 14:13:19 -06:00
Anthony J. Bentley
d86cb41972 Rename png.h to makepng.h, to avoid conflicts with libpng's png.h. 2016-10-22 14:03:14 -06:00
yenatch
95cd960b3b Fix the order of flags when including libpng.
This apparently does matter.
2016-10-11 21:54:18 -06:00
Anthony J. Bentley
bed43d2530 Document rgbasm -E. 2016-09-05 02:46:59 -06:00
Anthony J. Bentley
c02b04f7d2 Merge branch 'export-all-2' of https://github.com/Sanqui/rgbds 2016-09-05 02:43:23 -06:00
Anthony J. Bentley
2339f0fbae Merge branch 'an/fix-gfx-prefix' of https://github.com/AntonioND/rgbds 2016-09-05 02:35:24 -06:00
Anthony J. Bentley
6e0aca47d4 Declare string uppercase/lowercase functions unconditionally.
Avoid naming them str*(), because such names are reserved by ISO C.
2016-09-05 01:41:39 -06:00
Anthony J. Bentley
a8c603a7e8 Removed the wrong pkg-config. 2016-09-05 01:41:39 -06:00
Anthony J. Bentley
97a31c8fc0 Remove duplicate PKG_CONFIG. 2016-09-05 01:34:17 -06:00
Anthony J. Bentley
c3c31138dd Add rgbgfx. 2016-09-05 01:29:45 -06:00
AntonioND
fbb825af3b Fix GB graphics prefix output
The output of using the prefix '`' was inverted: The MSB was placed
before the LSB. Now, the LSB are placed first, allowing a direct copy
to VRAM.
2016-07-01 19:54:48 +01:00
Sanqui
280ca83acd Fix opening nonexistent overlay files 2016-03-28 20:47:47 +02:00
Sanqui
2e9c68f8c3 Add overlay file option to rgblink (-O)
This option takes a file and places fixed sections on top of it.
Should prove useful for patches and partial disassemblies.
2016-03-28 01:02:05 +02:00
Anthony J. Bentley
330a39596c Instead of blindly trusting the first byte, decode UTF-8 safely. 2016-01-28 23:16:42 -07:00
Anthony J. Bentley
e241137508 KNF. 2016-01-28 23:05:25 -07:00
Sanqui
deb44eaeef Merge branch 'master' into HEAD 2015-10-13 22:37:25 +02:00
Sanqui
338c176b37 Add -E option to rgbds, allows exporting all labels by default 2015-10-13 22:35:02 +02:00
yenatch
1a15ee5363 Increase the length of charmaps. 2015-10-13 08:46:29 -07:00
Anthony J. Bentley
2ea2e47231 Avoid a pointless strcpy(). 2015-10-05 23:58:00 -06:00
Anthony J. Bentley
31294d6d9d rgbasm: refactor bank range checking, and bump the SRAM limit.
This doesn’t affect rgblink, which still needs work.
2015-10-05 17:14:24 -06:00
yenatch
b2d523acde rgbasm: Evaluate BANK() arguments to verify they exist.
Symbols are created when using a label in the wild, even if they aren't defined. Solely using a symbol as an argument to BANK() skips this, so the symbol is never created.

This evaluates the argument instead of trying to find a symbol. This way, symbols that don't exist are created when passed into BANK().
2014-02-01 21:14:56 -05:00
128 changed files with 6900 additions and 3858 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
rgbasm
rgblink
rgbfix
rgbgfx
*.o
*.exe
*.html

13
.travis-deps.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
if [ $TRAVIS_OS_NAME = "osx" ]; then
brew update
brew install libpng pkg-config
else # linux
sudo apt-get -qq update
sudo apt-get install -y -q bison flex libpng-dev pkg-config
fi
echo "Dependencies:"
yacc --version
flex --version

16
.travis.yml Normal file
View File

@@ -0,0 +1,16 @@
language: c
sudo: required
install:
- ./.travis-deps.sh
os:
- linux
- osx
compiler:
- clang
- gcc
script:
- make
- sudo make install
after_success:
- pushd test/asm/ && ./test.sh && popd
- pushd test/link/ && ./test.sh && popd

6
GNUmakefile Normal file
View File

@@ -0,0 +1,6 @@
# GNU Make 3.x doesn't support the "!=" shell syntax, so here's an alternative
PKG_CONFIG = pkg-config
PNGFLAGS = $(shell ${PKG_CONFIG} --cflags libpng)
include Makefile

28
LICENSE
View File

@@ -1,28 +0,0 @@
rgbasm and rgblink are derived from Justin Lloyd's RGBDS, which is
released under the following license:
DO WHATEVER PUBLIC LICENSE*
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You can do whatever you want to with the work.
1. You cannot stop anybody from doing whatever they want to with the work.
2. You cannot revoke anybody elses DO WHATEVER PUBLIC LICENSE in the work.
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the DO WHATEVER PUBLIC LICENSE
Software originally created by Justin Lloyd @ http://otakunozoku.com/
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
under the ISC license; see the source file for the text of the license.
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
and is released under the MIT license.
extern/reallocarray.c is derived from the OpenBSD Project,
http://www.openbsd.org, and is released under the ISC license.
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
and is released under the BSD license.

74
LICENSE.md Normal file
View File

@@ -0,0 +1,74 @@
# Original code
Copyright (C) 1997 Carsten Sorensen <surfsmurf@matilde.demon.co.uk>
The ASMotor package (xAsm, xLink, RGBFix, examples and documentation) is
freeware and distributed as is. The author retains his copyright and right to
modify the specifications and operation of the software without notice.
In other words this means I encourage you to...
- use it for whatever purpose even professional work without me charging you a
penny
- copy it to another person (wholly or in part, though I'm sure he'd appreciate
the whole package) in whatever form you find suitable
- mass-distribute the ASMotor package if it is complete (xAsm, xLink, RGBFix and
documentation).
- contact me if you have any problems
This also means you can't...
- blame me for loss of profit, data, sleep, food or other nasty things through
the use or distribution of ASMotor. If you choose to use ASMotor you do so at
your own risk.
- expect me to be able to help you should you have a problem related or not to
ASMotor.
# Otaku no Zoku's modifications
Copyright (C) 1999 Justin Lloyd <jlloyd@imf.la> (?)
```
DO WHATEVER PUBLIC LICENSE*
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You can do whatever you want to with the work.
1. You cannot stop anybody from doing whatever they want to with the work.
2. You cannot revoke anybody elses DO WHATEVER PUBLIC LICENSE in the work.
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the DO WHATEVER PUBLIC LICENSE
Software originally created by Justin Lloyd @ http://otakunozoku.com/
```
# rgbds-linux
Copyright (C) 2009 Vegard Nossum <vegard.nossum@gmail.com>
# Current
rgbasm and rgblink are derived from Justin Lloyd's RGBDS.
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
under the ISC license; see the source file for the text of the license.
rgbgfx was written by stag019, and is released under the ISC license.
Some files of rgblink were written by Antonio Niño Díaz, and they are relased
under the ISC license. The affected files have the appropriate license in the
header of the file.
The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
released under the MIT license. The remainder of charmap.c was written by
stag019, and is released under the ISC license.
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
and is released under the MIT license.
extern/reallocarray.c is derived from the OpenBSD Project,
http://www.openbsd.org, and is released under the ISC license.
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
and is released under the BSD license.

126
Makefile
View File

@@ -1,14 +1,23 @@
.POSIX:
WARNFLAGS = -Wall -Werror=implicit
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
PKG_CONFIG = pkg-config
WARNFLAGS = -Wall -Werror
PNGFLAGS != ${PKG_CONFIG} --cflags libpng
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
-std=c99 -D_POSIX_C_SOURCE=200809L
LFLAGS := --nounistd
YACC := yacc
FLEX := flex
RM := rm -rf
# User-defined variables
PREFIX = /usr/local
BINPREFIX = ${PREFIX}/bin
MANPREFIX = ${PREFIX}/man
Q = @
PREFIX = /usr/local
bindir = ${PREFIX}/bin
mandir = ${PREFIX}/man
Q = @
STRIP = -s
BINMODE = 555
MANMODE = 444
rgbasm_obj = \
src/asm/asmy.o \
@@ -29,12 +38,15 @@ rgbasm_obj = \
rgblink_obj = \
src/link/assign.o \
src/link/lexer.o \
src/link/library.o \
src/link/main.o \
src/link/mapfile.o \
src/link/object.o \
src/link/output.o \
src/link/patch.o \
src/link/parser.o \
src/link/script.o \
src/link/symbol.o \
src/extern/err.o
@@ -42,25 +54,39 @@ rgbfix_obj = \
src/fix/main.o \
src/extern/err.o
all: rgbasm rgblink rgbfix
rgbgfx_obj = \
src/gfx/gb.o \
src/gfx/main.o \
src/gfx/makepng.o \
src/extern/err.o
all: rgbasm rgblink rgbfix rgbgfx
clean:
$Qrm -rf rgbds.html
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
$Qrm -rf src/asm/asmy.c src/asm/asmy.h
$Q${RM} rgbds.7.html gbz80.7.html rgbds.5.html
$Q${RM} rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.1.html rgbasm.5.html
$Q${RM} rgblink rgblink.exe ${rgblink_obj} rgblink.1.html rgblink.5.html
$Q${RM} rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.1.html
$Q${RM} rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.1.html
$Q${RM} src/asm/asmy.c src/asm/asmy.h
$Q${RM} src/link/lexer.c src/link/parser.c src/link/parser.h
install: all
$Qmkdir -p ${BINPREFIX}
$Qinstall -s -m 555 rgbasm ${BINPREFIX}/rgbasm
$Qinstall -s -m 555 rgbfix ${BINPREFIX}/rgbfix
$Qinstall -s -m 555 rgblink ${BINPREFIX}/rgblink
$Qmkdir -p ${MANPREFIX}/man1 ${MANPREFIX}/man7
$Qinstall -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7
$Qinstall -m 444 src/asm/rgbasm.1 ${MANPREFIX}/man1/rgbasm.1
$Qinstall -m 444 src/fix/rgbfix.1 ${MANPREFIX}/man1/rgbfix.1
$Qinstall -m 444 src/link/rgblink.1 ${MANPREFIX}/man1/rgblink.1
$Qmkdir -p ${DESTDIR}${bindir}
$Qinstall ${STRIP} -m ${BINMODE} rgbasm ${DESTDIR}${bindir}/rgbasm
$Qinstall ${STRIP} -m ${BINMODE} rgbfix ${DESTDIR}${bindir}/rgbfix
$Qinstall ${STRIP} -m ${BINMODE} rgblink ${DESTDIR}${bindir}/rgblink
$Qinstall ${STRIP} -m ${BINMODE} rgbgfx ${DESTDIR}${bindir}/rgbgfx
$Qmkdir -p ${DESTDIR}${mandir}/man1 ${DESTDIR}${mandir}/man5 ${DESTDIR}${mandir}/man7
$Qinstall -m ${MANMODE} src/rgbds.7 ${DESTDIR}${mandir}/man7/rgbds.7
$Qinstall -m ${MANMODE} src/gbz80.7 ${DESTDIR}${mandir}/man7/gbz80.7
$Qinstall -m ${MANMODE} src/rgbds.5 ${DESTDIR}${mandir}/man7/rgbds.5
$Qinstall -m ${MANMODE} src/asm/rgbasm.1 ${DESTDIR}${mandir}/man1/rgbasm.1
$Qinstall -m ${MANMODE} src/asm/rgbasm.5 ${DESTDIR}${mandir}/man1/rgbasm.5
$Qinstall -m ${MANMODE} src/fix/rgbfix.1 ${DESTDIR}${mandir}/man1/rgbfix.1
$Qinstall -m ${MANMODE} src/link/rgblink.1 ${DESTDIR}${mandir}/man1/rgblink.1
$Qinstall -m ${MANMODE} src/link/rgblink.5 ${DESTDIR}${mandir}/man5/rgblink.5
$Qinstall -m ${MANMODE} src/gfx/rgbgfx.1 ${DESTDIR}${mandir}/man1/rgbgfx.1
rgbasm: ${rgbasm_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
@@ -71,37 +97,61 @@ rgblink: ${rgblink_obj}
rgbfix: ${rgbfix_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
rgbgfx: ${rgbgfx_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbgfx_obj} `${PKG_CONFIG} --libs libpng`
.y.c:
$Q${YACC} -d ${YFLAGS} -o $@ $<
.l.o:
$Q${RM} $*.c
$Q${FLEX} ${LFLAGS} -o $*.c $<
$Q${CC} ${REALCFLAGS} -c -o $@ $*.c
$Q${RM} $*.c
.c.o:
$Q${CC} ${REALCFLAGS} -c -o $@ $<
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
src/asm/asmy.h: src/asm/asmy.c
src/link/lexer.o : src/link/parser.h
src/link/parser.h : src/link/parser.c
# Below is a target for the project maintainer to easily create win32 exes.
# This is not for Windows users!
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
# install instructions instead.
mingw:
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
make WARNFLAGS= CC=gcc CFLAGS="-I/usr/local/mingw32/include \
${CFLAGS}"
$Qmv rgbasm rgbasm.exe
$Qmv rgblink rgblink.exe
$Qmv rgbfix rgbfix.exe
$Q${RM} win32 win64
$Qmkdir win32 win64
$Qenv make clean
$Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
make CC=i686-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
$Qmv rgbasm win32/rgbasm.exe
$Qmv rgblink win32/rgblink.exe
$Qmv rgbfix win32/rgbfix.exe
$Qmv rgbgfx win32/rgbgfx.exe
$Qenv make clean
$Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
make CC=x86_64-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
$Qmv rgbasm win64/rgbasm.exe
$Qmv rgblink win64/rgblink.exe
$Qmv rgbfix win64/rgbfix.exe
$Qmv rgbgfx win64/rgbgfx.exe
$Qenv make clean
# Below is a target for the project maintainer to easily create web manuals.
# It relies on mandoc: http://mdocml.bsd.lv
MANDOC = -Thtml -Ios=General -Oman=/rgbds/manual/%N/ \
-Ostyle=/rgbds/manual/manual.css
MANDOC = -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=manual.css
wwwman:
$Qmandoc ${MANDOC} src/rgbds.7 | sed s/OpenBSD/General/ > rgbds.html
$Qmandoc ${MANDOC} src/asm/rgbasm.1 | sed s/OpenBSD/General/ > \
rgbasm.html
$Qmandoc ${MANDOC} src/fix/rgbfix.1 | sed s/OpenBSD/General/ > \
rgbfix.html
$Qmandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > \
rgblink.html
$Qmandoc ${MANDOC} src/rgbds.7 > rgbds.7.html
$Qmandoc ${MANDOC} src/gbz80.7 > gbz80.7.html
$Qmandoc ${MANDOC} src/rgbds.5 > rgbds.5.html
$Qmandoc ${MANDOC} src/asm/rgbasm.1 > rgbasm.1.html
$Qmandoc ${MANDOC} src/asm/rgbasm.5 > rgbasm.5.html
$Qmandoc ${MANDOC} src/fix/rgbfix.1 > rgbfix.1.html
$Qmandoc ${MANDOC} src/link/rgblink.1 > rgblink.1.html
$Qmandoc ${MANDOC} src/link/rgblink.5 > rgblink.5.html
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > rgbgfx.1.html

58
README
View File

@@ -1,58 +0,0 @@
----------------
RGBDS README
----------------
RGBDS (Rednex Game Boy Development System) is a free assembler/linker package
for the Game Boy and Game Boy Color. It consists of:
- rgbasm (assembler)
- rgblink (linker)
- rgbfix (checksum/header fixer)
rgbds-linux is a fork of the original RGBDS which aims to make the programs
more like other UNIX tools.
Installing RGBDS (UNIX)
=========================
To build the programs on a UNIX or UNIX-like system, just run in your terminal:
make
Then to install the compiled programs and manual pages, run (with appropriate
privileges):
make install
After installation, you can read the manuals with the man(1) command. E.g.,
man 1 rgbasm
Note: the variables described below can affect installation behavior when given
on the make command line. For example, to install rgbds in your home directory
instead of systemwide, run the following:
mkdir -p $HOME/{bin,man/man1,man/man7}
make install PREFIX=$HOME
PREFIX: Location where RGBDS will be installed. Defaults to /usr/local.
BINPREFIX: Location where the RGBDS programs will be installed. Defaults
to ${PREFIX}/bin.
MANPREFIX: Location where the RGBDS man pages will be installed. Defaults
to ${PREFIX}/man.
Q: Whether to quiet the build or not. To make the build more verbose, clear
this variable. Defaults to @.
Installing RGBDS (Windows)
============================
Windows builds are available here: https://github.com/bentley/rgbds/releases
Copy the .exe files to C:\Windows\ or similar.

158
README.md Normal file
View File

@@ -0,0 +1,158 @@
# RGBDS
RGBDS (Rednex Game Boy Development System) is a free assembler/linker package
for the Game Boy and Game Boy Color. It consists of:
- rgbasm (assembler)
- rgblink (linker)
- rgbfix (checksum/header fixer)
- rgbgfx (PNGtoGame Boy graphics converter)
This is a fork of the original RGBDS which aims to make the programs more like
other UNIX tools.
This toolchain is maintained on [GitHub](https://github.com/rednex/rgbds), as
well as its [documentation](https://github.com/rednex/rednex.github.io).
The documentation of this toolchain can be viewed online
[here](https://rednex.github.io/), it is generated from the man pages found in
this repository.
## 1. Installing RGBDS
### 1.1 Windows
Windows builds are available in the releases page on GitHub:
https://github.com/rednex/rgbds/releases
Copy the `.exe` files to `C:\Windows\` or similar.
If you require the latest version in development, it should be possible to
compile RGBDS with MinGW or Cygwin by following the instructions to build it
on UNIX systems.
### 1.2 macOS
You can build RGBDS by following the instructions below. However, if you would
prefer not to build RGBDS yourself, you may also install it using
[Homebrew](http://brew.sh/).
To install the latest release, use:
```sh
brew install rgbds
```
To install RGBDS with all of the current changes in development (as seen on the
`master` branch on GitHub), use:
```sh
brew install rgbds --HEAD
```
### 1.3 Other UNIX-like systems
No official binaries of RGBDS are distributed for these systems, you must follow
the simple instructions below to compile and install it.
## 2. Building RGBDS from source
RGBDS can be built in UNIX-like systems by following the instructions below.
### 2.1 Dependencies
RGBDS requires yacc, flex, libpng and pkg-config to be installed.
On macOS, install the latter two with [Homebrew](http://brew.sh/):
```sh
brew install libpng pkg-config
```
On other Unixes, use the built-in package manager. For example, on Debian or
Ubuntu:
```sh
sudo apt-get install byacc flex pkg-config libpng-dev
```
You can test if libpng and pkg-config are installed by running
`pkg-config --cflags libpng`: if the output is a path, then you're good, and if
it outputs an error then you need to install them via a package manager.
### 2.2 Build process
To build the programs, run in your terminal:
```sh
make
```
Then, to install the compiled programs and manual pages, run (with appropriate
privileges, e.g, with `sudo`):
```sh
make install
```
After installation, you can read the manuals with the `man` command. E.g.,
```sh
man 7 rgbds
```
There are some variables in the Makefile that can be redefined by the user. The
variables described below can affect installation behavior when given on the
make command line. For example, to install RGBDS in your home directory instead
of systemwide, run the following:
```sh
mkdir -p $HOME/{bin,man/man1,man/man7}
make install PREFIX=$HOME
```
To do a verbose build, run:
```sh
make Q=
```
This is the complete list of user-defined variables:
- `PREFIX`: Location where RGBDS will be installed. Defaults to `/usr/local`.
- `bindir`: Location where the binaries will be installed. Defaults to `${PREFIX}/bin`.
- `mandir`: Location where the manpages will be installed. Defaults to `${PREFIX}/man`.
- `DESTDIR`: This is prepended to all paths during the installation. It is
mainly used for packaging.
- `Q`: Whether to quiet the build or not. To make the build more verbose, clear
this variable. Defaults to `@`.
- `STRIP`: Whether to strip the installed binaries of debug symbols or not.
Defaults to `-s`.
- `BINMODE`: Permissions of the installed binaries. Defaults to `555`.
- `MANMODE`: Permissions of the installed manpages. Defaults to `444`.
## 3 History
- Around 1997, Carsten Sorensen (AKA SurfSmurf) writes ASMotor as a
general-purpose assembler/linker system for DOS/Win32
- Around 1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and
produce GBZ80 assembly/machine code, and releases this version as RGBDS.
- 2009, Vegard Nossum adapts the code to be more UNIX-like and releases this
version as rgbds-linux on [GitHub](https://github.com/vegard/rgbds-linux).
- 2010, Anthony J. Bentley forks that repository. The fork becomes the reference
implementation of rgbds.
- 2017, Bentley's repository is moved to a neutral name.

View File

@@ -1,129 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1>xAsm Documentation</h1>
<h2>Table of Contents</h2>
<h3>General stuff</h3>
<ul>
<li><a href="asm/history.htm">History</a>
<li><a href="asm/usage.htm">Usage</a>
<li><a href="asm/opt.htm">Changing options while assembling</a>
<li><a href="asm/popo.htm">The option stack</a>
<li><a href="asm/syntax.htm">Syntax and comments</a>
<li><a href="asm/section.htm">Sections</a>
</ul>
<h3>Symbols</h3>
<ul>
<li><a href="asm/symbols.htm">Symbols</a>
<li><a href="asm/export.htm">Exporting and importing symbols</a>
<li><a href="asm/purge.htm">Purging symbols</a>
<li><a href="asm/presym.htm">Predeclared symbols</a>
</ul>
<h3>The macrolanguage</h3>
<ul>
<li><a href="asm/print.htm">Printing out things during assembling</a>
<li><a href="asm/rept.htm">Automatically repeating blocks of code</a>
<li><a href="asm/fail.htm">Aborting the assembly process</a>
<li><a href="asm/include.htm">Including other sourcefiles</a>
<li><a href="asm/if.htm">Conditional assembling</a>
<li><a href="asm/expr_int.htm">Integer and Boolean expressions</a>
<li><a href="asm/expr_fix.htm">Fixed-point expressions and functions</a>
<li><a href="asm/expr_str.htm">String expressions, functions and formatting</a>
<li><a href="asm/miscfunc.htm">Other functions</a>
</ul>
<h3>Other ways than mnemonics to define data</h3>
<ul>
<li><a href="asm/db.htm">Defining constant data</a>
<li><a href="asm/ds.htm">Declaring variables in a RAM section</a>
<li><a href="asm/incbin.htm">Including binary files</a>
</ul>
<h3>Target specific information</h3>
<ul>
<li><a href="asm/trg_gb.htm">The Gameboy</a>
</ul>
<h3>Alphabetical list of the macro-language instructions and functions</h3>
<ul>
<li><a href="asm/presym.htm">@</a>
<li><a href="asm/presym.htm">__DATE__</a>
<li><a href="asm/presym.htm">__LINE__</a>
<li><a href="asm/presym.htm">__TIME__</a>
<li><a href="asm/presym.htm">_NARG</a>
<li><a href="asm/presym.htm">_PI</a>
<li><a href="asm/presym.htm">_RS</a>
<li><a href="asm/expr_fix.htm">ACOS</a>
<li><a href="asm/expr_fix.htm">ASIN</a>
<li><a href="asm/expr_fix.htm">ATAN</a>
<li><a href="asm/expr_fix.htm">ATAN2</a>
<li><a href="asm/miscfunc.htm">BANK</a>
<li><a href="asm/expr_fix.htm">COS</a>
<li><a href="asm/db.htm">DB</a>
<li><a href="asm/miscfunc.htm">DEF</a>
<li><a href="asm/expr_fix.htm">DIV</a>
<li><a href="asm/ds.htm">DS</a>
<li><a href="asm/db.htm">DW</a>
<li><a href="asm/if.htm">ELSE</a>
<li><a href="asm/if.htm">ENDC</a>
<li><a href="asm/macro.htm">ENDM</a>
<li><a href="asm/rept.htm">ENDR</a>
<li><a href="asm/equ.htm">EQU</a>
<li><a href="asm/equs.htm">EQUS</a>
<li><a href="asm/export.htm">EXPORT</a>
<li><a href="asm/fail.htm">FAIL</a>
<li><a href="asm/export.htm">GLOBAL</a>
<li><a href="asm/section.htm">HRAM</a>
<li><a href="asm/if.htm">IF</a>
<li><a href="asm/export.htm">IMPORT</a>
<li><a href="asm/incbin.htm">INCBIN</a>
<li><a href="asm/include.htm">INCLUDE</a>
<li><a href="asm/macro.htm">MACRO</a>
<li><a href="asm/expr_fix.htm">MUL</a>
<li><a href="asm/opt.htm">OPT</a>
<li><a href="asm/popo.htm">POPO</a>
<li><a href="asm/pops.htm">POPS</a>
<li><a href="asm/print.htm">PRINTF</a>
<li><a href="asm/print.htm">PRINTT</a>
<li><a href="asm/print.htm">PRINTV</a>
<li><a href="asm/purge.htm">PURGE</a>
<li><a href="asm/popo.htm">PUSHO</a>
<li><a href="asm/pops.htm">PUSHS</a>
<li><a href="asm/rept.htm">REPT</a>
<li><a href="asm/rs.htm">RB</a>
<li><a href="asm/section.htm">ROM0</a>
<li><a href="asm/section.htm">ROMX</a>
<li><a href="asm/rs.htm">RSRESET</a>
<li><a href="asm/rs.htm">RSSET</a>
<li><a href="asm/rs.htm">RW</a>
<li><a href="asm/section.htm">SECTION</a>
<li><a href="asm/set.htm">SET</a>
<li><a href="asm/shift.htm">SHIFT</a>
<li><a href="asm/expr_fix.htm">SIN</a>
<li><a href="asm/section.htm">SRAM</a>
<li><a href="asm/expr_str.htm">STRCAT</a>
<li><a href="asm/expr_str.htm">STRCMP</a>
<li><a href="asm/expr_str.htm">STRIN</a>
<li><a href="asm/expr_str.htm">STRLEN</a>
<li><a href="asm/expr_str.htm">STRLWR</a>
<li><a href="asm/expr_str.htm">STRSUB</a>
<li><a href="asm/expr_str.htm">STRUPR</a>
<li><a href="asm/expr_fix.htm">TAN</a>
<li><a href="asm/section.htm">VRAM</a>
<li><a href="asm/section.htm">WRAM0</a>
<li><a href="asm/section.htm">WRAMX</a>
<li><a href="asm/fail.htm">WARN</a>
<li><a href="asm/export.htm">XDEF</a>
<li><a href="asm/export.htm">XREF</a>
</ul>
<p>Last updated 20 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,26 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm DB, DW</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>DB, DW</h1>
<p><dfn>DB</dfn> defines a list of bytes that will be stored in the final image. Ideal for tables and text.</p>
<pre>DB 1,2,3,4,"This is a string"</pre>
<p>Alternatively you can use <dfn>DW</dfn> to store a list of words. Strings are not allowed as arguments to DW.</p>
<p>You can also use DB and DW without arguments. This works exactly like “DS 1” and “DS 2” respectively. Consequently DB and DW can be used in a WRAM0/WRAMX/HRAM/VRAM/SRAM section.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
<li><a href="expr_fix.htm">Fixed-point expressions and functions</a>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
<li><a href="ds.htm">Declaring variables in a RAM section</a>
<li><a href="miscfunc.htm">Other functions</a>
</ul>
<hr>
<p>Last updated 02 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm DS</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>DS</h1>
<p><dfn>DS</dfn> allocates a number of bytes. The content is undefined. This is the preferred method of allocationg space in a <a href="section.htm">RAM section</a>. You can however also use DB and DW without any arguments.</p>
<pre>DS str_SIZEOF ;allocate str_SIZEOF bytes</pre>
<h1>See also:</h1>
<ul>
<li><a href="db.htm">Defining constant data (DB/DW)</a>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
</ul>
<hr>
<p>Last updated 02 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,21 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm EQU</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>EQU</h1>
<p>EQUates are constant symbols. They can for example be used for things such as bit-definitions of hardware-registers.</p>
<pre>DONUT_ISGOOD EQU $01
DONUT_ISBAD EQU $02</pre>
<p>Note that a colon (:) following the label-name is not allowed. EQUates can be <a href="export.htm">exported and imported</a>. They don't change their value during the link process.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,27 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm EQUS</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>EQUS</h1>
<p>EQUS is used to define string-symbols. Wherever the assembler meets a string symbol its name is replaced with its value. If you are familiar with C you can think of it as the same as #define.</p>
<pre>COUNTREG EQUS "[hl+]"
ld a,COUNTREG</pre>
<p>(Note that : following the label-name is not allowed.)</p>
<p>This will be interpreted as:</p>
<pre> ld a,[hl+]</pre>
<p>String-symbols can also be used to define small one-line macros:</p>
<pre>PUSHA EQUS "push af\npush bc\npush de\npush hl\n"</pre>
<p>Note that a colon (:) following the label-name is not allowed. String equates can't be exported or imported.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,35 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm EXPORT/XREF, IMPORT/XDEF, GLOBAL</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>EXPORT/XREF, IMPORT/XDEF, GLOBAL</h1>
<p>Importing and exporting of symbols is a feature that is very useful when your project spans many source-files and for example you need to jump to a routine defined in another file.</p>
<table>
<caption>Import/export commands</caption>
<thead>
<tr>
<th scope="col">Command</th>
<th scope="col">Meaning</th>
</tr>
</thead>
<tr>
<td>IMPORT (or XREF) <i>label</i>[,<i>label</i>,...]</td>
<td>This instructs the assembler to define label as if it were present
in the current file but leave the address calculation to the linker.</td>
</tr>
<tr>
<td>EXPORT (or XDEF) <i>label</i>[,<i>label</i>,...]</td>
<td>The assembler will make <i>label</i> accessible to other files during the link process.</td>
</tr>
<tr>
<td>GLOBAL <i>label</i>[,<i>label</i>,...]</td>
<td>If <i>label</i> is defined during the assembly it will be exported, if not it will be imported. Handy (very!) for include-files.</td>
</tr>
</table>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body></html>

View File

@@ -1,76 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Fixed-point expression</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Fixedpoint Expressions</h1>
<p>Fixed point constants are basically normal 32-bit constants where the upper 16 bits are used for the integer part and the lower 16 bits are used for the fraction (65536ths). This means that you can use them in normal integer expression and indeed some integer operators like plus and minus don't care whether the operands are integer or fixed-point. You can easily convert a fixed-point number to an integer by shifting it right 16 bits. It follows that you can convert an integer to a fixed-point number by shifting it left.</p>
<p>Some things are different for fixed-point math though. Which is why you have the following functions to use:</p>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Operation</th>
</tr>
</thead>
<tr>
<td>DIV(x,y)</td>
<td>x/y</td>
</tr>
<tr>
<td>MUL(x,y)</td>
<td>x*y</td>
</tr>
<tr>
<td>SIN(x)</td>
<td>sin(x)</td>
</tr>
<tr>
<td>COS(x)</td>
<td>cos(x)</td>
</tr>
<tr>
<td>TAN(x)</td>
<td>tan(x)</td>
</tr>
<tr>
<td>ASIN(x)</td>
<td>sin<SUP>-1</SUP>(x)</td>
</tr>
<tr>
<td>ACOS(x)</td>
<td>cos<SUP>-1</SUP>(x)</td>
</tr>
<tr>
<td>ATAN(x)</td>
<td>tan<SUP>-1</SUP>(x)</td>
</tr>
<tr>
<td>ATAN2(x,y)</td>
<td>(x,y) angle</td>
</tr>
</table>
<p>These functions are extremely useful for automatic generation of various tables. A circle has 65536.0 degrees. Sine values are between [-1.0;1.0]</p>
<pre>; --
; -- Generate a 256 byte sine table with values between 0 and 128
; --
ANGLE SET 0.0
REPT 256
DB (MUL(64.0,SIN(ANGLE))+64.0)>>16
ANGLE SET ANGLE+256.0
ENDR</pre>
<h1>See also:</h1>
<ul>
<li><a href="symbols.htm">Symbols</a>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
<li><a href="miscfunc.htm">Other functions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,92 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Integer/Boolean expressions</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Integer and Boolean expressions</h1>
<p>An expression can be composed of many things. Expressions are always evaluated using signed 32-bit math.</p>
<p>The most basic expression is just a single number.</p>
<h2>Numeric Formats</h2>
<p>xAsm has a number of numeric formats.</p>
<ul>
<li>Hexadecimal: $0123456789ABCDEF. Case-insensitive
<li>Decimal: 0123456789
<li>Octal: &01234567
<li>Binary: %01
<li>Fixedpoint (16.16): 01234.56789
<li>Character constant: "ABYZ"
<li>Gameboy graphics: `0123
</ul>
<p>The last one, Gameboy graphics, is quite interesting and useful. The values are actually pixel values and it converts the “chunky” data to “planar” data as used in the Gameboy.</p>
<pre>DW `01012323</pre>
<p>Admittedly an expression with just a single number is quite boring. To spice things up a bit theres a few operators you can use to perform calculations between numbers.</p>
<h2>Operators</h2>
<p>A great number of operators you can use in expressions are available (listed in order of precedence):</p>
<table>
<caption>Operators</caption>
<thead>
<tr>
<th scope="col">Operator</th>
<th scope="col">Meaning</th>
</tr>
</thead>
<tr>
<td>( )</td>
<td>Precedence override</td>
</tr>
<tr>
<td>FUNC()</td>
<td>Functioncall</td>
</tr>
<tr>
<td>~ + -</td>
<td>Unary not/plus/minus</td>
</tr>
<tr>
<td>* / %</td>
<td>Multiply/divide/modulo</td>
</tr>
<tr>
<td>&lt;&lt; &gt;&gt;</td>
<td>Shift left/right</td>
</tr>
<tr>
<td>&amp; | ^</td>
<td>Binary and/or/xor</td>
</tr>
<tr>
<td>+ -</td>
<td>Add/subtract</td>
</tr>
<tr>
<td>!= == &lt;= &gt;= &lt; &gt;</td>
<td>Boolean comparison</td>
</tr>
<tr>
<td>&amp;&amp; ||</td>
<td>Boolean and/or</td>
</tr>
<tr>
<td>!</td>
<td>Unary Boolean not</td>
</tr>
</table>
<p>The result of the boolean operators is zero if when FALSE and non-zero when TRUE. Thus it is legal to use an integer as the condition for <a href="if.htm">IF</a> blocks. You can use symbols instead of numbers in your expression if you wish.</p>
<p>An expression is said to be constant when it doesn't change its value during linking. This basically means that you can't use labels in those expressions. The instructions in the macro-language all require expressions that are constant.</p>
<h1>See also:</h1>
<ul>
<li><a href="symbols.htm">Symbols</a>
<li><a href="expr_fix.htm">Fixed-point expressions and functions</a>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
<li><a href="miscfunc.htm">Other functions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,114 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm String expressions</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>String Expressions</h1>
<p>The most basic string expression is any number of characters contained in double quotes ("for instance"). As in C the escape character is <b>\</b> and there is a number of commands you can use within a string:</p>
<table>
<caption>Escape characters:</caption>
<thead>
<tr>
<th scope="col">Character sequence</th>
<th scope="col">Meaning</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tr>
<td>\\</td>
<td>Backslash</td>
<td></td>
</tr>
<tr>
<td>\"</td>
<td>Double-quote</td>
<td></td>
</tr>
<tr>
<td>\{</td>
<td>Curly bracket left</td>
<td></td>
</tr>
<tr>
<td>\}</td>
<td>Curly bracket right</td>
<td></td>
</tr>
<tr>
<td>\n</td>
<td>Newline ($0A)</td>
<td></td>
</tr>
<tr>
<td>\t</td>
<td>Tab ($09)</td>
<td></td>
</tr>
<tr>
<td>\1-\9</td>
<td>Macroargument</td>
<td>Only in macros</td>
</tr>
<tr>
<td>\@</td>
<td>Labelname suffix</td>
<td>Only in macros and repts</td>
</tr>
</table>
<p>A funky feature is <b>{symbol}</b> withing a string. This will examine the type of the symbol and insert its value accordingly. If symbol is a string symbol the symbols value is simply copied. If it's a numeric symbol the value is converted to hexadecimal notation and inserted as a string.</p>
<p><strong>HINT:</strong> The <b>{symbol}</b> construct can also be used outside strings. The symbols value is again inserted as a string. This is just a short way of doing &quot;{symbol}&quot;.</p>
<p>Whenever the macro-language expects a string you can actually use a string expression. This consists of one or more of these function. Yes, you can nest them. Note that some of these functions actually return an integer and can be used as part of an integer expression!</p>
<table>
<caption>String functions:</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Operation</th>
</tr>
</thead>
<tr>
<td>STRLEN(<i>stringexpr</i>)</td>
<td>Returns the number of characters in <i>string</i></td>
</tr>
<tr>
<td>STRCAT(<i>stringexpr1,stringexpr2</i>)</td>
<td>Appends <i>stringexpr2</i> to <i>stringexpr1</i>.</td>
</tr>
<tr>
<td>STRCMP(<i>stringexpr1,stringexpr2</i>)</td>
<td>Returns negative if <i>stringexpr1</i> is alphabetically less than <i>stringexpr2</i><BR>Zero if they match<BR>Positive if greater than</td>
</tr>
<tr>
<td>STRIN(<i>haystack,needle</i>)</td>
<td>Returns <i>needle</i>s position within <i>haystack</i> or zero if it's not present</td>
</tr>
<tr>
<td>STRSUB(<i>stringexpr,pos,count</i>)</td>
<td>Returns a substring of <i>stringexpr</i> starting at <i>pos</i> (first character is position 1) and with <i>count</i> characters</td>
</tr>
<tr>
<td>STRUPR(<i>stringexpr</i>)</td>
<td>Converts all characters in <i>string</i> to capitals and returns the new string</td>
</tr>
<tr>
<td>STRLWR(<i>string</i>)</td>
<td>Converts all characters in <i>string</i> to lower case and returns the new string</td>
</tr>
</table>
<h1>See also:</h1>
<ul>
<li><a href="symbols.htm">Symbols</a>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
<li><a href="expr_fix.htm">Fixed-point expressions and functions</a>
<li><a href="miscfunc.htm">Other functions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm FAIL, WARN</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>FAIL, WARN</h1>
<p>FAIL and WARN can be used to terminate the assembling process if you wish to do so. This is especially useful for macros that get an invalid argument. FAIL and WARN take a string as the only argument and they will print this string out as a normal error with a linenumber.</p>
<p>FAIL stops assembling immediately while WARN continues after printing the errormessage.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,224 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm History</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>xAsm History</h1>
<table>
<caption>The history of xAsm</caption>
<thead>
<tr>
<th scope="col">Version</th>
<th scope="col">Dated</th>
<th scope="col">Release notes</th>
</tr>
</thead>
<tr>
<td>1.0</td>
<td>1 Oct. 96</td>
<td>First release</td>
</tr>
<tr>
<td>1.01</td>
<td>1 Dec. 96</td>
<td><ul>
<li>Fixed bug in <a href="incbin.htm">INCBIN</a> (sometimes reported the section full)</li>
<li>Added <a href="miscfunc.htm">DEF()</a> function
</ul></td>
</tr>
<tr>
<td>1.02</td>
<td>12 Feb. 97</td>
<td><ul>
<li>Added <a href="expr_str.htm">STRLEN(), STRCAT(), STRIN(), STRCMP(), STRSUB(), STRUPR() and STRLWR()</a> functions</li>
<li><a href="export.htm">IMPORT/EXPORT/GLOBAL</a> takes multiple arguments now</li>
<li><a href="section.htm">HRAM</a> sectiontype added</li>
<li>ORG like features added to <a href="section.htm">SECTION</a></li>
<li><a href="trg_gb.htm">LDIO</a> mnemonic added</li>
</ul></td>
</tr>
<tr>
<td>1.03</td>
<td>23 Mar. 97</td>
<td><ul>
<li>The <a href="section.htm">HRAM section</a> was 128 bytes long instead of 127. potentially thrashing the interrupt enable register if you filled the HRAM.</li>
<li>The <a href="miscfunc.htm">BANK() function</a>, when used on a symbol defined in the current sourcefile, returned the wrong bank ID. (reported by Harry P. Mulder)</li>
<li>The <a href="miscfunc.htm">BANK() function</a> didn't check whether the argument was a properly defined symbol. (reported by Harry P. Mulder)</li>
<li>Completely new lexical analyser module. This fixed several linenumber bugs and other macro/if/rept related bugs. Also fixed a bug which made it possible to have equated symbols with the same name as a reserved keyword (if you get a "parse error" with this release on some of your sources, this is probably what is going on)</li>
<li><a href="fail.htm">FAIL and WARN</a> commands.</li>
<li><a href="presym.htm">__LINE__, __FILE__, __TIME__, __DATE__</a> predefined symbols added.</li>
</ul>
</td>
</tr>
<tr>
<td>1.04</td>
<td>03 July 1997</td>
<td><ul><li>First ASMotor release</li>
<li><a href="presym.htm">__TIME__ and __DATE__</a> give todays date instead of when the assembler was compiled.</li>
<li>Sometimes the first line of a file wouldn't assemble correctly. Reported by Jeff Frohwein.</li>
<li>Unrolling multiline <a href="equs.htm">string symbols</a> left the linecounter in a sorry state. Jeff Frohwein again.</li>
<li><a href="db.htm">DB and DW</a> can now (officially ;-) be used in BSS/HRAM/VRAM sections without any arguments to reserve a byte or a word respectively. Reported/suggested/inspired by Mr. Frohwein.</li>
<li>The character # can now be used as part of a <a href="symbols.htm">symbol name</A>. Jeff....</li>
<li>The <a href="rs.htm">RS</a> counter "_RS" is now defined from the very start of the assembly process instead of after the first RSSET or RSRESET.</li>
<li>Bug fixed: You couldn't use \0-\9 and \@ in <a href="expr_str.htm">{} constructs</a></li>
<li><a href="purge.htm">PURGE</a> pseudo-op added. Purges a symbol from the symboltable and memory. Use with extreme caution! Inspired by Harry P. Mulder</li>
<li><a href="macro.htm">MACRO</a> parameter passing method changed drastically. Read (and re-read) the manual for details. Suggested by Harry P. Mulder.</li>
</ul>
</td>
<tr>
<td>1.05</td>
<td>20 July 1997</td>
<td><B>RGBDS fixes:</B><BR>
RGBAsm supports the LDD and LDI syntax plus [HLD] and [HLI]. LDH is
synonymous with LDIO.<BR>
<B>General fixes:</B><BR>
There was a bug in the macro parameter passing. Any whitespace after the
last parameter would be appended to the last parameter. Reported by Jeff Frohwein.<BR>
A section stack has been implemented. Look up <a href="pops.htm">POPS and PUSHS</A>. Jeff Frohweins doing again.<BR>
<a href="opt.htm">OPT</A> command added for defining and changing some options while assembling.<BR>
You can now define which characters are used for the <a href="expr_int.htm">Gameboy graphics
integer (`)</A> using the <a href="usage.htm">commandline</A> or the new <a href="opt.htm">OPT</A> command. Cool idea by (surprise surprise) Jeff Frohwein.<BR>
Also, an option stack has been added. Look up <a href="popo.htm">POPO and PUSHO</A> in the
manual.<BR>
Fixed yet another line number bug reported by Jeff Frohwein (when will this guy leave me alone? ;)<BR>
</td>
<tr>
<td>1.06</td>
<td>22 July 1997</td>
<td><B>General fixes:</B><BR>
The lamest typo bug of all time has been fixed. RGBAsm would output a word defined with DW as 4 bytes instead of 2. Jeff Frohwein reported this.<BR>
The first line of an included file didn't assemble correctly.<BR>
<a href="usage.htm">-b option</A> added for setting the characters used for binary constants.<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>21 September 1997</td>
<td><B>General fixes:</B><BR>
A crash occured if you tried to use a macro symbol in an expression.
(Jeff Frohwein)<BR>
You couldn't use STRCMP, STRLEN and STRIN in relocatable expressions. (Harry
P. Mulder)<BR>
Relocatable symbols are no longer allowed as arguments to the DEF function.<BR>
Bug fixed in the assembler where it would sometimes write out too many bytes
for HRAM section definitions.<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>02 July 1999</td>
<td>
<B>Feature:</B>
<BR>
DQ directive added for defining 32-bit data constants. See operation of DW &amp; DB.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>05 July 1999</td>
<td>
<B>Feature:</B>
<BR>
Allow only a part of a binary file to be included instead of the whole thing.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>10 June 1999</td>
<td>
<B>Feature:</B>
<BR>
Added output of file dependency information for each file included/assembled. Enabled with a command line option.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Feature:</B>
<BR>
Added ORG directive to allow anonymous sections.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Feature:</B>
<BR>
Added ability to output error information in either RGBDS or Microsoft Developer Studio format.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Feature:</B>
<BR>
Added pseudo-instructions to handle NE (not equal), EQ (equal), and LT (less than) on JR/JP/CALL instructions
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Feature:</B>
<BR>
Added STRTRIM, STRLTRIM, STRRTRIM directives to allow trimming of white space from strings in macro arguments.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Bug Fix:</B>
<BR>
When an "unknown symbol" error was reported during the link phase the undefined symbol was not given.
<BR>
</td>
</tr>
<tr>
<td>1.08</td>
<td>?? ???? 1999</td>
<td>
<B>Bug Fix:</B>
<BR>
Declaring a symbol as GLOBAL in a header file and then referencing it in code but never defining it would crash the linker.
<BR>
</td>
</tr>
<tr>
<td>1.09</td>
<td>08 February 2000</td>
<td>
<B>Feature:</B>
<BR>
Can now use a command line option to set the number format between a slightly tweaked Motorola/RGBDS format and Zilog.
<BR>
Hex numbers can now be represented as $FF or FFh.
<BR>
Octal as &amp;77 or 77o.
<BR>
Binary as %10010110 or 10010110b.
<BR>
Gameboy graphics numbers as `1001 or 1001g.
<BR>
Decimal numbers remain unchanged.
<BR>
</td>
</tr>
</TABLE>
<BR><HR>
<FONT SIZE="-1"><I><P ALIGN=RIGHT>Last updated 21 September 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</A></P></I></FONT>

View File

@@ -1,24 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm IF, ELSE, ENDC</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>IF, ELSE, ENDC</h1>
<p>These three commands is used to conditionally assemble parts of your file. It is a powerful feature commonly used in macros.</p>
<pre>IF 2+2==4
PRINTT "2+2==4\n"
ELSE
PRINTT "2+2!=4\n"
ENDC</pre>
<p>The ELSE block is optional. IF/ELSE/ENDC-blocks can be nested.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm INCBIN</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>INCBIN</h1>
<p>You probably have some graphics youd like to include. Use <dfn>INCBIN</dfn> to include a raw binary file as it is. If the file isnt found in the current directory the <a href="usage.htm">include-path</a> list will be searched.</p>
<pre>INCBIN "titlepic.bin"
INCBIN "sprites\\hero.bin"</pre>
<p>You can also include only part of a file with <b>INCBIN</b>. The example below includes 256 bytes from <i>data.bin</i> starting from position 78.</p>
<pre>INCBIN "data.bin",78,256</pre>
<h1>See also:</h1>
<ul>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,19 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm INCLUDE</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>INCLUDE</h1>
<p>Use INCLUDE to process another assembler-file and then return to the current file when done. If the file isn't found in the current directory the <a href="usage.htm">include-path</a> list will be searched. You may nest <b>INCLUDE</b> calls infinitely (or until you run out of memory whichever comes first).</p>
<pre>INCLUDE "irq.inc"</pre>
<h1>See also:</h1>
<ul>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Labels</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Labels</h1>
<p>One of the assemblers main tasks is to keep track of addresses for you so you dort have to remember obscure numbers but can make do with a meaningful name, a label.</p>
<p>This can be done in a number of ways:</p>
<pre>GlobalLabel
AnotherGlobal:
.locallabel
.yet_a_local:
ThisWillBeExported:: ;note the two colons</pre>
<p>This is very similar to other assemblers. Local labels are only accessible within the scope they are defined. A scope starts after a global label and ends at the next global label. You may or may not have seen the <b>::</b> feature before. It declares a normal global label but does an <a href="export.htm">EXPORT</a> at the same time.</p>
<p>Labels will normally change their value during the <a href="../link.htm">link process</a> and are thus <em>not</em> constant.</p>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,60 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm MACRO/ENDM</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>MACRO, ENDM</h1>
<p>One of the best features of an assembler is the ability to write macros for it. Macros also provide a method of passing arguments to them and they can then react to the input using IF-constructs.</p>
<pre>MyMacro: MACRO
ld a,80
call MyFunc
ENDM</pre>
<p>The above example is a very simple macro. You execute the macro by typing its name.</p>
<pre> add a,b
ld sp,hl
MyMacro ;This will be expanded
sub a,87</pre>
<p>When the assembler meets MyMacro it will insert the macrodefinition (the text enclosed in <b>MACRO/ENDM</b>).</p>
<p id="labelsuffix">Suppose your macro contains a loop.</p>
<pre>LoopyMacro: MACRO
xor a,a
.loop ld [hl+],a
dec c
jr nz,.loop
ENDM</pre>
<p>This is fine. That is, if you only use the macro once per <a href="labels.htm">scope</a>. To get around this problem there is a special label string equate called <b>\@</b> that you can append to your labels and it will then expand to a unique string.</p>
<p><b>\@</b> also works in <a href="rept.htm">REPT-blocks</a> should you have any loops there.</p>
<pre>LoopyMacro: MACRO
xor a,a
.loop\@ ld [hl+],a
dec c
jr nz,.loop\@
ENDM</pre>
<h2>Arguments</h2>
<p>Id like <i>LoopyMacro</i> a lot better if I didnt have to pre-load the registers with values and <em>then</em> call it. What Id like is the ability to pass it arguments and it then loaded the registers itself.</p>
<p>And I can do that. In macros you can get the arguments by using the special macro string equates <b>\1</b> through <b>\9</b>, <b>\1</b> being the first argument specified on the calling of the macro.</p>
<pre>LoopyMacro: MACRO
ld hl,\1
ld c,\2
xor a,a
.loop\@ ld [hl+],a
dec c
jr nz,.loop\@
ENDM</pre>
<p>Now I can call the macro specifying two arguments. The first being the address and the second being a bytecount. The macro will then reset all bytes in this range.</p>
<pre> LoopyMacro MyVars,54</pre>
<p>You can specify up to nine arguments when calling a macro. Arguments are passed as string equates. Theres no need to enclose them in quotes. Parameter passing has changed a bit since v1.03 in that an expression will not be evaluated first but passed directly. This means that its probably a very good idea to use brackets around \1\9 if you perform further calculations on them. For instance if you pass 1+2 as the first argument and then do <code> PRINTV \1*2</code>
you will get the value 5 on screen and not 6 as you might have expected.</p>
<p>Note that a colon (:) following the macro-name is required. Macros can't be exported or imported. It's valid to call a macro from a macro (yes, even the same one).</p>
<h1>See also:</h1>
<ul>
<li><a href="shift.htm">SHIFT</a>
</ul>
<hr>
<p>Last updated 02 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,38 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Other functions</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Other functions</h1>
<p>There's a few other functions that do various useful things:</p>
<table>
<caption>Other functions</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Operation</th>
</tr>
</thead>
<tr>
<td>BANK(<i>label</i>)</td>
<td>Gameboy ONLY: Returns the bank number <i>label</i> is in. The link will have to resolve this so it can't be used when the expression has to be constant</td>
</tr>
<tr>
<td>DEF(<i>label</i>)</td>
<td>Returns TRUE if <i>label</i> has been defined</td>
</tr>
</table>
<h1>See alse:</h1>
<ul>
<li><a href="section.htm">Sections</a>
<li><a href="symbols.htm">Symbols</a>
<li><a href="presym.htm">Predeclared symbols</a>
<li><a href="if.htm">Conditional assembling</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,27 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm OPT</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>OPT</h1>
<p>OPT can be used to change <I>some</I> of the options during assembling you source instead of defining them on the commandline.</p>
<p>OPT takes a comma-seperated list of options as its argument:</p>
<pre> PUSHO
OPT g.oOX ;Set the GB graphics constants to use these characters
DW `..ooOOXX
POPO
DW `00112233</pre>
<p>The options that OPT can modify are currently: <b>b, e and g</b></p>
<h1>See also:</h1>
<ul>
<li><a href="usage.htm">Usage</a>
<li><a href="popo.htm">The option stack</a>
</ul>
<hr>
<p>Last updated 20 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm POPO, PUSHO</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>POPO, PUSHO</h1>
<p>POPO and PUSHO provide the interface to the option stack. PUSHO will push the current set of options on the option stack. POPO can then later be used to restore them. Useful if you want to change some options in an include file and you don't want to destroy the options set by the program that included your file. The stacks number of entries is limited only by the amount of memory in your machine.</p>
<h1>See also:</h1>
<ul>
<li><a href="opt.htm">Changing options while assembling</a>
</ul>
<hr>
<p>Last updated 20 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm POPS, PUSHS</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>POPS, PUSHS</h1>
<p>POPS and PUSHS provide the interface to the section stack. PUSHS will push the current section context on the section stack. POPS can then later be used to restore it. Useful for defining sections in included files when you don't want to destroy the section context for the program that included your file. The stacks number of entries is limited only by the amount of memory in your machine.</p>
<h1>See also:</h1>
<ul>
<li><a href="section.htm">Sections</a>
</ul>
<hr>
<p>Last updated 18 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,63 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Predeclared symbols</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Predeclared symbols</h1>
<table>
<caption>Symbols</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Contents</th>
<th scope="col">Type</th>
</tr>
</thead>
<tr>
<td>@</td>
<td>PC value</td>
<td>EQU</td>
</tr>
<tr>
<td>_PI</td>
<td>Fixed point ¶</td>
<td>EQU</td>
</tr>
<tr>
<td>_RS</td>
<td>_RS counter</td>
<td>SET</td>
</tr>
<tr>
<td>_NARG</td>
<td>Number of arguments passed to macro</td>
<td>EQU</td>
</tr>
<tr>
<td>__LINE__</td>
<td>The current linenumber</td>
<td>EQU</td>
</tr>
<tr>
<td>__FILE__</td>
<td>The current filename</td>
<td>EQUS</td>
</tr>
<tr>
<td>__DATE__</td>
<td>Todays date</td>
<td>EQUS</td>
</tr>
<tr>
<td>__TIME__</td>
<td>The current time</td>
<td>EQUS</td>
</tr>
</table>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,29 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm PRINTT, PRINTV, PRINTF</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>PRINTT, PRINTV, PRINTF</h1>
<p>These three instructions type text and values to stdout. Useful for debugging macros or wherever you may feel the need to tell yourself some important information.</p>
<pre>PRINTT "I'm the greatest programmer in the whole wide world\n"
PRINTV (2+3)/5
PRINTF MUL(3.14,3987.0)</pre>
<ul>
<li><dfn>PRINTT</dfn> prints out a string</li>
<li><dfn>PRINTV</dfn> prints out an integer value or, as in the example, the result of a calculation. Unsurprisingly you can also print out a <a href="symbols.htm">constant symbols</a> value</li>
<li><dfn>PRINTF</dfn> prints out a fixed point value.</li>
</ul>
<h1>See also:</h1>
<ul>
<li><a href="asm/expr_int.htm">Integer and Boolean expressions</a>
<li><a href="asm/expr_fix.htm">Fixed-point expressions and functions</a>
<li><a href="asm/expr_str.htm">String expressions, functions and formatting</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm PURGE</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>PURGE</h1>
<p>The PURGE command allows you to completely remove a symbol from the symbol table as if it had never existed. USE WITH EXTREME CAUTION!!! I cant stress this enough but you <em>seriously</em> need to know what you are doing. DONT purge symbol that you use in expressions the linker needs to calculate. In fact, its probably not even safe to purge anything other than string symbols and macros.</p>
<pre>Kamikaze EQUS "I don't want to live anymore"
AOLer EQUS "Me too"
PURGE Kamikaze,AOLer</pre>
<p>Note that string symbols that are part of a PURGE command WILL NOT BE EXPANDED as the ONLY exception to this rule.</p>
<hr>
<p>Last updated 02 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,32 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm REPT, ENDR</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>REPT, ENDR</h1>
<p>Suppose youre feeling lazy and you want to unroll a time consuming loop. <dfn>REPT</dfn> is here for that purpose. Everything between REPT and ENDR will be repeated a number of times just as if you done a copy/paste operation yourself</p>
<pre>REPT 4
add a,c
ENDR</pre>
<p>This will assemble <code>add a,c</code> four times.</p>
<p>You can also use REPT to generate tables on the fly:</p>
<pre>; --
; -- Generate a 256 byte sine table with values between 0 and 128
; --
ANGLE SET 0.0
REPT 256
DB (MUL(64.0,SIN(ANGLE))+64.0)>>16
ANGLE SET ANGLE+256.0
ENDR</pre>
<p>REPT is also very useful in recursive macros and as in macros you can also use the special label operator \@. REPT-blocks can be nested.<p>
<h1>See also:</h1>
<ul>
<li><a href="macro.htm#labelsuffix">\@</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,76 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm RSSET, RSRESET, RB, RW</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>RSSET, RERESET, RB, RW</h1>
<p>The <dfn>RS</dfn> group of commands is a handy way of defining structures:</p>
<pre> RSRESET
str_pStuff RW 1
str_tData RB 256
str_bCount RB 1
str_SIZEOF RB 0</pre>
<p>The example defines four <a href="equ.htm">equated</a> symbols:</p>
<table>
<caption>Defined symbols</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Value</th>
</tr>
</thead>
<tr>
<td>str_pStuff</td>
<td>0</td>
</tr>
<tr>
<td>str_tData</td>
<td>2</td>
</tr>
<tr>
<td>str_bCount</td>
<td>258</td>
</tr>
<tr>
<td>str_SIZEOF</td>
<td>259</td>
</tr>
</table>
<p>There are four commands in the RS group of commands:</p>
<table>
<caption>RS related commands</caption>
<thead>
<tr>
<th scope="col">Command</th>
<th scope="col">Meaning</th>
</tr>
</thead>
<tr>
<td>RSRESET</td>
<td>Resets the <a href="presym.htm">_RS</a> counter to zero</td>
</tr>
<tr>
<td>RSSET <i>constexpr</i></td>
<td>Sets the <a href="presym.htm">_RS</a> counter to <i>constexpr</i></td>
</tr>
<tr>
<td>RB <i>constexpr</i></td>
<td>Sets the preceding symbol to <a href="presym.htm">_RS</a> and adds <i>constexpr</i> to _RS</td>
</tr>
<tr>
<td>RW <i>constexpr</i></td>
<td>Sets the preceding symbol to <a href="presym.htm">_RS</a> and adds <i>constexpr*2</i> to _RS</td>
</tr>
</table>
<p>Note that a colon (:) following the symbol-name is not allowed. RS symbols can be exported and imported. They don't change their value during the link process.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,70 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm SECTION</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>SECTION</h1>
<p>Before you can start writing code you must define a section. This tells the assembler what kind of data follows and if it is code where to put it.</p>
<pre>SECTION "CoolStuff",ROMX</pre>
<p>This switches to the section called <b>"CoolStuff"</b> (or creates it if it doesn't already exits) and it defines it as a code section. All sections within a sourcefile must be identified by a <em>unique</em> name.</p>
<p>Possible section types are as follows:
<dl>
<dt>ROM0</dt>
<dd>A ROM section. Mapped to memory at $0000$3fff.</dd>
<dt>ROMX</dt>
<dd>A banked ROM section. Mapped to memory at $4000$7fff. Valid banks range from 1 to 511.</dd>
<dt>VRAM</dt>
<dd>A banked video RAM section. Mapped to memory at $8000$9fff. Can only allocate memory, not fill it. Valid banks range from 0 to 1.</dd>
<dt>SRAM</dt>
<dd>A banked external (save) RAM section. Mapped to memory at $a000$bfff. Can only allocate memory, not fill it. Valid banks range from 0 to 3.</dd>
<dt>WRAM0</dt>
<dd>A general-purpose RAM section. Mapped to memory at $c000$cfff. Can only allocate memory, not fill it.</dd>
<dt>WRAMX</dt>
<dd>A banked general-purpose RAM section. Mapped to memory at $d000$dfff. Can only allocate memory, not fill it. Valid banks range from 1 to 7.</dd>
<dt>HRAM</dt>
<dd>A high RAM section. Mapped to memory at $ff80$fffe. Can only allocate memory, not fill it. NOTE WELL: if you use this method of allocating HRAM the assembler will NOT choose the short addressingmode in the LD instruction because the actual address calculation is done by the linker! If you find this undesirable you can use <a href="rs.htm">RSSET/RB/RW</a> instead or use the LDIO mnemonic. The address calculation is then done by the assembler.</dd>
</dl>
<p>The following deprecated section names are aliases for some of the above sections:
<dl>
<dt>HOME</dt>
<dd>Alias for ROM0.</dd>
<dt>CODE</dt>
<dt>DATA</dt>
<dd>Alias for ROMX.</dd>
<dt>BSS</dt>
<dd>Alias for WRAM0.</dd>
</dl>
<p>Due to quite a lot of emails requesting an ORG directive you can now add an address to the sectiontype for the Gameboy:</p>
<pre>SECTION "CoolStuff",ROM0[$1234]</pre>
<p>This will force the section to address $1234. This also works with the other sectiontypes. For ROMX sections the linker will then place the section in any bank at the address you specify. If you also want to specify the bank you can do:</p>
<pre>SECTION "CoolStuff",ROMX[$4567],BANK[3]</pre>
<p>And if you only want to force the section into a certain bank, and not it's position within the bank, that's also possible:</p>
<pre>SECTION "CoolStuff",ROMX,BANK[7]</pre>
<p><strong>HINT:</strong> If you think this is a lot of typing for doing a simple ORG type thing you can quite easily write an intelligent macro (called ORG for example) that uses <a href="expr_str.htm">\@</a> for the sectionname and determines correct sectiontype etc as arguments for SECTION</p>
<h1>See also:</h1>
<ul>
<li><a href="../link.htm">xLink</a> documentation
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
<li><a href="pops.htm">POPS and PUSHS:</a> The section stack.
</ul>
<hr>
<p>Last updated 18 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm SET</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>SET</h1>
<p>SETs are like <a href="equ.htm">EQUates</a> also constant symbols in the sense that their values are defined during the assembly process. These symbols are normally used in macros.</p>
<pre>KINKYCOUNT SET 2
KINKYCOUNT SET DONUT_ISGOOD+KINKYCOUNT</pre>
<p>Note that a colon (:) following the label-name is not allowed. SETs can be exported and imported but the result is undefined and might change in a later release. Alternatively you can use = as a synonym for SET.</p>
<h1>See also:</h1>
<ul>
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,19 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm SHIFT</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>SHIFT</h1>
<p><dfn>SHIFT</dfn> is a special command only available in <a href="macro.htm">macros</a>. Very useful in <a href="rept.htm">REPT-blocks</a>. It will "shift" the arguments by one "to the left". <b>\1</b> will get <b>\2</b>'s value, <b>\2</b> will get <b>\3</b>'s value and so forth.</p>
<h1>See also:</h1>
<ul>
<li><a href="macro.htm">Macros</a>
<li><a href="rept.htm">Automatically repeating blocks of code</a>
</ul>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,31 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Symbols</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>xAsm Symbols</h1>
<p>xAsm supports several types of symbols:</p>
<ul>
<li><a href="labels.htm">Label</a>. Used to assign a memory location with a name
<li><a href="equ.htm">EQUate</a>. Give a constant a name.
<li><a href="set.htm">SET</a>. Same as EQUate but with a subtle difference. You can change the value of a SET during assembling.
<li><a href="rs.htm">Structures (the RS group)</a>. Define a structure easily.
<li><a href="equs.htm">String equate (EQUS)</a>. Give an often used string a name. Can also be used as a mini-macro. Much like #define in C.
<li><a href="macro.htm">MACROs</a>. A block of code or pseudo instructions that you invoke like any other mnemonic. You can give them arguments too! Life is good.
</ul>
<p><strong>A symbol cannot have the same name as a reserved keyword.</strong></p>
<h1>See also:</h1>
<ul>
<li><a href="presym.htm">Predeclared symbols</a>
<li><a href="export.htm">Importing and exporting symbols</a>
<li><a href="purge.htm">Purging symbols</a>
</ul>
<hr>
<p>Last updated 02 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,23 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Syntax</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>xAsm Syntax</h1>
<p>The syntax linebased, just as in any other assembler. Meaning that you do one instruction or pseudoop per line:</p>
<pre>[label] [instruction] [;comment]</pre>
<p>Example:</p>
<pre>John: ld a,87 ;Weee</pre>
<p>A comment can also be an asterisk (*) followed by the comment if the asterisk is the first character on the line:</p>
<pre>********************************
* These are full line comments *
********************************</pre>
<p>All pseudoops, mnemonics and registers (reserved keywords) are <em>caseinsensitive</em> and all labels are <em>casesensitive</em>.</p>
<hr>
<p>Last updated 21 June 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,102 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Gameboy</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Gameboy</h1>
<p>The full GB-Z80 instruction-set is implemented with a few modifications to the original Zilog syntax. This is due to a Bison problem but in my opinion the syntax is better than the original one.</p>
<h2>Instructions</h2>
<ul>
<li>ADC
<li>ADD
<li>AND
<li>BIT
<li>CALL
<li>CCF
<li>CP
<li>CPL
<li>DAA
<li>DEC
<li>DI
<li>EI
<li>EX
<li>HALT
<li>INC
<li>JP
<li>JR
<li>LD
<li>LDD
<li>LDI
<li>LDH/LDIO (see note below)
<li>NOP
<li>OR
<li>POP
<li>PUSH
<li>RES
<li>RET
<li>RETI
<li>RL
<li>RLA
<li>RLC
<li>RLCA
<li>RR
<li>RRA
<li>RRC
<li>RRCA
<li>RST
<li>SBC
<li>SCF
<li>SET
<li>SLA
<li>SRA
<li>SRL
<li>STOP
<li>SUB
<li>SWAP
<li>XOR
</ul>
<p>Note that you can use both
<pre> OR A,B
OR B</pre>
<h2>Addressingmodes</h2>
<p>Indirect addressing has been changed to [ ] instead of ( ):</p>
<ul>
<li> A
<li> B
<li> C
<li> D
<li> E
<li> H
<li> L
<li> AF
<li> BC
<li> DE
<li> HL
<li> SP
<li> [BC]
<li> [DE]
<li> [HL]
<li> [HL-]/[HLI]
<li> [HL+]/[HLD]
<li> [SP]
<li> n8 (8 bit expression)
<li> n16 (16 bit expression)
<li> n3 (3 bit CONSTANT expression)
<li> [n16]/[$FF00+n8]
<li> [$FF00+C]/[C]
</ul>
<p>The assembler will intelligently decide between <b>[n16]</b> and <b>[$FF00+n8]</b> in the LD instruction. Note however that if you use any <a href="symbols.htm">constant symbols</a> in the expression they had better be defined before the instruction or your symbol-table may become mangled. Also worth noting is that it will only ever select the short $FF00 mode when you use constant symbols. NOT if you use symbols defined in a <a href="section.htm">HRAM section</a>. As this defies the whole point of implementing the HRAM sectiontype I've added the LDIO mnemonic. It works like the LD instruction but it will ALWAYS generate the $FF00+ form and it will also automatically logically AND the expression with $FF if it is relocatable. Which is what you want. Trust me ;)</p>
<h2>Conditioncodes</h2>
<ul>
<li> C
<li> NC
<li> Z
<li> NZ
</ul>
<hr>
<p>Last updated 20 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,30 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xAsm Usage</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>xAsm Usage</h1>
<pre>C:\>xAsm [options] asmfile</pre>
<p>Options are preceded by a hyphen (-) and go as follows:</p>
<pre> o<b>objectfile</b> : Write an <a href="../rgb0.htm">object-file</a> for <a href="../link.htm">xLink</a>
i<b>path</b> : Add an extra include-path
h : Short help text
e<b>(l|b)</b> : Change endianness (CAUTION!)
g<b>ASCI</b> : Change the four characters used for Gameboy graphics
constants (default is <b>0123</b>)
b<b>AS</b> : Change the two characters used for binary constants
(default is <b>01</b>)
z<b>HX</b> : Set the byte value (hex format) used for uninitialised data (default is ? for random)
</pre>
<h1>See also:</h1>
<ul>
<li><a href="opt.htm">Changing options while assembling</a>
</ul>
<hr>
<p>Last updated 08 October 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,116 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>General Information</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1><abbr title="Rednex Game Boy Development System">RGBDS</abbr>—ASMotor General Information</h1>
<h2>Table of Contents</h2>
<ul>
<li><a href="#license">License</a>
<li><a href="#Author">The Author</a>
<li><a href="#Introduction">Introduction</a>
<li><a href="#Installation">Installation</a>
<li><a href="#Documentation">The Documentation</a>
<li><a href="#History">History</a>
</ul>
<h2 id="license">License</h2>
<p>The <dfn>ASMotor</dfn> package (<a href="asm.htm">xAsm</a>, <a href="link.htm">xLink</a>, <a href="fix.htm">RGBFix</a>, examples and <a href="#Documentation">documentation</a>) is freeware and distributed as is. The author retains his copyright and right to modify the specifications and operation of the software without notice.
<p>In other words this means I encourage you to…
<ul>
<li>use it for whatever purpose even professional work without me charging you a penny
<li>copy it to another person (wholly or in part, though Im sure hed appreciate the whole package) in
whatever form you find suitable
<li>mass-distribute the ASMotor package if it is complete (<a href="asm.htm">xAsm</a>, <a href="link.htm">xLink</a>, <a href="fix.htm">RGBFix</a> and documentation).
<li>contact me if you have any problems
</ul>
<p>This also means you cant…
<ul>
<li>blame me for loss of profit, data, sleep, food or other nasty things through the use or distribution of ASMotor. If
you choose to use ASMotor you do so at your own risk.
<li>expect me to be able to help you should you have a problem related or not to ASMotor.
</ul>
<h2 id="Author">The Author</h2>
<p>Any questions? Write me!
<h3>Address</h3>
<p>
Carsten Sorensen<br>
1 Spring Court<br>
Guildford<br>
Surrey GU2 6QW<br>
United Kingdom<br>
<h3 id="Email">e-mail:</h3>
<ul>
<li><a href="mailto:surfsmurf@matilde.demon.co.uk">surfsmurf@matilde.demon.co.uk</a> (private)
<li><a href="mailto:csorensen@ea.com">csorensen@ea.com</a> (work)
</ul>
<p>Get the latest version from my web page at <a href="http://www.matilde.demon.co.uk">http://www.matilde.demon.co.uk</a>
<h2 id="History">History</h2>
<table>
<caption>The history of ASMotor</caption>
<thead>
<tr>
<th>Version</th>
<th>Dated</th>
<th>Release notes</th>
</tr>
</thead>
<tr>
<td>1.0</td>
<td>03 July 1997</td>
<td>First release</td>
</tr>
<tr>
<td>1.01</td>
<td>20 July 1997</td>
<td><p>RGBDS fixes:</p>
<ul>
<li>RGBFix can now also truncate the ROM-images to a valid size.
<li>RGBAsm supports the LDD and LDI syntax plus [HLD] and [HLI]. LDH is synonymous with LDIO.
<li>Example filenames have been changed to adhere to Jeff Frohweins proposed standard.
</ul>
<p>General fixes:</p>
<ul>
<li>RGBLink knows about big and little endian. Plus it can do range checking on intermediate results in an expression. This is necessary to support
different types of CPUs.
<li>RGBLink <em>didnt</em> know about the special PC symbol “@” so if you used it more than once per sourcefile in an expression the linker had to resolve, things would go horribly wrong.
<li>There was a bug in the macro parameter passing. Any whitespace after the last parameter would be appended to the last parameter. Reported by Jeff Frohwein.
<li>A section stack has been implemented. Look up POPS and PUSHS in the
manual. Jeff Frohweins doing again.
<li>OPT command added for defining and changing some options while assembling.
<li>You can now define which characters are used for the Gameboy graphics integer (`) using the commandline or the new OPT command. Cool idea by (surprise surprise) Jeff Frohwein.
<li>Also, an option stack has been added. Look up POPO and PUSHO in the manual.
<li>Fixed yet another line number bug reported by Jeff Frohwein (when will this guy leave me alone? ;)
</ul>
</td>
<tr>
<td>1.02</td>
<td>22 July 1997</td>
<td><p>General fixes:</p>
<ul>
<li>The lamest typo bug of all time has been fixed. RGBAsm would output a word defined with DW as 4 bytes instead of 2. Jeff Frohwein reported this.
<li>The first line of an included file didnt assemble correctly.
<li>-b option added for setting the characters used for binary constants.
</ul>
</td>
</tr>
<tr>
<td>1.10</td>
<td>21 Sep 1997</td>
<td><p>General fixes:</p>
<ul>
<li>The assembler would crash if you tried to use a macro symbol in an expression. (Jeff Frohwein)
<li>You couldnt use STRCMP, STRLEN and STRIN in relocatable expressions. (Harry P. Mulder)
<li>Relocatable symbols are no longer allowed as arguments to the DEF function.
<li>Finally! A librarian and smart linking has been added.
<li>Bug fixed in the assembler where it would sometimes write out too many bytes for HRAM section definitions.
<li>-z options (set fill value used for uninitialised data) added to the
assembler and linker.
<li>The assembler will now read in any type of ASCII file on any type of OS.
</ul>
</table>
<p>Last updated 08 October 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>RGBDS—ASMotor Documentation</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1><abbr title="Rednex Game Boy Development System">RGBDS</abbr>—ASMotor v1.10 Documentation</h1>
<h2>Table of Contents</h2>
<ul>
<li><a href="geninfo.htm">ASMotor General Information</a>
<li><a href="asm.htm">xASM Documentation</a>
<li><a href="link.htm">xLink Documentation</a>
<li><a href="fix.htm">RGBFix Documentation</a>
<li><a href="rgb0.htm">The RGB0-2 ObjectFileFormat</a>
</ul>
<p>Last updated 21 September 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,118 +0,0 @@
<!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xLink</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1>xLink Documentation</h1>
<h2>Table of Contents</h2>
<ul>
<li><a href="#history"> History</a>
<li><a href="#usage"> Usage</a>
<li><a href="#linkfile"> The Linkfile</a>
<li><a href="#operationtg"> Operation for Gameboy</a>
<li><a href="#smallmode"> Operation for Gameboy small mode</a>
<li><a href="#psion2"> Operation for Psion2 relocatable modules</a>
</ul>
<hr>
<h2 id="history">History</h2>
<table>
<caption>The history of xLink</caption>
<thead>
<tr>
<th scope="col">Version</th>
<th scope="col">Dated</th>
<th scope="col">Release notes</th>
</tr>
</thead>
<tr>
<td>1.0</td>
<td>1 Oct. 96</td>
<td>First release (RGBDS)</td>
</tr>
<tr>
<td>1.01</td>
<td>3 Dec. 96</td>
<td>
<ul>
<li>BANK() didn't work. Fixed.</li>
<li>Sections were quite often output in the wrong order. Fixed.</li>
</ul>
</tr>
<tr>
<td>1.02</td>
<td>12 Feb. 97</td>
<td><a href="#usage">-s switch and mapfile option</A> added</td>
</tr>
<tr>
<td>1.03</td>
<td>23 Mar. 97</td>
<td>
<ul>
<li><a href="#usage">Mapfile</A> now shows BSS, VRAM and HRAM areas</li>
<li>There was a bug regarding <a href="#operation">fixed HOME sections.</a>
</ul></td>
</tr>
<tr>
<td>1.04</td>
<td>03 July 1997</td>
<td>First ASMotor release. Supports big-endian CPUs as well. <a href="#usage">Usage</a> changed to allow for different output fileformats</td>
</tr>
<tr>
<td>1.05</td>
<td>20 July 1997</td>
<td>
<ul>
<li>We can now do range checking on intermediate results in an expression. This is necessary to support different types of CPUs.</li>
<li>RGBLink DIDNT know about the special PC symbol "@" so if you used it more than once per sourcefile in an expression the linker had to resolve, things would go horribly wrong.</li>
</ul>
</td>
<tr>
<td>1.06</td>
<td>21 September 1997</td>
<td><ul><li>Smart linking and library support added
<li>Program renamed to xLink
</ul>
</td>
</table>
<h2 id="usage">Usage</h2>
<pre> xlink [options] linkfile</pre>
<p>Options are preceded by a hyphen (-) and go as follows:
<pre> h : Short help text
m<b>mapfile</b> : Write a mapfile
t : Output target:
tg : Gameboy <a href="#operationtg">ROM image</a> (default)
ts : Gameboy <a href="#smallmode">Small mode (32kB)</a> ROM image
tp : <a href="#psion2">Psion2</a> relocatable module
z<b>HX</b> : Set the byte value (hex format) used for uninitialised data (default is ? for random)
</pre>
<h2 id="linkfile">The Linkfile</h2>
<p>A linkfile is used to tell <B>xLink</B> which objects to include and what the outputname should be. It is in plain ASCII-format.
<pre> # Linkfile for foobar.gb
[Objects]
foo.obj
bar.obj
[Libraries]
mylib.lib
[Output]
foobar.gb</pre>
<p>A line starting with # is ignored.
<p>If you use libraries they will only be included if one of the objects actually reference them. This works on a SECTION level and not on a module level. This means that when you write libraries you can put each subroutine in its own SECTION so only the relevant bits are included.
<h2 id="operationtg">Operation for Gameboy (-tg)</h2>
<p><a href="asm.htm#sections">Sections</a> created with <b>ROM0</b> in the assembler are placed in the GB bank #0 (the fixed bank $0000-$3FFF) in the order they are loaded from the objectfiles specified in the linkfile. So you want the first file in the linkfile to contain your header. <b>ROMX</b> sections are placed in <em>any bank other than #0</em>. This means you have absolutely <em>no</em> control over which sections goes where. This insures minimal slack (unused bytes) at the end of each bank in the image.
<p>Currently the linker doesn't calculate the GB checksums.
You must use <a href="fix.htm">RGBFix</a> to do this.
<h3 id="smallmode">Operation for Gameboy small mode (-ts)</h3>
<p>Small mode forces all <b>ROMX</b> sections to be of type <b>ROM0</b> and increases the <b>ROM0</b> section size from 16kB to 32kB. This also means that <b>ROM0/ROMX</b> sections are written to the final image in the order you have specified on the command line.
<p>Currently the linker doesn't calculate the GB checksums. You must use <a href="fix.htm">RGBFix</a> to do this.
<hr>
<p>Last updated 08 October 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -1,210 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>RGB? Fileformat</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1>The RGB ObjectFileFormats</h1>
<h2>Table of Contents</h2>
<ul>
<li><a href="#background">Background</A>
<li><a href="#filestructure">FileStructure</A>
<li><a href="#rpn">Rpn Data</A>
</ul>
<h2 id="background">Background</h2>
<p>I developed the RGB0 fileformat mainly because I needed a suitable dataformat to hold the output from <a href="asm.htm">xAsm</a> that was powerful to accomodate all the features I needed and also would make it easy for me to add new ones. The reason for documenting it is so people can write converters between it and other formats. Perhaps even develop other compilers for it?</p>
<p>The RGB1 fileformat saw the light of day with the V1.02 of the old RGBDS release because of the addition of fixed sections.</p>
<p>The RGB2 fileformat emerged because I needed to add support for big endian CPUs.</p>
<h2 id="filestructure">FileStructure</h2>
<ul>
<li><dfn>LONG</dfn> is a 32bit integer stored in littleendian format (Intel)
<li><dfn>BYTE</dfn> is an 8bit integer
<li><dfn>STRING</dfn> is a 0terminated string of <b>BYTE</b>
</ul>
<p>Down to business...</p>
<pre>
; There's a header...
BYTE ID[4] ;"RGB0", "RGB1", "RGB2"
LONG NumberOfSymbols ;The number of symbols used in this file
LONG NumberOfSections ;The number of sections used in this file
; Now for some symbols
REPT NumberOfSymbols ;<b>NumberOfSymbols</b> symboldefs follow
STRING Name ;The name of this symbol
BYTE Type ;0 = LOCAL symbol only used in this file
;1 = IMPORT this symbol from elsewhere
;2 = EXPORT this symbol to other objects
IF Type != 1
LONG SectionID ;The section number in which this symbol
;is defined. If -1 this symbol is an EQUate
LONG Value ;The symbols value. If SectionID!=-1 it's the
;offset into that section
ENDC
ENDR
; And I'll be... Sections!
REPT NumberOfSections
LONG Size ;Size in bytes of this section
BYTE Type ;0 = WRAM0
;1 = VRAM
;2 = ROMX
;3 = ROM0
;4 = HRAM
LONG Org ;Only present in RGB1. Address to fix this
;section at. -1 if the linker should
;decide (normal operation)
LONG Bank ;Only present in RGB1. Bank to load this
;section into. -1 if the linker should
;decide (normal operation). This field is
;only valid for ROMX sections.
IF Type==ROMX || Type==ROM0
BYTE Data[Size]
LONG NumberOfPatches
; These types of sections may have patches
REPT NumberOfPatches
STRING SourceFile ;The name of the sourcefile (for
;printing an errormessage)
LONG Line ;The line of the sourcefile
LONG Offset ;Offset into the section where patch
;should be applied
BYTE Type ;0 = BYTE patch
;1 = little endian WORD patch
;2 = little endianLONG patch
;3 = big endian WORD patch (RGB2 and later)
;4 = big endianLONG patch (RGB2 and later)
LONG RPNSize
BYTE RPN[RPNSize] ;RPN definition below
ENDR
ENDC
ENDR</pre>
<h2 id="rpn">Rpn Data</h2>
<p>Expressions in the objectfile are stored as <abbr title="Reverse Polish Notation">RPN</abbr>. This is an expression of the form “2 5 +”. This will first push the value “2” to the stack. Then “5”. The “+” operator pops two arguments from the stack, adds them, and then pushes the result on the stack, effectively replacing the two top arguments with their sum. In the RGB format RPN expressions are stored as <b>BYTE</b>s with some bytes being special prefixes for integers and symbols.</p>
<table>
<caption>RPN Expressions</caption>
<thead>
<tr>
<th scope="col">Byte value</th>
<th scope="col">Meaning</th>
</tr>
</thead>
<tr>
<td>$00</td>
<td>+ operator</td>
</tr>
<tr>
<td>$01</td>
<td>- operator</td>
</tr>
<tr>
<td>$02</td>
<td>* operator</td>
</tr>
<tr>
<td>$03</td>
<td>/ operator</td>
</tr>
<tr>
<td>$04</td>
<td>% operator</td>
</tr>
<tr>
<td>$05</td>
<td>unary -</td>
</tr>
<tr>
<td>$06</td>
<td>| operator</td>
</tr>
<tr>
<td>$07</td>
<td>& operator</td>
</tr>
<tr>
<td>$08</td>
<td>^ operator</td>
</tr>
<tr>
<td>$09</td>
<td>unary ~</td>
</tr>
<tr>
<td>$0A</td>
<td>&& comparison</td>
</tr>
<tr>
<td>$0B</td>
<td>|| comparison</td>
</tr>
<tr>
<td>$0C</td>
<td>unary !</td>
</tr>
<tr>
<td>$0D</td>
<td>== comparison</td>
</tr>
<tr>
<td>$0E</td>
<td>!= comparison</td>
</tr>
<tr>
<td>$0F</td>
<td>&gt comparison</td>
</tr>
<tr>
<td>$10</td>
<td>&lt comparison</td>
</tr>
<tr>
<td>$11</td>
<td>&gt= comparison</td>
</tr>
<tr>
<td>$12</td>
<td>&lt= comparison</td>
</tr>
<tr>
<td>$13</td>
<td>&lt&lt operator</td>
</tr>
<tr>
<td>$14</td>
<td>&gt&gt operator</td>
</tr>
<tr>
<td>$15</td>
<td>BANK() function for Gameboy, a symbol ID follows</td>
</tr>
<tr>
<td>$16</td>
<td>HRAMCheck for Gameboy, check if value is in HRAM and logically and it with 0xFF</td>
</tr>
<tr>
<td>$17</td>
<td>ZeroPageCheck for PC-Engine, check if value is in ZP (0x2000-0x20FF) and logically and it with 0xFF</td>
</tr>
<tr>
<td>$18</td>
<td>RangeCheck. LOW and HIGH signed LONGs follow. Checks a value to see if within the range [LOW;HIGH]. If not, generate an error.
</td>
</tr>
<tr>
<td>$80</td>
<td>LONG integer follows</td>
</tr>
<tr>
<td>$81</td>
<td>Symbol ID follows</td>
</tr>
</table>
<hr>
<p>Last updated 18 July 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
</body>
</html>

View File

@@ -30,6 +30,6 @@ extern struct sSymbol *pPCSymbol;
extern bool oDontExpandStrings;
#define MAXMACROARGS 256
#define MAXINCPATHS 16
#define MAXINCPATHS 128
#endif /* // ASM_H */

View File

@@ -2,7 +2,7 @@
#define RGBDS_ASM_CHARMAP_H
#define MAXCHARMAPS 512
#define CHARMAPLENGTH 8
#define CHARMAPLENGTH 16
struct Charmap {
int count;

View File

@@ -59,9 +59,7 @@ extern void yyunputbytes(ULONG count);
extern YY_BUFFER_STATE pCurrentBuffer;
#ifdef __GNUC__
extern void strupr(char *s);
extern void strlwr(char *s);
#endif
extern void upperstring(char *s);
extern void lowerstring(char *s);
#endif

View File

@@ -4,80 +4,79 @@
n = 8-bit
nn = 16-bit
*ADC A,n : 0xCE
*ADC A,r : 0x88|r
*ADD A,n : 0xC6
*ADD A,r : 0x80|r
*ADD HL,ss : 0x09|(ss<<4)
*ADD SP,n : 0xE8
*AND A,n : 0xE6
*AND A,r : 0xA0|r
*BIT n3,r : 0xCB 0x40|(n3<<3)|r
*CALL cc,nn : 0xC4|(cc<<3)
*CALL nn : 0xCD
*CCF : 0x3F
*CP A,n : 0xFE
*CP A,r : 0xB8|r
*CPL : 0x2F
*DAA : 0x27
*DEC r : 0x05|(r<<3)
*DEC ss : 0x0B|(ss<<4)
*DI : 0xF3
*EI : 0xFB
*EX HL,(SP) : 0xE3
*HALT : 0x76
*INC r : 0x04|(r<<3)
*INC ss : 0x03|(ss<<4)
*JP (HL) : 0xE9
*JP cc,nn : 0xC2|(cc<<3)
*JP nn : 0xC3|(cc<<3)
*JR n : 0x18
*JR cc,n : 0x20|(cc<<3)
*LD (nn),SP : 0x08
*LD ($FF00+C),A : 0xE2
*LD ($FF00+n),A : 0xE0
*LD (nn),A : 0xEA
*LD (rr),A : 0x02|(rr<<4)
*LD A,($FF00+C) : 0xF2
*LD A,($FF00+n) : 0xF0
*LD A,(nn) : 0xFA
*LD A,(rr) : 0x0A|(rr<<4)
*LD HL,(SP+n) : 0xF8
*LD SP,HL : 0xF9
*LD r,n : 0x06|(r<<3)
*LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed
*LD ss,nn : 0x01|(ss<<4)
*NOP : 0x00
*OR A,n : 0xF6
*OR A,r : 0xB0|r
*POP tt : 0xC1|(tt<<4)
*PUSH tt : 0xC5|(tt<<4)
*RES n3,r : 0xCB 0x80|(n3<<3)|r
*RET : 0xC9
*RET cc : 0xC0|(cc<<3)
*RETI : 0xD9
*RL r : 0xCB 0x10|r
*RLA : 0x17
*RLC r : 0xCB 0x00|r
*RLCA : 0x07
*RR r : 0xCB 0x18|r
*RRA : 0x1F
*RRC r : 0xCB 0x08|r
*RRCA : 0x0F
*RST n : 0xC7|n
*SBC A,n : 0xDE
*SBC A,r : 0x98|r
*SCF : 0x37
*SET n3,r : 0xCB 0xC0|(n8<<3)|r
*SLA r : 0xCB 0x20|r
*SRA r : 0xCB 0x28|r
*SRL r : 0xCB 0x38|r
*STOP : 0x10
*SUB A,n : 0xD6
*SUB A,r : 0x90|r
*SWAP r : 0xCB 0x30|r
*XOR A,n : 0xEE
*XOR A,r : 0xA8|r
* ADC A,n : 0xCE
* ADC A,r : 0x88|r
* ADD A,n : 0xC6
* ADD A,r : 0x80|r
* ADD HL,ss : 0x09|(ss<<4)
* ADD SP,n : 0xE8
* AND A,n : 0xE6
* AND A,r : 0xA0|r
* BIT n3,r : 0xCB 0x40|(n3<<3)|r
* CALL cc,nn : 0xC4|(cc<<3)
* CALL nn : 0xCD
* CCF : 0x3F
* CP A,n : 0xFE
* CP A,r : 0xB8|r
* CPL : 0x2F
* DAA : 0x27
* DEC r : 0x05|(r<<3)
* DEC ss : 0x0B|(ss<<4)
* DI : 0xF3
* EI : 0xFB
* HALT : 0x76
* INC r : 0x04|(r<<3)
* INC ss : 0x03|(ss<<4)
* JP HL : 0xE9
* JP cc,nn : 0xC2|(cc<<3)
* JP nn : 0xC3|(cc<<3)
* JR n : 0x18
* JR cc,n : 0x20|(cc<<3)
* LD (nn),SP : 0x08
* LD ($FF00+C),A : 0xE2
* LD ($FF00+n),A : 0xE0
* LD (nn),A : 0xEA
* LD (rr),A : 0x02|(rr<<4) // HL+ and HL- included
* LD A,($FF00+C) : 0xF2
* LD A,($FF00+n) : 0xF0
* LD A,(nn) : 0xFA
* LD A,(rr) : 0x0A|(rr<<4) // HL+ and HL- included
* LD HL,SP+n : 0xF8
* LD SP,HL : 0xF9
* LD r,n : 0x06|(r<<3)
* LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed
* LD ss,nn : 0x01|(ss<<4)
* NOP : 0x00
* OR A,n : 0xF6
* OR A,r : 0xB0|r
* POP tt : 0xC1|(tt<<4)
* PUSH tt : 0xC5|(tt<<4)
* RES n3,r : 0xCB 0x80|(n3<<3)|r
* RET : 0xC9
* RET cc : 0xC0|(cc<<3)
* RETI : 0xD9
* RL r : 0xCB 0x10|r
* RLA : 0x17
* RLC r : 0xCB 0x00|r
* RLCA : 0x07
* RR r : 0xCB 0x18|r
* RRA : 0x1F
* RRC r : 0xCB 0x08|r
* RRCA : 0x0F
* RST n : 0xC7|n
* SBC A,n : 0xDE
* SBC A,r : 0x98|r
* SCF : 0x37
* SET n3,r : 0xCB 0xC0|(n8<<3)|r
* SLA r : 0xCB 0x20|r
* SRA r : 0xCB 0x28|r
* SRL r : 0xCB 0x38|r
* STOP : 0x10 0x00
* SUB A,n : 0xD6
* SUB A,r : 0x90|r
* SWAP r : 0xCB 0x30|r
* XOR A,n : 0xEE
* XOR A,r : 0xA8|r
*/

View File

@@ -2,6 +2,7 @@
#define RGBDS_MAIN_H
#include <stdbool.h>
#include "extern/stdnoreturn.h"
struct sOptions {
char gbgfx[4];
@@ -9,6 +10,8 @@ struct sOptions {
SLONG fillchar;
bool verbose;
bool haltnop;
bool exportall;
bool warnings; /* true to enable warnings, false to disable them. */
//-1 == random
};
@@ -23,8 +26,9 @@ extern void opt_Push(void);
extern void opt_Pop(void);
extern void opt_Parse(char *s);
void fatalerror(const char *fmt, ...);
noreturn void fatalerror(const char *fmt, ...);
void yyerror(const char *fmt, ...);
void warning(const char *fmt, ...);
#define YY_FATAL_ERROR fatalerror

View File

@@ -1,60 +1,6 @@
#ifndef RGBDS_ASM_LINK_H
#define RGBDS_ASM_LINK_H
/* RGB0 .obj format:
*
* Header
* Symbols
* Sections
*
* Header:
* "RGB0"
* LONG NumberOfSymbols
* LONG NumberOfSections
*
* Symbols:
* Symbol[NumberOfSymbols]
*
* Symbol:
* char Name (NULL terminated)
* char nType
* if( nType!=SYM_IMPORT )
* {
* LONG SectionID
* LONG Offset
* }
*
* Sections:
* Section[NumberOfSections]
*
* Section:
* LONG SizeInBytes
* char Type
* if( Type!=WRAM0 )
* {
* char Data[SizeInBytes]
* Patches
* }
*
* Patches:
* LONG NumberOfPatches
* Patch[NumberOfPatches]
*
* Patch:
* char Filename NULL-terminated
* LONG LineNo
* LONG Offset
* char Type
* LONG RpnByteSize
* Rpn[RpnByteSize]
*
* Rpn:
* Operators: 0x00-0x7F
* Constants: 0x80 0x00000000
* Symbols : 0x81 0x00000000
*
*/
enum {
RPN_ADD = 0,
RPN_SUB,
@@ -86,10 +32,6 @@ enum {
RPN_HRAM,
RPN_PCEZP,
RPN_RANGECHECK,
RPN_CONST = 0x80,
RPN_SYM = 0x81
};
@@ -101,7 +43,8 @@ enum {
SECT_ROM0,
SECT_HRAM,
SECT_WRAMX,
SECT_SRAM
SECT_SRAM,
SECT_OAM
};
enum {
@@ -113,8 +56,6 @@ enum {
enum {
PATCH_BYTE = 0,
PATCH_WORD_L,
PATCH_LONG_L,
PATCH_WORD_B,
PATCH_LONG_B
PATCH_LONG_L
};
#endif

View File

@@ -10,6 +10,7 @@ struct Section {
ULONG nPC;
ULONG nOrg;
ULONG nBank;
ULONG nAlign;
struct Section *pNext;
struct Patch *pPatches;
struct Charmap *charmap;
@@ -20,6 +21,7 @@ void out_PrepPass2(void);
void out_SetFileName(char *s);
void out_NewSection(char *pzName, ULONG secttype);
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank);
void out_NewAlignedSection(char *pzName, ULONG secttype, SLONG alignment, SLONG bank);
void out_AbsByte(int b);
void out_AbsByteGroup(char *s, int length);
void out_RelByte(struct Expression * expr);

View File

@@ -15,68 +15,67 @@ ULONG rpn_isPCRelative(struct Expression * expr);
void rpn_Symbol(struct Expression * expr, char *tzSym);
void rpn_Number(struct Expression * expr, ULONG i);
void rpn_LOGNOT(struct Expression * expr, struct Expression * src1);
void
void
rpn_LOGOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGAND(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGGT(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGLT(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGGE(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGLE(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_LOGNE(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_ADD(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_SUB(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_XOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_OR(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_AND(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_SHL(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_SHR(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_MUL(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_DIV(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void
void
rpn_MOD(struct Expression * expr, struct Expression * src1,
struct Expression * src2);
void rpn_HIGH(struct Expression * expr, struct Expression * src);
void rpn_LOW(struct Expression * expr, struct Expression * src);
void rpn_UNNEG(struct Expression * expr, struct Expression * src);
void rpn_UNNOT(struct Expression * expr, struct Expression * src);
UWORD rpn_PopByte(struct Expression * expr);
void rpn_Bank(struct Expression * expr, char *tzSym);
void rpn_Reset(struct Expression * expr);
int
rpn_RangeCheck(struct Expression * expr, struct Expression * src, SLONG low,
SLONG high);
void rpn_CheckHRAM(struct Expression * expr, struct Expression * src1);
#endif

View File

@@ -36,6 +36,7 @@ struct sSymbol {
* not be changed during linking */
ULONG calchash(char *s);
void sym_SetExportAll(BBOOL set);
void sym_PrepPass1(void);
void sym_PrepPass2(void);
void sym_AddLocalReloc(char *tzSym);
@@ -53,7 +54,6 @@ void sym_AddEqu(char *tzSym, SLONG value);
void sym_AddSet(char *tzSym, SLONG value);
void sym_Init(void);
ULONG sym_GetConstantValue(char *s);
void sym_Import(char *tzSym);
ULONG sym_isConstant(char *s);
struct sSymbol *sym_FindSymbol(char *tzName);
void sym_Global(char *tzSym);
@@ -70,5 +70,6 @@ ULONG sym_GetDefinedValue(char *s);
ULONG sym_isDefined(char *tzName);
void sym_Purge(char *tzName);
ULONG sym_isConstDefined(char *tzName);
int sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
#endif

View File

@@ -12,5 +12,5 @@
#define noreturn _declspec( noreturn)
#else
/* unsupported, but no need to throw a fit */
#define noreturn
#define noreturn
#endif

30
include/gfx/gb.h Normal file
View File

@@ -0,0 +1,30 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef RGBDS_GFX_GB_H
#define RGBDS_GFX_GB_H
#include <stdint.h>
#include "gfx/main.h"
void png_to_gb(struct PNGImage png, struct GBImage *gb);
void output_file(struct Options opts, struct GBImage gb);
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size);
void create_tilemap(struct Options opts, struct GBImage *gb, struct Tilemap *tilemap);
void output_tilemap_file(struct Options opts, struct Tilemap tilemap);
void output_palette_file(struct Options opts, struct PNGImage png);
#endif

75
include/gfx/main.h Normal file
View File

@@ -0,0 +1,75 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef RGBDS_GFX_MAIN_H
#define RGBDS_GFX_MAIN_H
#include <png.h>
#include <stdbool.h>
#include <stdint.h>
#include "extern/err.h"
struct Options {
bool debug;
bool verbose;
bool hardfix;
bool fix;
bool horizontal;
bool unique;
int trim;
char *mapfile;
bool mapout;
char *palfile;
bool palout;
char *outfile;
char *infile;
};
struct PNGImage {
png_struct *png;
png_info *info;
png_byte **data;
int width;
int height;
png_byte depth;
png_byte type;
bool horizontal;
int trim;
char *mapfile;
bool mapout;
char *palfile;
bool palout;
};
struct GBImage {
uint8_t *data;
int size;
bool horizontal;
int trim;
};
struct Tilemap {
uint8_t *data;
int size;
};
int depth, colors;
#include "gfx/makepng.h"
#include "gfx/gb.h"
#endif

28
include/gfx/makepng.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef RGBDS_GFX_PNG_H
#define RGBDS_GFX_PNG_H
#include "gfx/main.h"
void input_png_file(struct Options opts, struct PNGImage *img);
void get_text(struct PNGImage *png);
void set_text(struct PNGImage *png);
void output_png_file(struct Options opts, struct PNGImage *png);
void free_png_data(struct PNGImage *png);
#endif

View File

@@ -1,17 +1,33 @@
#ifndef RGBDS_LINK_ASSIGN_H
#define RGBDS_LINK_ASSIGN_H
#include "mylink.h"
#include "types.h"
enum eBankDefine {
BANK_ROM0 = 0,
BANK_WRAM0 = 512,
BANK_WRAMX,
BANK_VRAM = 520,
BANK_HRAM = 522,
BANK_SRAM = 523
enum eBankCount {
BANK_COUNT_ROM0 = 1,
BANK_COUNT_ROMX = 511,
BANK_COUNT_WRAM0 = 1,
BANK_COUNT_WRAMX = 7,
BANK_COUNT_VRAM = 2,
BANK_COUNT_OAM = 1,
BANK_COUNT_HRAM = 1,
BANK_COUNT_SRAM = 16
};
#define MAXBANKS 527
enum eBankDefine {
BANK_ROM0 = 0,
BANK_ROMX = BANK_ROM0 + BANK_COUNT_ROM0,
BANK_WRAM0 = BANK_ROMX + BANK_COUNT_ROMX,
BANK_WRAMX = BANK_WRAM0 + BANK_COUNT_WRAM0,
BANK_VRAM = BANK_WRAMX + BANK_COUNT_WRAMX,
BANK_OAM = BANK_VRAM + BANK_COUNT_VRAM,
BANK_HRAM = BANK_OAM + BANK_COUNT_OAM,
BANK_SRAM = BANK_HRAM + BANK_COUNT_HRAM
};
#define MAXBANKS (BANK_COUNT_ROM0 + BANK_COUNT_ROMX + BANK_COUNT_WRAM0 + BANK_COUNT_WRAMX \
+ BANK_COUNT_VRAM + BANK_COUNT_OAM + BANK_COUNT_HRAM + BANK_COUNT_SRAM)
extern SLONG area_Avail(SLONG bank);
extern void AssignSections(void);
@@ -19,4 +35,16 @@ extern void CreateSymbolTable(void);
extern SLONG MaxBankUsed;
extern SLONG MaxAvail[MAXBANKS];
int
IsSectionNameInUse(const char *name);
void
SetLinkerscriptName(char *tzLinkerscriptFile);
int
IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank);
unsigned int
AssignSectionAddressAndBankByName(const char *name, unsigned int address, int bank);
#endif

View File

@@ -4,6 +4,6 @@
#include "types.h"
extern SLONG fillchar;
extern char smartlinkstartsymbol[256];
extern char *smartlinkstartsymbol;
#endif

View File

@@ -8,8 +8,11 @@
#include "types.h"
extern SLONG options;
#define OPT_SMALL 0x01
#define OPT_TINY 0x01
#define OPT_SMART_C_LINK 0x02
#define OPT_OVERLAY 0x04
#define OPT_CONTWRAM 0x08
#define OPT_DMG_MODE 0x10
enum eRpnData {
RPN_ADD = 0,
@@ -42,10 +45,6 @@ enum eRpnData {
RPN_HRAM,
RPN_PCEZP,
RPN_RANGECHECK,
RPN_CONST = 0x80,
RPN_SYM = 0x81
};
@@ -57,14 +56,17 @@ enum eSectionType {
SECT_ROM0,
SECT_HRAM,
SECT_WRAMX,
SECT_SRAM
SECT_SRAM,
SECT_OAM
};
struct sSection {
SLONG nBank;
SLONG nOrg;
SLONG nAlign;
BBOOL oAssigned;
char *pzName;
SLONG nByteSize;
enum eSectionType Type;
UBYTE *pData;
@@ -92,9 +94,7 @@ struct sSymbol {
enum ePatchType {
PATCH_BYTE = 0,
PATCH_WORD_L,
PATCH_LONG_L,
PATCH_WORD_B,
PATCH_LONG_B
PATCH_LONG_L
};
struct sPatch {

View File

@@ -2,6 +2,7 @@
#define RGBDS_LINK_OUTPUT_H
void out_Setname(char *tzOutputfile);
void out_SetOverlayname(char *tzOverlayfile);
void Output(void);
#endif

37
include/link/script.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef RGBDS_LINK_SCRIPT_H
#define RGBDS_LINK_SCRIPT_H
#include "extern/stdnoreturn.h"
noreturn void script_fatalerror(const char *fmt, ...);
void script_Parse(const char *path);
void script_IncludeFile(const char *path);
int script_IncludeDepthGet(void);
void script_IncludePop(void);
void script_InitSections(void);
void script_SetCurrentSectionType(const char *type, unsigned int bank);
void script_SetAddress(unsigned int addr);
void script_SetAlignment(unsigned int alignment);
void script_OutputSection(const char *section_name);
#endif

View File

@@ -20,6 +20,49 @@
char *tzNewMacro;
ULONG ulNewMacroSize;
void
bankrangecheck(char *name, ULONG secttype, SLONG org, SLONG bank)
{
SLONG minbank, maxbank;
char *stype = NULL;
switch (secttype) {
case SECT_ROMX:
stype = "ROMX";
minbank = 1;
maxbank = 0x1ff;
break;
case SECT_SRAM:
stype = "SRAM";
minbank = 0;
maxbank = 0x1ff;
break;
case SECT_WRAMX:
stype = "WRAMX";
minbank = 1;
maxbank = 7;
break;
case SECT_VRAM:
stype = "VRAM";
minbank = 0;
maxbank = 1;
break;
default:
yyerror("BANK only allowed for "
"ROMX, WRAMX, SRAM, or VRAM sections");
}
if (stype && (bank < minbank || bank > maxbank)) {
yyerror("%s bank value $%x out of range ($%x to $%x)",
stype, bank, minbank, maxbank);
}
if (secttype == SECT_WRAMX) {
bank -= minbank;
}
out_NewAbsSection(name, secttype, org, bank);
}
size_t symvaluetostring(char *dest, size_t maxLength, char *sym)
{
size_t length;
@@ -75,7 +118,6 @@ ULONG str2int2( char *s, int length )
r<<=8;
r|=(UBYTE)(s[i]);
i++;
}
return( r );
}
@@ -99,8 +141,9 @@ void copyrept( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
char *bufferEnd = pCurrentBuffer->pBufferStart + pCurrentBuffer->nBufferSize;
while( *src && level )
while( src < bufferEnd && level )
{
if( instring==0 )
{
@@ -139,6 +182,10 @@ void copyrept( void )
}
}
if (level != 0) {
fatalerror("Unterminated REPT block");
}
len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer;
@@ -174,8 +221,9 @@ void copymacro( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
char *bufferEnd = pCurrentBuffer->pBufferStart + pCurrentBuffer->nBufferSize;
while( *src && level )
while( src < bufferEnd && level )
{
if( instring==0 )
{
@@ -214,6 +262,10 @@ void copymacro( void )
}
}
if (level != 0) {
fatalerror("Unterminated MACRO definition");
}
len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer;
@@ -305,6 +357,10 @@ void if_skip_to_else( void )
}
}
if (level != 0) {
fatalerror("Unterminated IF construct");
}
len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len );
@@ -360,6 +416,10 @@ void if_skip_to_endc( void )
}
}
if (level != 0) {
fatalerror("Unterminated IF construct");
}
len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len );
@@ -399,7 +459,7 @@ void if_skip_to_endc( void )
%left T_OP_MUL T_OP_DIV T_OP_MOD
%left T_OP_NOT
%left T_OP_DEF
%left T_OP_BANK
%left T_OP_BANK T_OP_ALIGN
%left T_OP_SIN
%left T_OP_COS
%left T_OP_TAN
@@ -413,6 +473,7 @@ void if_skip_to_endc( void )
%left T_OP_CEIL
%left T_OP_FLOOR
%token T_OP_HIGH T_OP_LOW
%left T_OP_STRCMP
%left T_OP_STRIN
@@ -452,13 +513,14 @@ void if_skip_to_endc( void )
%token T_POP_POPO
%token T_POP_PUSHO
%token T_POP_OPT
%token T_SECT_WRAM0 T_SECT_VRAM T_SECT_ROMX T_SECT_ROM0 T_SECT_HRAM T_SECT_WRAMX T_SECT_SRAM
%token T_SECT_WRAM0 T_SECT_VRAM T_SECT_ROMX T_SECT_ROM0 T_SECT_HRAM T_SECT_WRAMX T_SECT_SRAM T_SECT_OAM
%token T_SECT_HOME T_SECT_DATA T_SECT_CODE T_SECT_BSS
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
%token T_Z80_BIT
%token T_Z80_CALL T_Z80_CCF T_Z80_CP T_Z80_CPL
%token T_Z80_DAA T_Z80_DEC T_Z80_DI
%token T_Z80_EI T_Z80_EX
%token T_Z80_EI
%token T_Z80_HALT
%token T_Z80_INC
%token T_Z80_JP T_Z80_JR
@@ -476,11 +538,12 @@ void if_skip_to_endc( void )
%token T_Z80_SLA T_Z80_SRA T_Z80_SRL T_Z80_SUB T_Z80_SWAP
%token T_Z80_XOR
%token T_MODE_A T_MODE_B T_MODE_C T_MODE_C_IND T_MODE_D T_MODE_E T_MODE_H T_MODE_L
%token T_TOKEN_A T_TOKEN_B T_TOKEN_C T_TOKEN_D T_TOKEN_E T_TOKEN_H T_TOKEN_L
%token T_MODE_AF
%token T_MODE_BC T_MODE_BC_IND
%token T_MODE_DE T_MODE_DE_IND
%token T_MODE_SP T_MODE_SP_IND
%token T_MODE_C_IND
%token T_MODE_HL T_MODE_HL_IND T_MODE_HL_INDDEC T_MODE_HL_INDINC
%token T_CC_NZ T_CC_Z T_CC_NC
@@ -618,7 +681,7 @@ fail : T_POP_FAIL string {
};
warn : T_POP_WARN string {
yyerror("%s", $2);
warning("%s", $2);
};
shift : T_POP_SHIFT
@@ -709,7 +772,13 @@ import_list : import_list_entry
| import_list_entry ',' import_list
;
import_list_entry : T_ID { sym_Import($1); }
import_list_entry : T_ID {
/* This is done automatically if
* the label isn't found in the
* list of defined symbols. */
if( nPass==1 )
warning("IMPORT is a deprecated keyword with no effect: %s", $1);
}
;
export : T_POP_EXPORT export_list
@@ -931,6 +1000,10 @@ relocconst : T_ID
{ rpn_UNNEG(&$$,&$2); }
| T_OP_NOT relocconst %prec NEG
{ rpn_UNNOT(&$$,&$2); }
| T_OP_HIGH '(' relocconst ')'
{ rpn_HIGH(&$$, &$3); }
| T_OP_LOW '(' relocconst ')'
{ rpn_LOW(&$$, &$3); }
| T_OP_BANK '(' T_ID ')'
{ rpn_Bank(&$$,$3); $$.nVal = 0; }
| T_OP_DEF { oDontExpandStrings = true; } '(' T_ID ')'
@@ -979,9 +1052,14 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
| const T_OP_LOGICNE const { $$ = $1 != $3; }
| const T_OP_ADD const { $$ = $1 + $3; }
| const T_OP_SUB const { $$ = $1 - $3; }
| T_ID T_OP_SUB T_ID { $$ = sym_GetDefinedValue($1) - sym_GetDefinedValue($3); }
| T_ID T_OP_SUB T_ID
{
if (sym_IsRelocDiffDefined($1, $3) == 0)
fatalerror("'%s - %s' not defined.", $1, $3);
$$ = sym_GetDefinedValue($1) - sym_GetDefinedValue($3);
}
| const T_OP_XOR const { $$ = $1 ^ $3; }
| const T_OP_OR const { $$ = $1 | $3; }
| const T_OP_OR const { $$ = $1 | $3; }
| const T_OP_AND const { $$ = $1 & $3; }
| const T_OP_SHL const { $$ = $1 << $3; }
| const T_OP_SHR const { $$ = $1 >> $3; }
@@ -1036,9 +1114,9 @@ string : T_STRING
| T_OP_STRCAT '(' string ',' string ')'
{ strcpy($$,$3); strcat($$,$5); }
| T_OP_STRUPR '(' string ')'
{ strcpy($$,$3); strupr($$); }
{ strcpy($$,$3); upperstring($$); }
| T_OP_STRLWR '(' string ')'
{ strcpy($$,$3); strlwr($$); }
{ strcpy($$,$3); lowerstring($$); }
;
section:
T_POP_SECTION string ',' sectiontype
@@ -1052,78 +1130,28 @@ section:
else
yyerror("Address $%x not 16-bit", $6);
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_ALIGN '[' const ']'
{
out_NewAlignedSection($2, $4, $8, -1);
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
{
if( $4==SECT_ROMX ) {
if( $8>=1 && $8<=0x1ff )
out_NewAbsSection($2,$4,-1,$8);
else
yyerror("ROM bank value $%x out of range (1 to $1ff)", $8);
} else if ($4 == SECT_SRAM) {
if ($8 >= 0 && $8 <= 3) {
out_NewAbsSection($2, $4, -1, $8);
} else {
yyerror("SRAM bank value $%x out of range (0 to 3)", $8);
}
} else if ($4 == SECT_WRAMX) {
if ($8 >= 1 && $8 <= 7) {
out_NewAbsSection($2, $4, -1, $8 - 1);
} else {
yyerror("WRAMX bank value $%x out of range (1 to 7)", $8);
}
} else if ($4 == SECT_VRAM) {
if ($8 >= 0 && $8 <= 1) {
out_NewAbsSection($2, $4, -1, $8);
} else {
yyerror("VRAM bank value $%x out of range (0 to 1)", $8);
}
} else {
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
}
bankrangecheck($2, $4, -1, $8);
}
| T_POP_SECTION string ',' sectiontype '[' const ']' ',' T_OP_BANK '[' const ']'
{
if( $4==SECT_ROMX ) {
if( $6>=0 && $6<0x10000 ) {
if( $11>=1 && $11<=0x1ff )
out_NewAbsSection($2,$4,$6,$11);
else
yyerror("ROM bank value $%x out of range (1 to $1ff)", $11);
} else
yyerror("Address $%x not 16-bit", $6);
} else if ($4 == SECT_SRAM) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 0 && $11 <= 3) {
out_NewAbsSection($2, $4, $6, $11);
} else {
yyerror("SRAM bank value $%x out of range (0 to 3)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else if ($4 == SECT_WRAMX) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 1 && $11 <= 7) {
out_NewAbsSection($2, $4, $6, $11 - 1);
} else {
yyerror("WRAMX bank value $%x out of range (1 to 7)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else if ($4 == SECT_VRAM) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 0 && $11 <= 1) {
out_NewAbsSection($2,$4,$6,$11);
} else {
yyerror("VRAM bank value $%x out of range (0 to 1)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else {
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
if ($6 < 0 || $6 > 0x10000) {
yyerror("Address $%x not 16-bit", $6);
}
bankrangecheck($2, $4, $6, $11);
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_ALIGN '[' const ']' ',' T_OP_BANK '[' const ']'
{
out_NewAlignedSection($2, $4, $8, $13);
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']' ',' T_OP_ALIGN '[' const ']'
{
out_NewAlignedSection($2, $4, $13, $8);
}
;
@@ -1135,6 +1163,23 @@ sectiontype:
| T_SECT_HRAM { $$=SECT_HRAM; }
| T_SECT_WRAMX { $$=SECT_WRAMX; }
| T_SECT_SRAM { $$=SECT_SRAM; }
| T_SECT_OAM { $$=SECT_OAM; }
| T_SECT_HOME {
warning("HOME section name is deprecated, use ROM0 instead.");
$$=SECT_ROM0;
}
| T_SECT_DATA {
warning("DATA section name is deprecated, use ROMX instead.");
$$=SECT_ROMX;
}
| T_SECT_CODE {
warning("CODE section name is deprecated, use ROMX instead.");
$$=SECT_ROMX;
}
| T_SECT_BSS {
warning("BSS section name is deprecated, use WRAM0 instead.");
$$=SECT_WRAM0;
}
;
@@ -1150,7 +1195,6 @@ cpu_command : z80_adc
| z80_dec
| z80_di
| z80_ei
| z80_ex
| z80_halt
| z80_inc
| z80_jp
@@ -1241,12 +1285,6 @@ z80_ei : T_Z80_EI
{ out_AbsByte(0xFB); }
;
z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
{ out_AbsByte(0xE3); }
| T_Z80_EX T_MODE_SP_IND comma T_MODE_HL
{ out_AbsByte(0xE3); }
;
z80_halt: T_Z80_HALT
{
out_AbsByte(0x76);
@@ -1267,7 +1305,11 @@ z80_jp : T_Z80_JP const_16bit
| T_Z80_JP ccode comma const_16bit
{ out_AbsByte(0xC2|($2<<3)); out_RelWord(&$4); }
| T_Z80_JP T_MODE_HL_IND
{ out_AbsByte(0xE9); }
{
out_AbsByte(0xE9);
if( nPass==1 )
warning("'JP [HL]' is obsolete, use 'JP HL' instead.");
}
| T_Z80_JP T_MODE_HL
{ out_AbsByte(0xE9); }
;
@@ -1281,12 +1323,24 @@ z80_jr : T_Z80_JR const_PCrel
z80_ldi : T_Z80_LDI T_MODE_HL_IND comma T_MODE_A
{ out_AbsByte(0x02|(2<<4)); }
| T_Z80_LDI T_MODE_A comma T_MODE_HL
{
out_AbsByte(0x0A|(2<<4));
if( nPass==1 )
warning("'LDI A,HL' is obsolete, use 'LDI A,[HL]' or 'LD A,[HL+] instead.");
}
| T_Z80_LDI T_MODE_A comma T_MODE_HL_IND
{ out_AbsByte(0x0A|(2<<4)); }
;
z80_ldd : T_Z80_LDD T_MODE_HL_IND comma T_MODE_A
{ out_AbsByte(0x02|(3<<4)); }
| T_Z80_LDD T_MODE_A comma T_MODE_HL
{
out_AbsByte(0x0A|(3<<4));
if( nPass==1 )
warning("'LDD A,HL' is obsolete, use 'LDD A,[HL]' or 'LD A,[HL-] instead.");
}
| T_Z80_LDD T_MODE_A comma T_MODE_HL_IND
{ out_AbsByte(0x0A|(3<<4)); }
;
@@ -1421,8 +1475,14 @@ z80_ld_a : T_Z80_LD reg_r comma T_MODE_C_IND
}
;
z80_ld_ss : T_Z80_LD reg_ss comma const_16bit
{ out_AbsByte(0x01|($2<<4)); out_RelWord(&$4); }
z80_ld_ss : T_Z80_LD T_MODE_BC comma const_16bit
{ out_AbsByte(0x01|(REG_BC<<4)); out_RelWord(&$4); }
| T_Z80_LD T_MODE_DE comma const_16bit
{ out_AbsByte(0x01|(REG_DE<<4)); out_RelWord(&$4); }
/*
* HL is taken care of in z80_ld_hl
* SP is taken care of in z80_ld_sp
*/
;
z80_nop : T_Z80_NOP
@@ -1562,10 +1622,33 @@ op_a_n : const_8bit { $$ = $1; }
comma : ','
;
T_MODE_A : T_TOKEN_A
| T_OP_HIGH '(' T_MODE_AF ')'
;
T_MODE_B : T_TOKEN_B
| T_OP_HIGH '(' T_MODE_BC ')'
;
T_MODE_C : T_TOKEN_C
| T_OP_LOW '(' T_MODE_BC ')'
;
T_MODE_D : T_TOKEN_D
| T_OP_HIGH '(' T_MODE_DE ')'
;
T_MODE_E : T_TOKEN_E
| T_OP_LOW '(' T_MODE_DE ')'
;
T_MODE_H : T_TOKEN_H
| T_OP_HIGH '(' T_MODE_HL ')'
;
T_MODE_L : T_TOKEN_L
| T_OP_LOW '(' T_MODE_HL ')'
;
ccode : T_CC_NZ { $$ = CC_NZ; }
| T_CC_Z { $$ = CC_Z; }
| T_CC_NC { $$ = CC_NC; }
| T_MODE_C { $$ = CC_C; }
| T_TOKEN_C { $$ = CC_C; }
;
reg_r : T_MODE_B { $$ = REG_B; }

View File

@@ -1,3 +1,57 @@
/*
* UTF-8 decoder copyright © 20082009 Björn Höhrmann <bjoern@hoehrmann.de>
* http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdint.h>
static const uint8_t utf8d[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
};
uint32_t
decode(uint32_t* state, uint32_t* codep, uint32_t byte) {
uint32_t type = utf8d[byte];
*codep = (*state != 0) ?
(byte & 0x3fu) | (*codep << 6) :
(0xff >> type) & (byte);
*state = utf8d[256 + *state*16 + type];
return *state;
}
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
@@ -28,122 +82,95 @@ struct Charmap globalCharmap = {0};
extern struct Section *pCurrentSection;
int
readUTF8Char(char *destination, char *source)
readUTF8Char(char *dest, char *src)
{
int size;
UBYTE first;
first = source[0];
uint32_t state;
uint32_t codep;
int i;
if(first >= 0xFC)
{
size = 6;
for (i = 0, state = 0;; i++) {
if (decode(&state, &codep, (uint8_t)src[i]) == 1) {
fatalerror("invalid UTF-8 character");
}
dest[i] = src[i];
i++;
if (state == 0) {
dest[i] = '\0';
return i;
}
dest[i] = src[i];
}
else if(first >= 0xF8)
{
size = 5;
}
else if(first >= 0xF0)
{
size = 4;
}
else if(first >= 0xE0)
{
size = 3;
}
else if(first >= 0xC0)
{
size = 2;
}
else if(first != '\0')
{
size = 1;
}
else
{
size = 0;
}
strncpy(destination, source, size);
destination[size] = 0;
return size;
}
int
charmap_Add(char *input, UBYTE output)
{
int i, input_length;
char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0, temp2o = 0;
int i;
size_t input_length;
char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0,
temp2o = 0;
struct Charmap *charmap;
if(pCurrentSection)
{
if(pCurrentSection -> charmap)
{
charmap = pCurrentSection -> charmap;
}
else
{
if((charmap = (struct Charmap *) calloc(1, sizeof(struct Charmap))) == NULL)
{
if (pCurrentSection) {
if (pCurrentSection->charmap) {
charmap = pCurrentSection->charmap;
} else {
if ((charmap = calloc(1, sizeof(struct Charmap))) ==
NULL) {
fatalerror("Not enough memory for charmap");
}
pCurrentSection -> charmap = charmap;
pCurrentSection->charmap = charmap;
}
}
else
{
} else {
charmap = &globalCharmap;
}
if(nPass == 2)
{
return charmap -> count;
if (nPass == 2) {
return charmap->count;
}
if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH)
{
if (charmap->count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH) {
return -1;
}
input_length = strlen(input);
if(input_length > 1)
{
if (input_length > 1) {
i = 0;
while(i < charmap -> count + 1)
{
if(input_length > strlen(charmap -> input[i]))
{
memcpy(temp1i, charmap -> input[i], CHARMAPLENGTH + 1);
memcpy(charmap -> input[i], input, input_length);
temp1o = charmap -> output[i];
charmap -> output[i] = output;
while (i < charmap->count + 1) {
if (input_length > strlen(charmap->input[i])) {
memcpy(temp1i, charmap->input[i],
CHARMAPLENGTH + 1);
memcpy(charmap->input[i], input, input_length);
temp1o = charmap->output[i];
charmap->output[i] = output;
i++;
break;
}
i++;
}
while(i < charmap -> count + 1)
{
memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1);
memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1);
while (i < charmap->count + 1) {
memcpy(temp2i, charmap->input[i], CHARMAPLENGTH + 1);
memcpy(charmap->input[i], temp1i, CHARMAPLENGTH + 1);
memcpy(temp1i, temp2i, CHARMAPLENGTH + 1);
temp2o = charmap -> output[i];
charmap -> output[i] = temp1o;
temp2o = charmap->output[i];
charmap->output[i] = temp1o;
temp1o = temp2o;
i++;
}
memcpy(charmap -> input[charmap -> count + 1], temp1i, CHARMAPLENGTH + 1);
charmap -> output[charmap -> count + 1] = temp1o;
memcpy(charmap->input[charmap->count + 1], temp1i,
CHARMAPLENGTH + 1);
charmap->output[charmap->count + 1] = temp1o;
} else {
memcpy(charmap->input[charmap->count], input, input_length);
charmap->output[charmap->count] = output;
}
else
{
memcpy(charmap -> input[charmap -> count], input, input_length);
charmap -> output[charmap -> count] = output;
}
return ++charmap -> count;
return ++charmap->count;
}
int
int
charmap_Convert(char **input)
{
struct Charmap *charmap;
@@ -152,47 +179,35 @@ charmap_Convert(char **input)
char *buffer;
int i, j, length;
if(pCurrentSection && pCurrentSection -> charmap)
{
charmap = pCurrentSection -> charmap;
}
else
{
if (pCurrentSection && pCurrentSection->charmap) {
charmap = pCurrentSection->charmap;
} else {
charmap = &globalCharmap;
}
if((buffer = (char *) malloc(strlen(*input))) == NULL)
{
if ((buffer = malloc(strlen(*input))) == NULL) {
fatalerror("Not enough memory for buffer");
}
length = 0;
while(**input)
{
while (**input) {
j = 0;
for(i = 0; i < charmap -> count; i++)
{
j = strlen(charmap -> input[i]);
if(memcmp(*input, charmap -> input[i], j) == 0)
{
outchar[0] = charmap -> output[i];
for (i = 0; i < charmap->count; i++) {
j = strlen(charmap->input[i]);
if (memcmp(*input, charmap->input[i], j) == 0) {
outchar[0] = charmap->output[i];
outchar[1] = 0;
break;
}
j = 0;
}
if(!j)
{
if (!j) {
j = readUTF8Char(outchar, *input);
}
if(!outchar[0])
{
if (!outchar[0]) {
buffer[length++] = 0;
}
else
{
for(i = 0; outchar[i]; i++)
{
} else {
for (i = 0; outchar[i]; i++) {
buffer[length++] = outchar[i];
}
}
@@ -201,4 +216,3 @@ charmap_Convert(char **input)
*input = buffer;
return length;
}

View File

@@ -47,7 +47,7 @@ ULONG ulMacroReturnValue;
/*
* Context push and pop
*/
void
void
pushcontext(void)
{
struct sContext **ppFileStack;
@@ -84,7 +84,7 @@ pushcontext(void)
fatalerror("No memory for context");
}
int
int
popcontext(void)
{
struct sContext *pLastFile, **ppLastFile;
@@ -148,7 +148,7 @@ popcontext(void)
return (1);
}
int
int
yywrap(void)
{
return (popcontext());
@@ -157,7 +157,7 @@ yywrap(void)
/*
* Dump the context stack to stderr
*/
void
void
fstk_Dump(void)
{
struct sContext *pLastFile;
@@ -176,10 +176,18 @@ fstk_Dump(void)
/*
* Extra includepath stuff
*/
void
void
fstk_AddIncludePath(char *s)
{
strcpy(IncludePaths[NextIncPath++], s);
if (NextIncPath == MAXINCPATHS) {
fatalerror("Too many include directories passed from command line");
return;
}
if (strlcpy(IncludePaths[NextIncPath++], s, _MAX_PATH) >= _MAX_PATH) {
fatalerror("Include path too long '%s'",s);
return;
}
}
FILE *
@@ -194,7 +202,7 @@ fstk_FindFile(char *fname)
}
for (i = 0; i < NextIncPath; ++i) {
if (strlcpy(path, IncludePaths[i], sizeof path) >=
if (strlcpy(path, IncludePaths[i], sizeof path) >=
sizeof path) {
continue;
}
@@ -243,7 +251,7 @@ fstk_RunInclude(char *tzFileName)
/*
* Set up a macro for parsing
*/
ULONG
ULONG
fstk_RunMacro(char *s)
{
struct sSymbol *sym;
@@ -270,7 +278,7 @@ fstk_RunMacro(char *s)
/*
* Set up a macroargument for parsing
*/
void
void
fstk_RunMacroArg(SLONG s)
{
char *sym;
@@ -293,7 +301,7 @@ fstk_RunMacroArg(SLONG s)
/*
* Set up a stringequate for parsing
*/
void
void
fstk_RunString(char *s)
{
struct sSymbol *pSym;
@@ -312,7 +320,7 @@ fstk_RunString(char *s)
/*
* Set up a repeat block for parsing
*/
void
void
fstk_RunRept(ULONG count)
{
if (count) {
@@ -338,7 +346,9 @@ fstk_Init(char *s)
{
char tzFileName[_MAX_PATH + 1];
sym_AddString("__FILE__", s);
char tzSymFileName[_MAX_PATH + 1 + 2];
snprintf(tzSymFileName, sizeof(tzSymFileName), "\"%s\"", s);
sym_AddString("__FILE__", tzSymFileName);
strcpy(tzFileName, s);
pFileStack = NULL;

View File

@@ -17,7 +17,7 @@ bool oDontExpandStrings = false;
SLONG nGBGfxID = -1;
SLONG nBinaryID = -1;
SLONG
SLONG
gbgfx2bin(char ch)
{
SLONG i;
@@ -31,7 +31,7 @@ gbgfx2bin(char ch)
return (0);
}
SLONG
SLONG
binary2bin(char ch)
{
SLONG i;
@@ -45,7 +45,7 @@ binary2bin(char ch)
return (0);
}
SLONG
SLONG
char2bin(char ch)
{
if (ch >= 'a' && ch <= 'f')
@@ -62,7 +62,7 @@ char2bin(char ch)
typedef SLONG(*x2bin) (char ch);
SLONG
SLONG
ascii2bin(char *s)
{
SLONG radix = 10;
@@ -97,7 +97,7 @@ ascii2bin(char *s)
while (*s != '\0') {
c = convertfunc(*s++);
result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
result = result * 2 + ((c & 2) << 7) + (c & 1);
}
} else {
while (*s != '\0')
@@ -107,7 +107,7 @@ ascii2bin(char *s)
return (result);
}
ULONG
ULONG
ParseFixedPoint(char *s, ULONG size)
{
//char dest[256];
@@ -133,7 +133,7 @@ ParseFixedPoint(char *s, ULONG size)
return (1);
}
ULONG
ULONG
ParseNumber(char *s, ULONG size)
{
char dest[256];
@@ -145,7 +145,7 @@ ParseNumber(char *s, ULONG size)
return (1);
}
ULONG
ULONG
ParseSymbol(char *src, ULONG size)
{
char dest[MAXSYMLEN + 1];
@@ -203,7 +203,7 @@ ParseSymbol(char *src, ULONG size)
}
}
ULONG
ULONG
PutMacroArg(char *src, ULONG size)
{
char *s;
@@ -221,7 +221,7 @@ PutMacroArg(char *src, ULONG size)
return (0);
}
ULONG
ULONG
PutUniqueArg(char *src, ULONG size)
{
char *s;
@@ -267,6 +267,7 @@ struct sLexInitString staticstrings[] = {
{"def", T_OP_DEF},
{"bank", T_OP_BANK},
{"align", T_OP_ALIGN},
{"round", T_OP_ROUND},
{"ceil", T_OP_CEIL},
@@ -281,6 +282,9 @@ struct sLexInitString staticstrings[] = {
{"atan", T_OP_ATAN},
{"atan2", T_OP_ATAN2},
{"high", T_OP_HIGH},
{"low", T_OP_LOW},
{"strcmp", T_OP_STRCMP},
{"strin", T_OP_STRIN},
{"strsub", T_OP_STRSUB},
@@ -301,9 +305,6 @@ struct sLexInitString staticstrings[] = {
{"ds", T_POP_DS},
{NAME_DB, T_POP_DB},
{NAME_DW, T_POP_DW},
#ifdef NAME_DL
{NAME_DL, T_POP_DL},
#endif
{"section", T_POP_SECTION},
{"purge", T_POP_PURGE},
@@ -331,22 +332,22 @@ struct sLexInitString staticstrings[] = {
{"endc", T_POP_ENDC},
{"wram0", T_SECT_WRAM0},
{"bss", T_SECT_WRAM0}, /* deprecated */
{"vram", T_SECT_VRAM},
{"code", T_SECT_ROMX}, /* deprecated */
{"data", T_SECT_ROMX}, /* deprecated */
{"romx", T_SECT_ROMX},
{"home", T_SECT_ROM0}, /* deprecated */
{"rom0", T_SECT_ROM0},
{"hram", T_SECT_HRAM},
{"wramx", T_SECT_WRAMX},
{"sram", T_SECT_SRAM},
{"oam", T_SECT_OAM},
/* Deprecated section type names */
{"home", T_SECT_HOME},
{"code", T_SECT_CODE},
{"data", T_SECT_DATA},
{"bss", T_SECT_BSS},
{NAME_RB, T_POP_RB},
{NAME_RW, T_POP_RW},
#ifdef NAME_RL
{NAME_RL, T_POP_RL},
#endif
{"equ", T_POP_EQU},
{"equs", T_POP_EQUS},
@@ -388,7 +389,7 @@ struct sLexFloat tMacroUniqueToken = {
T_LEX_MACROUNIQUE
};
void
void
setuplex(void)
{
ULONG id;

View File

@@ -39,9 +39,8 @@ ULONG tFloatingChars[256];
ULONG nFloating;
enum eLexerState lexerstate = LEX_STATE_NORMAL;
#ifdef __GNUC__
void
strupr(char *s)
void
upperstring(char *s)
{
while (*s) {
*s = toupper(*s);
@@ -49,28 +48,28 @@ strupr(char *s)
}
}
void
strlwr(char *s)
void
lowerstring(char *s)
{
while (*s) {
*s = tolower(*s);
s += 1;
}
}
#endif
void
void
yyskipbytes(ULONG count)
{
pLexBuffer += count;
}
void
void
yyunputbytes(ULONG count)
{
pLexBuffer -= count;
}
void
void
yyunput(char c)
{
if (pLexBuffer <= pLexBufferRealStart)
@@ -79,7 +78,7 @@ yyunput(char c)
*(--pLexBuffer) = c;
}
void
void
yyunputstr(char *s)
{
int i, len;
@@ -93,26 +92,26 @@ yyunputstr(char *s)
*(--pLexBuffer) = s[i];
}
void
void
yy_switch_to_buffer(YY_BUFFER_STATE buf)
{
pCurrentBuffer = buf;
}
void
void
yy_set_state(enum eLexerState i)
{
lexerstate = i;
}
void
void
yy_delete_buffer(YY_BUFFER_STATE buf)
{
free(buf->pBufferStart - SAFETYMARGIN);
free(buf);
}
YY_BUFFER_STATE
YY_BUFFER_STATE
yy_scan_bytes(char *mem, ULONG size)
{
YY_BUFFER_STATE pBuffer;
@@ -133,7 +132,7 @@ yy_scan_bytes(char *mem, ULONG size)
return (NULL);
}
YY_BUFFER_STATE
YY_BUFFER_STATE
yy_create_buffer(FILE * f)
{
YY_BUFFER_STATE pBuffer;
@@ -220,7 +219,7 @@ lex_CheckCharacterRange(UWORD start, UWORD end)
}
}
void
void
lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -231,7 +230,7 @@ lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end)
}
}
void
void
lex_FloatAddRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -242,7 +241,7 @@ lex_FloatAddRange(ULONG id, UWORD start, UWORD end)
}
}
void
void
lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -253,7 +252,7 @@ lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end)
}
}
void
void
lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -264,7 +263,7 @@ lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end)
}
}
void
void
lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -275,7 +274,7 @@ lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end)
}
}
void
void
lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end)
{
lex_CheckCharacterRange(start, end);
@@ -303,7 +302,7 @@ lexgetfloat(ULONG nFloatMask)
return (&tLexFloat[i]);
}
ULONG
ULONG
lexcalchash(char *s)
{
ULONG hash = 0;
@@ -315,7 +314,7 @@ lexcalchash(char *s)
return (hash % LEXHASHSIZE);
}
void
void
lex_Init(void)
{
ULONG i;
@@ -334,7 +333,7 @@ lex_Init(void)
nFloating = 0;
}
void
void
lex_AddStrings(struct sLexInitString * lex)
{
while (lex->tzName) {
@@ -352,7 +351,7 @@ lex_AddStrings(struct sLexInitString * lex)
(*ppHash)->nToken = lex->nToken;
(*ppHash)->pNext = NULL;
strupr((*ppHash)->tzName);
upperstring((*ppHash)->tzName);
if ((*ppHash)->nNameLength > nLexMaxLength)
nLexMaxLength = (*ppHash)->nNameLength;
@@ -436,10 +435,10 @@ yylex_GetLongestFixed()
size_t
CopyMacroArg(char *dest, size_t maxLength, char c)
{
int i;
size_t i;
char *s;
int argNum;
switch (c) {
case '1':
case '2':
@@ -566,6 +565,15 @@ yylex_ReadQuotedString()
case '"':
ch = '"';
break;
case ',':
ch = ',';
break;
case '{':
ch = '{';
break;
case '}':
ch = '}';
break;
default:
maxLength = MAXSTRLEN - index;
length = CopyMacroArg(&yylval.tzString[index], maxLength, ch);
@@ -699,6 +707,15 @@ yylex_MACROARGS()
case '\\':
ch = '\\';
break;
case ',':
ch = ',';
break;
case '{':
ch = '{';
break;
case '}':
ch = '}';
break;
default:
maxLength = MAXSTRLEN - index;
length = CopyMacroArg(&yylval.tzString[index], maxLength, ch);
@@ -707,7 +724,7 @@ yylex_MACROARGS()
index += length;
else
fatalerror("Illegal character escape '%c'", ch);
ch = 0;
break;
}
@@ -740,7 +757,7 @@ yylex_MACROARGS()
return 0;
}
ULONG
ULONG
yylex(void)
{
switch (lexerstate) {

View File

@@ -17,7 +17,6 @@ struct sLexInitString localstrings[] = {
{"dec", T_Z80_DEC},
{"di", T_Z80_DI},
{"ei", T_Z80_EI},
{"ex", T_Z80_EX},
{"halt", T_Z80_HALT},
{"inc", T_Z80_INC},
{"jp", T_Z80_JP},
@@ -60,30 +59,31 @@ struct sLexInitString localstrings[] = {
{"nz", T_CC_NZ},
{"z", T_CC_Z},
{"nc", T_CC_NC},
/* { "c", T_MODE_C }, */
/* { "c", T_TOKEN_C }, */
{"[bc]", T_MODE_BC_IND},
{"[de]", T_MODE_DE_IND},
{"[hl]", T_MODE_HL_IND},
{"[hl+]", T_MODE_HL_INDINC},
{"[hl-]", T_MODE_HL_INDDEC},
{"[hli]", T_MODE_HL_INDINC},
{"[hld]", T_MODE_HL_INDDEC},
{"hl", T_MODE_HL},
{"af", T_MODE_AF},
{"[bc]", T_MODE_BC_IND},
{"bc", T_MODE_BC},
{"[de]", T_MODE_DE_IND},
{"de", T_MODE_DE},
{"[sp]", T_MODE_SP_IND},
{"af", T_MODE_AF},
{"bc", T_MODE_BC},
{"de", T_MODE_DE},
{"hl", T_MODE_HL},
{"sp", T_MODE_SP},
{"a", T_MODE_A},
{"b", T_MODE_B},
{"[$ff00+c]", T_MODE_C_IND},
{"[c]", T_MODE_C_IND},
{"c", T_MODE_C},
{"d", T_MODE_D},
{"e", T_MODE_E},
{"h", T_MODE_H},
{"l", T_MODE_L},
{"[$ff00+c]", T_MODE_C_IND},
{"a", T_TOKEN_A},
{"b", T_TOKEN_B},
{"c", T_TOKEN_C},
{"d", T_TOKEN_D},
{"e", T_TOKEN_E},
{"h", T_TOKEN_H},
{"l", T_TOKEN_L},
{NULL, 0}
};

View File

@@ -20,8 +20,6 @@ int cldefines_index;
int cldefines_size;
char **cldefines;
char *progname;
clock_t nStartClock, nEndClock;
SLONG nLineNo;
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
@@ -42,7 +40,7 @@ struct sOptionStackEntry {
struct sOptionStackEntry *pOptionStack = NULL;
void
void
opt_SetCurrentOptions(struct sOptions * pOpt)
{
if (nGBGfxID != -1) {
@@ -105,7 +103,7 @@ opt_SetCurrentOptions(struct sOptions * pOpt)
}
}
void
void
opt_Parse(char *s)
{
struct sOptions newopt;
@@ -154,7 +152,7 @@ opt_Parse(char *s)
opt_SetCurrentOptions(&newopt);
}
void
void
opt_Push(void)
{
struct sOptionStackEntry *pOpt;
@@ -167,7 +165,7 @@ opt_Push(void)
fatalerror("No memory for option stack");
}
void
void
opt_Pop(void)
{
if (pOptionStack) {
@@ -226,15 +224,15 @@ opt_ParseDefines()
void
verror(const char *fmt, va_list args)
{
fprintf(stderr, "ERROR:\t");
fprintf(stderr, "ERROR: ");
fstk_Dump();
fprintf(stderr, " :\n\t");
fprintf(stderr, ":\n\t");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
nErrors += 1;
}
void
void
yyerror(const char *fmt, ...)
{
va_list args;
@@ -243,7 +241,7 @@ yyerror(const char *fmt, ...)
va_end(args);
}
void
void
fatalerror(const char *fmt, ...)
{
va_list args;
@@ -253,16 +251,34 @@ fatalerror(const char *fmt, ...)
exit(5);
}
static void
void
warning(const char *fmt, ...)
{
if (!CurrentOptions.warnings)
return;
va_list args;
va_start(args, fmt);
fprintf(stderr, "warning: ");
fstk_Dump();
fprintf(stderr, ":\n\t");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}
static void
usage(void)
{
printf(
"Usage: rgbasm [-hv] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
"Usage: rgbasm [-hvE] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
" [-o outfile] [-p pad_value] file.asm\n");
exit(1);
}
int
int
main(int argc, char *argv[])
{
int ch;
@@ -283,8 +299,6 @@ main(int argc, char *argv[])
if (argc == 1)
usage();
progname = argv[0];
/* yydebug=1; */
DefaultOptions.gbgfx[0] = '0';
@@ -296,12 +310,14 @@ main(int argc, char *argv[])
DefaultOptions.fillchar = 0;
DefaultOptions.verbose = false;
DefaultOptions.haltnop = true;
DefaultOptions.exportall = false;
DefaultOptions.warnings = true;
opt_SetCurrentOptions(&DefaultOptions);
newopt = CurrentOptions;
while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:v")) != -1) {
while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:vEw")) != -1) {
switch (ch) {
case 'b':
if (strlen(optarg) == 2) {
@@ -348,6 +364,12 @@ main(int argc, char *argv[])
case 'v':
newopt.verbose = true;
break;
case 'E':
newopt.exportall = true;
break;
case 'w':
newopt.warnings = false;
break;
default:
usage();
}
@@ -379,6 +401,7 @@ main(int argc, char *argv[])
nPass = 1;
nErrors = 0;
sym_PrepPass1();
sym_SetExportAll(CurrentOptions.exportall);
fstk_Init(tzMainfile);
opt_ParseDefines();

View File

@@ -18,7 +18,7 @@
/*
* Define the _PI symbol
*/
void
void
math_DefinePI(void)
{
sym_AddEqu("_PI", double2fix(PI));
@@ -27,7 +27,7 @@ math_DefinePI(void)
/*
* Print a fixed point value
*/
void
void
math_Print(SLONG i)
{
if (i >= 0)
@@ -41,7 +41,7 @@ math_Print(SLONG i)
/*
* Calculate sine
*/
SLONG
SLONG
math_Sin(SLONG i)
{
return (double2fix(sin(fix2double(i) * 2 * PI / 65536)));
@@ -50,7 +50,7 @@ math_Sin(SLONG i)
/*
* Calculate cosine
*/
SLONG
SLONG
math_Cos(SLONG i)
{
return (double2fix(cos(fix2double(i) * 2 * PI / 65536)));
@@ -59,7 +59,7 @@ math_Cos(SLONG i)
/*
* Calculate tangent
*/
SLONG
SLONG
math_Tan(SLONG i)
{
return (double2fix(tan(fix2double(i) * 2 * PI / 65536)));
@@ -68,7 +68,7 @@ math_Tan(SLONG i)
/*
* Calculate arcsine
*/
SLONG
SLONG
math_ASin(SLONG i)
{
return (double2fix(asin(fix2double(i)) / 2 / PI * 65536));
@@ -77,7 +77,7 @@ math_ASin(SLONG i)
/*
* Calculate arccosine
*/
SLONG
SLONG
math_ACos(SLONG i)
{
return (double2fix(acos(fix2double(i)) / 2 / PI * 65536));
@@ -86,7 +86,7 @@ math_ACos(SLONG i)
/*
* Calculate arctangent
*/
SLONG
SLONG
math_ATan(SLONG i)
{
return (double2fix(atan(fix2double(i)) / 2 / PI * 65536));
@@ -95,7 +95,7 @@ math_ATan(SLONG i)
/*
* Calculate atan2
*/
SLONG
SLONG
math_ATan2(SLONG i, SLONG j)
{
return (double2fix
@@ -105,7 +105,7 @@ math_ATan2(SLONG i, SLONG j)
/*
* Multiplication
*/
SLONG
SLONG
math_Mul(SLONG i, SLONG j)
{
return (double2fix(fix2double(i) * fix2double(j)));
@@ -114,7 +114,7 @@ math_Mul(SLONG i, SLONG j)
/*
* Division
*/
SLONG
SLONG
math_Div(SLONG i, SLONG j)
{
return (double2fix(fix2double(i) / fix2double(j)));
@@ -123,7 +123,7 @@ math_Div(SLONG i, SLONG j)
/*
* Round
*/
SLONG
SLONG
math_Round(SLONG i)
{
return double2fix(round(fix2double(i)));
@@ -132,7 +132,7 @@ math_Round(SLONG i)
/*
* Ceil
*/
SLONG
SLONG
math_Ceil(SLONG i)
{
return double2fix(ceil(fix2double(i)));
@@ -141,7 +141,7 @@ math_Ceil(SLONG i)
/*
* Floor
*/
SLONG
SLONG
math_Floor(SLONG i)
{
return double2fix(floor(fix2double(i)));

View File

@@ -53,7 +53,7 @@ struct SectionStackEntry *pSectionStack = NULL;
/*
* Section stack routines
*/
void
void
out_PushSection(void)
{
struct SectionStackEntry *pSect;
@@ -66,7 +66,7 @@ out_PushSection(void)
fatalerror("No memory for section stack");
}
void
void
out_PopSection(void)
{
if (pSectionStack) {
@@ -83,7 +83,7 @@ out_PopSection(void)
/*
* Count the number of symbols used in this object
*/
ULONG
ULONG
countsymbols(void)
{
struct PatchSymbol *pSym;
@@ -102,7 +102,7 @@ countsymbols(void)
/*
* Count the number of sections used in this object
*/
ULONG
ULONG
countsections(void)
{
struct Section *pSect;
@@ -121,7 +121,7 @@ countsections(void)
/*
* Count the number of patches used in this object
*/
ULONG
ULONG
countpatches(struct Section * pSect)
{
struct Patch *pPatch;
@@ -139,7 +139,7 @@ countpatches(struct Section * pSect)
/*
* Write a long to a file (little-endian)
*/
void
void
fputlong(ULONG i, FILE * f)
{
fputc(i, f);
@@ -151,7 +151,7 @@ fputlong(ULONG i, FILE * f)
/*
* Write a NULL-terminated string to a file
*/
void
void
fputstring(char *s, FILE * f)
{
while (*s)
@@ -162,7 +162,7 @@ fputstring(char *s, FILE * f)
/*
* Return a section's ID
*/
ULONG
ULONG
getsectid(struct Section * pSect)
{
struct Section *sec;
@@ -184,7 +184,7 @@ getsectid(struct Section * pSect)
/*
* Write a patch to a file
*/
void
void
writepatch(struct Patch * pPatch, FILE * f)
{
fputstring(pPatch->tzFilename, f);
@@ -198,20 +198,20 @@ writepatch(struct Patch * pPatch, FILE * f)
/*
* Write a section to a file
*/
void
void
writesection(struct Section * pSect, FILE * f)
{
//printf("SECTION: %s, ID: %d\n", pSect->pzName, getsectid(pSect));
fputstring(pSect->pzName, f);
fputlong(pSect->nPC, f);
fputc(pSect->nType, f);
fputlong(pSect->nOrg, f);
//RGB1 addition
fputlong(pSect->nBank, f);
fputlong(pSect->nAlign, f);
fputlong(pSect->nBank, f);
//RGB1 addition
if ((pSect->nType == SECT_ROM0)
if ((pSect->nType == SECT_ROM0)
|| (pSect->nType == SECT_ROMX)) {
struct Patch *pPatch;
@@ -229,7 +229,7 @@ writesection(struct Section * pSect, FILE * f)
/*
* Write a symbol to a file
*/
void
void
writesymbol(struct sSymbol * pSym, FILE * f)
{
char symname[MAXSYMLEN * 2 + 1];
@@ -243,25 +243,27 @@ writesymbol(struct sSymbol * pSym, FILE * f)
offset = 0;
sectid = -1;
type = SYM_IMPORT;
} else if (pSym->nType & SYMF_EXPORT) {
/* Symbol should be exported */
strcpy(symname, pSym->tzName);
type = SYM_EXPORT;
offset = pSym->nValue;
if (pSym->nType & SYMF_CONST)
sectid = -1;
else
sectid = getsectid(pSym->pSection);
} else {
/* Symbol is local to this file */
if (pSym->nType & SYMF_LOCAL) {
strcpy(symname, pSym->pScope->tzName);
strcat(symname, pSym->tzName);
} else
strcpy(symname, pSym->tzName);
type = SYM_LOCAL;
offset = pSym->nValue;
sectid = getsectid(pSym->pSection);
if (pSym->nType & SYMF_EXPORT) {
/* Symbol should be exported */
type = SYM_EXPORT;
offset = pSym->nValue;
if (pSym->nType & SYMF_CONST)
sectid = -1;
else
sectid = getsectid(pSym->pSection);
} else {
/* Symbol is local to this file */
type = SYM_LOCAL;
offset = pSym->nValue;
sectid = getsectid(pSym->pSection);
}
}
fputstring(symname, f);
@@ -276,7 +278,7 @@ writesymbol(struct sSymbol * pSym, FILE * f)
/*
* Add a symbol to the object
*/
ULONG
ULONG
addsymbol(struct sSymbol * pSym)
{
struct PatchSymbol *pPSym, **ppPSym;
@@ -309,7 +311,7 @@ addsymbol(struct sSymbol * pSym)
/*
* Add all exported symbols to the object
*/
void
void
addexports(void)
{
int i;
@@ -349,7 +351,7 @@ allocpatch(void)
/*
* Create a new patch (includes the rpn expr)
*/
void
void
createpatch(ULONG type, struct Expression * expr)
{
struct Patch *pPatch;
@@ -425,7 +427,7 @@ createpatch(ULONG type, struct Expression * expr)
/*
* A quick check to see if we have an initialized section
*/
void
void
checksection(void)
{
if (pCurrentSection)
@@ -438,7 +440,7 @@ checksection(void)
* A quick check to see if we have an initialized section that can contain
* this much initialized data
*/
void
void
checkcodesection(SLONG size)
{
checksection();
@@ -476,7 +478,7 @@ checkcodesection(SLONG size)
/*
* Write an objectfile
*/
void
void
out_WriteObject(void)
{
FILE *f;
@@ -487,7 +489,7 @@ out_WriteObject(void)
struct PatchSymbol *pSym;
struct Section *pSect;
fwrite("RGB2", 1, 4, f);
fwrite("RGB4", 1, 4, f);
fputlong(countsymbols(), f);
fputlong(countsections(), f);
@@ -510,7 +512,7 @@ out_WriteObject(void)
/*
* Prepare for pass #2
*/
void
void
out_PrepPass2(void)
{
struct Section *pSect;
@@ -527,7 +529,7 @@ out_PrepPass2(void)
/*
* Set the objectfilename
*/
void
void
out_SetFileName(char *s)
{
tzObjectname = s;
@@ -543,7 +545,7 @@ out_SetFileName(char *s)
* Find a section by name and type. If it doesn't exist, create it
*/
struct Section *
out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank, SLONG alignment)
{
struct Section *pSect, **ppSect;
@@ -554,7 +556,8 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
if (strcmp(pzName, pSect->pzName) == 0) {
if (secttype == pSect->nType
&& ((ULONG) org) == pSect->nOrg
&& ((ULONG) bank) == pSect->nBank) {
&& ((ULONG) bank) == pSect->nBank
&& ((ULONG) alignment == pSect->nAlign)) {
return (pSect);
} else
fatalerror
@@ -571,6 +574,7 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
pSect->nPC = 0;
pSect->nOrg = org;
pSect->nBank = bank;
pSect->nAlign = alignment;
pSect->pNext = NULL;
pSect->pPatches = NULL;
pSect->charmap = NULL;
@@ -591,7 +595,7 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
/*
* Set the current section
*/
void
void
out_SetCurrentSection(struct Section * pSect)
{
pCurrentSection = pSect;
@@ -604,25 +608,37 @@ out_SetCurrentSection(struct Section * pSect)
/*
* Set the current section by name and type
*/
void
void
out_NewSection(char *pzName, ULONG secttype)
{
out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1));
out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1, 1));
}
/*
* Set the current section by name and type
*/
void
void
out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
{
out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank));
out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank, 1));
}
/*
* Set the current section by name and type, using a given byte alignment
*/
void
out_NewAlignedSection(char *pzName, ULONG secttype, SLONG alignment, SLONG bank)
{
if (alignment < 0 || alignment > 16) {
yyerror("Alignment must be between 0-16 bits.");
}
out_SetCurrentSection(out_FindSection(pzName, secttype, -1, bank, 1 << alignment));
}
/*
* Output an absolute byte
*/
void
void
out_AbsByte(int b)
{
checkcodesection(1);
@@ -635,7 +651,7 @@ out_AbsByte(int b)
pPCSymbol->nValue += 1;
}
void
void
out_AbsByteGroup(char *s, int length)
{
checkcodesection(length);
@@ -646,7 +662,7 @@ out_AbsByteGroup(char *s, int length)
/*
* Skip this many bytes
*/
void
void
out_Skip(int skip)
{
checksection();
@@ -665,7 +681,7 @@ out_Skip(int skip)
/*
* Output a NULL terminated string (excluding the NULL-character)
*/
void
void
out_String(char *s)
{
checkcodesection(strlen(s));
@@ -678,7 +694,7 @@ out_String(char *s)
* is an absolute value in disguise.
*/
void
void
out_RelByte(struct Expression * expr)
{
checkcodesection(1);
@@ -699,7 +715,7 @@ out_RelByte(struct Expression * expr)
/*
* Output an absolute word
*/
void
void
out_AbsWord(int b)
{
checkcodesection(2);
@@ -717,7 +733,7 @@ out_AbsWord(int b)
* Output a relocatable word. Checking will be done to see if
* it's an absolute value in disguise.
*/
void
void
out_RelWord(struct Expression * expr)
{
ULONG b;
@@ -741,7 +757,7 @@ out_RelWord(struct Expression * expr)
/*
* Output an absolute longword
*/
void
void
out_AbsLong(SLONG b)
{
checkcodesection(sizeof(SLONG));
@@ -760,7 +776,7 @@ out_AbsLong(SLONG b)
* Output a relocatable longword. Checking will be done to see if
* is an absolute value in disguise.
*/
void
void
out_RelLong(struct Expression * expr)
{
SLONG b;
@@ -786,7 +802,7 @@ out_RelLong(struct Expression * expr)
/*
* Output a PC-relative byte
*/
void
void
out_PCRelByte(struct Expression * expr)
{
SLONG b = expr->nVal;
@@ -803,7 +819,7 @@ out_PCRelByte(struct Expression * expr)
/*
* Output a binary file
*/
void
void
out_BinaryFile(char *s)
{
FILE *f;
@@ -834,7 +850,7 @@ out_BinaryFile(char *s)
fclose(f);
}
void
void
out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
{
FILE *f;

View File

@@ -1,4 +1,18 @@
.Dd February 26, 2015
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 17, 2017
.Dt RGBASM 1
.Os RGBDS Manual
.Sh NAME
@@ -6,7 +20,7 @@
.Nd Game Boy assembler
.Sh SYNOPSIS
.Nm rgbasm
.Op Fl hv
.Op Fl Ehvw
.Op Fl b Ar chars
.Op Fl D Ar name Ns Op = Ns Ar value
.Op Fl g Ar chars
@@ -29,6 +43,8 @@ Add string symbol to the compiled source code. This is equivalent to
.Cm EQUS
.Qq Ar "value"
in code. If a value is not specified, a value of 1 is given.
.It Fl E
Export all labels, including unreferenced and local labels.
.It Fl g Ar chars
Change the four characters used for binary constants.
The defaults are 0123.
@@ -52,6 +68,8 @@ When padding an image, pad with this value.
The default is 0x00.
.It Fl v
Be verbose.
.It Fl w
Disable warning output.
.El
.Sh EXAMPLES
Assembling a basic source file is simple:
@@ -64,10 +82,16 @@ run through
and
.Xr rgbfix 1 .
.Sh SEE ALSO
.Xr rgbasm 5 ,
.Xr rgbfix 1 ,
.Xr rgblink 1 ,
.Xr rgbds 7
.Xr rgbds 5 ,
.Xr rgbds 7 ,
.Xr gbz80 7
.Pp
.Lk https://rednex.github.io/rgbds/asm.htm rgbasm assembly commands
.Sh HISTORY
.Nm
was originally written by Carsten S\(/orensen as part of the ASMotor package,
and was later packaged in RGBDS by Justin Lloyd.
and was later packaged in RGBDS by Justin Lloyd. It is now maintained by a
number of contributors at https://github.com/rednex/rgbds.

1008
src/asm/rgbasm.5 Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,7 @@
#include "asm/main.h"
#include "asm/rpn.h"
void
void
mergetwoexpressions(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -28,7 +28,7 @@ mergetwoexpressions(struct Expression * expr, struct Expression * src1,
/*
* Add a byte to the RPN expression
*/
void
void
pushbyte(struct Expression * expr, int b)
{
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
@@ -37,7 +37,7 @@ pushbyte(struct Expression * expr, int b)
/*
* Reset the RPN module
*/
void
void
rpn_Reset(struct Expression * expr)
{
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
@@ -46,7 +46,7 @@ rpn_Reset(struct Expression * expr)
/*
* Returns the next rpn byte in expression
*/
UWORD
UWORD
rpn_PopByte(struct Expression * expr)
{
if (expr->nRPNOut == expr->nRPNLength) {
@@ -58,7 +58,7 @@ rpn_PopByte(struct Expression * expr)
/*
* Determine if the current expression is relocatable
*/
ULONG
ULONG
rpn_isReloc(struct Expression * expr)
{
return (expr->isReloc);
@@ -67,7 +67,7 @@ rpn_isReloc(struct Expression * expr)
/*
* Determine if the current expression can be pc-relative
*/
ULONG
ULONG
rpn_isPCRelative(struct Expression * expr)
{
return (expr->isPCRel);
@@ -76,7 +76,7 @@ rpn_isPCRelative(struct Expression * expr)
/*
* Add symbols, constants and operators to expression
*/
void
void
rpn_Number(struct Expression * expr, ULONG i)
{
rpn_Reset(expr);
@@ -88,7 +88,7 @@ rpn_Number(struct Expression * expr, ULONG i)
expr->nVal = i;
}
void
void
rpn_Symbol(struct Expression * expr, char *tzSym)
{
if (!sym_isConstant(tzSym)) {
@@ -110,18 +110,15 @@ rpn_Symbol(struct Expression * expr, char *tzSym)
rpn_Number(expr, sym_GetConstantValue(tzSym));
}
void
void
rpn_Bank(struct Expression * expr, char *tzSym)
{
if (!sym_isConstant(tzSym)) {
struct sSymbol *psym;
rpn_Reset(expr);
psym = sym_FindSymbol(tzSym);
if (nPass == 2 && psym == NULL) {
yyerror("'%s' not defined", tzSym);
}
/* Check that the symbol exists by evaluating and discarding the value. */
sym_GetValue(tzSym);
expr->isReloc = 1;
pushbyte(expr, RPN_BANK);
while (*tzSym)
@@ -131,43 +128,21 @@ rpn_Bank(struct Expression * expr, char *tzSym)
yyerror("BANK argument must be a relocatable identifier");
}
int
rpn_RangeCheck(struct Expression * expr, struct Expression * src, SLONG low,
SLONG high)
{
*expr = *src;
if (rpn_isReloc(src)) {
pushbyte(expr, RPN_RANGECHECK);
pushbyte(expr, low);
pushbyte(expr, low >> 8);
pushbyte(expr, low >> 16);
pushbyte(expr, low >> 24);
pushbyte(expr, high);
pushbyte(expr, high >> 8);
pushbyte(expr, high >> 16);
pushbyte(expr, high >> 24);
return (1);
} else {
return (expr->nVal >= low && expr->nVal <= high);
}
}
void
void
rpn_CheckHRAM(struct Expression * expr, struct Expression * src)
{
*expr = *src;
pushbyte(expr, RPN_HRAM);
}
void
void
rpn_LOGNOT(struct Expression * expr, struct Expression * src)
{
*expr = *src;
pushbyte(expr, RPN_LOGUNNOT);
}
void
void
rpn_LOGOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -176,7 +151,7 @@ rpn_LOGOR(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGOR);
}
void
void
rpn_LOGAND(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -185,7 +160,47 @@ rpn_LOGAND(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGAND);
}
void
void
rpn_HIGH(struct Expression * expr, struct Expression * src)
{
*expr = *src;
expr->nVal = (expr->nVal >> 8) & 0xFF;
pushbyte(expr, RPN_CONST);
pushbyte(expr, 8);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, RPN_SHR);
pushbyte(expr, RPN_CONST);
pushbyte(expr, 0xFF);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, RPN_AND);
}
void
rpn_LOW(struct Expression * expr, struct Expression * src)
{
*expr = *src;
expr->nVal = expr->nVal & 0xFF;
pushbyte(expr, RPN_CONST);
pushbyte(expr, 0xFF);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, 0);
pushbyte(expr, RPN_AND);
}
void
rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -194,7 +209,7 @@ rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGEQ);
}
void
void
rpn_LOGGT(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -203,7 +218,7 @@ rpn_LOGGT(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGGT);
}
void
void
rpn_LOGLT(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -212,7 +227,7 @@ rpn_LOGLT(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGLT);
}
void
void
rpn_LOGGE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -221,7 +236,7 @@ rpn_LOGGE(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGGE);
}
void
void
rpn_LOGLE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -230,7 +245,7 @@ rpn_LOGLE(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGLE);
}
void
void
rpn_LOGNE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -239,7 +254,7 @@ rpn_LOGNE(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_LOGNE);
}
void
void
rpn_ADD(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -248,7 +263,7 @@ rpn_ADD(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_ADD);
}
void
void
rpn_SUB(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -257,7 +272,7 @@ rpn_SUB(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_SUB);
}
void
void
rpn_XOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -266,7 +281,7 @@ rpn_XOR(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_XOR);
}
void
void
rpn_OR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -275,7 +290,7 @@ rpn_OR(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_OR);
}
void
void
rpn_AND(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -284,7 +299,7 @@ rpn_AND(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_AND);
}
void
void
rpn_SHL(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -293,7 +308,7 @@ rpn_SHL(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_SHL);
}
void
void
rpn_SHR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -302,7 +317,7 @@ rpn_SHR(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_SHR);
}
void
void
rpn_MUL(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
@@ -311,25 +326,31 @@ rpn_MUL(struct Expression * expr, struct Expression * src1,
pushbyte(expr, RPN_MUL);
}
void
void
rpn_DIV(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
joinexpr();
if (src2->nVal == 0) {
fatalerror("division by zero");
}
expr->nVal = (expr->nVal / src2->nVal);
pushbyte(expr, RPN_DIV);
}
void
void
rpn_MOD(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{
joinexpr();
if (src2->nVal == 0) {
fatalerror("division by zero");
}
expr->nVal = (expr->nVal % src2->nVal);
pushbyte(expr, RPN_MOD);
}
void
void
rpn_UNNEG(struct Expression * expr, struct Expression * src)
{
*expr = *src;
@@ -337,7 +358,7 @@ rpn_UNNEG(struct Expression * expr, struct Expression * src)
pushbyte(expr, RPN_UNSUB);
}
void
void
rpn_UNNOT(struct Expression * expr, struct Expression * src)
{
*expr = *src;

View File

@@ -12,6 +12,7 @@
#include "asm/main.h"
#include "asm/mymath.h"
#include "asm/output.h"
#include "extern/err.h"
struct sSymbol *tHashedSymbols[HASHSIZE];
struct sSymbol *pScope = NULL;
@@ -21,8 +22,11 @@ char *currentmacroargs[MAXMACROARGS + 1];
char *newmacroargs[MAXMACROARGS + 1];
char SavedTIME[256];
char SavedDATE[256];
char SavedTIMESTAMP_ISO8601_LOCAL[256];
char SavedTIMESTAMP_ISO8601_UTC[256];
bool exportall;
SLONG
SLONG
Callback_NARG(struct sSymbol * sym)
{
ULONG i = 0;
@@ -36,7 +40,7 @@ Callback_NARG(struct sSymbol * sym)
/*
* Get the nValue field of a symbol
*/
SLONG
SLONG
getvaluefield(struct sSymbol * sym)
{
if (sym->Callback) {
@@ -48,7 +52,7 @@ getvaluefield(struct sSymbol * sym)
/*
* Calculate the hash value for a string
*/
ULONG
ULONG
calchash(char *s)
{
ULONG hash = 5381;
@@ -152,7 +156,7 @@ sym_FindSymbol(char *tzName)
/*
* Purge a symbol
*/
void
void
sym_Purge(char *tzName)
{
struct sSymbol **ppSym;
@@ -183,7 +187,7 @@ sym_Purge(char *tzName)
/*
* Determine if a symbol has been defined
*/
ULONG
ULONG
sym_isConstDefined(char *tzName)
{
struct sSymbol *psym, *pscope;
@@ -207,7 +211,7 @@ sym_isConstDefined(char *tzName)
return (0);
}
ULONG
ULONG
sym_isDefined(char *tzName)
{
struct sSymbol *psym, *pscope;
@@ -228,7 +232,7 @@ sym_isDefined(char *tzName)
/*
* Determine if the symbol is a constant
*/
ULONG
ULONG
sym_isConstant(char *s)
{
struct sSymbol *psym, *pscope;
@@ -265,7 +269,7 @@ sym_GetStringValue(char *tzSym)
/*
* Return a constant symbols value
*/
ULONG
ULONG
sym_GetConstantValue(char *s)
{
struct sSymbol *psym, *pscope;
@@ -291,7 +295,7 @@ sym_GetConstantValue(char *s)
/*
* Return a symbols value... "estimated" if not defined yet
*/
ULONG
ULONG
sym_GetValue(char *s)
{
struct sSymbol *psym, *pscope;
@@ -330,7 +334,7 @@ sym_GetValue(char *s)
/*
* Return a defined symbols value... aborts if not defined yet
*/
ULONG
ULONG
sym_GetDefinedValue(char *s)
{
struct sSymbol *psym, *pscope;
@@ -359,7 +363,7 @@ sym_GetDefinedValue(char *s)
/*
* Macro argument stuff
*/
void
void
sym_ShiftCurrentMacroArgs(void)
{
SLONG i;
@@ -377,12 +381,13 @@ sym_FindMacroArg(SLONG i)
if (i == -1)
i = MAXMACROARGS + 1;
assert(i-1 >= 0 &&
i-1 < sizeof currentmacroargs / sizeof *currentmacroargs);
assert(i-1 >= 0);
assert((size_t)(i-1) < sizeof(currentmacroargs)/sizeof(*currentmacroargs));
return (currentmacroargs[i - 1]);
}
void
void
sym_UseNewMacroArgs(void)
{
SLONG i;
@@ -393,7 +398,7 @@ sym_UseNewMacroArgs(void)
}
}
void
void
sym_SaveCurrentMacroArgs(char *save[])
{
SLONG i;
@@ -402,7 +407,7 @@ sym_SaveCurrentMacroArgs(char *save[])
save[i] = currentmacroargs[i];
}
void
void
sym_RestoreCurrentMacroArgs(char *save[])
{
SLONG i;
@@ -411,7 +416,7 @@ sym_RestoreCurrentMacroArgs(char *save[])
currentmacroargs[i] = save[i];
}
void
void
sym_FreeCurrentMacroArgs(void)
{
SLONG i;
@@ -422,7 +427,7 @@ sym_FreeCurrentMacroArgs(void)
}
}
void
void
sym_AddNewMacroArg(char *s)
{
SLONG i = 0;
@@ -439,7 +444,7 @@ sym_AddNewMacroArg(char *s)
yyerror("A maximum of %d arguments allowed", MAXMACROARGS);
}
void
void
sym_SetMacroArgID(ULONG nMacroCount)
{
char s[256];
@@ -448,7 +453,7 @@ sym_SetMacroArgID(ULONG nMacroCount)
newmacroargs[MAXMACROARGS] = strdup(s);
}
void
void
sym_UseCurrentMacroArgs(void)
{
SLONG i;
@@ -469,7 +474,7 @@ sym_FindMacro(char *s)
/*
* Add an equated symbol
*/
void
void
sym_AddEqu(char *tzSym, SLONG value)
{
if ((nPass == 1)
@@ -493,9 +498,18 @@ sym_AddEqu(char *tzSym, SLONG value)
}
/*
* Add a string equated symbol
* Add a string equated symbol.
*
* If the desired symbol is a string it needs to be passed to this function with
* quotes inside the string, like sym_AddString("name", "\"test\"), or the
* assembler won't be able to use it with DB and similar. This is equivalent as
* ``` name EQUS "\"test\"" ```
*
* If the desired symbol is a register or a number, just the terminator quotes
* of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same
* as ``` M_PI EQUS "3.1415" ```
*/
void
void
sym_AddString(char *tzSym, char *tzValue)
{
struct sSymbol *nsym;
@@ -521,7 +535,7 @@ sym_AddString(char *tzSym, char *tzValue)
/*
* check if symbol is a string equated symbol
*/
ULONG
ULONG
sym_isString(char *tzSym)
{
struct sSymbol *pSym;
@@ -536,7 +550,7 @@ sym_isString(char *tzSym)
/*
* Alter a SET symbols value
*/
void
void
sym_AddSet(char *tzSym, SLONG value)
{
struct sSymbol *nsym;
@@ -555,7 +569,7 @@ sym_AddSet(char *tzSym, SLONG value)
/*
* Add a local (.name) relocatable symbol
*/
void
void
sym_AddLocalReloc(char *tzSym)
{
if ((nPass == 1)
@@ -575,6 +589,9 @@ sym_AddLocalReloc(char *tzSym)
nsym->nValue = nPC;
nsym->nType |=
SYMF_RELOC | SYMF_LOCAL | SYMF_DEFINED;
if (exportall) {
nsym->nType |= SYMF_EXPORT;
}
nsym->pScope = pScope;
nsym->pSection = pCurrentSection;
}
@@ -586,7 +603,7 @@ sym_AddLocalReloc(char *tzSym)
/*
* Add a relocatable symbol
*/
void
void
sym_AddReloc(char *tzSym)
{
if ((nPass == 1)
@@ -604,6 +621,9 @@ sym_AddReloc(char *tzSym)
if (nsym) {
nsym->nValue = nPC;
nsym->nType |= SYMF_RELOC | SYMF_DEFINED;
if (exportall) {
nsym->nType |= SYMF_EXPORT;
}
nsym->pScope = NULL;
nsym->pSection = pCurrentSection;
}
@@ -611,10 +631,53 @@ sym_AddReloc(char *tzSym)
pScope = findsymbol(tzSym, NULL);
}
/*
* Check if the subtraction of two symbols is defined. That is, either both
* symbols are defined and the result is a constant, or both symbols are
* relocatable and belong to the same section.
*
* It returns 1 if the difference is defined, 0 if not.
*/
int
sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2)
{
/* Do nothing the first pass. */
if (nPass != 2)
return 1;
struct sSymbol *nsym1, *nsym2;
/* Do the symbols exist? */
if ((nsym1 = sym_FindSymbol(tzSym1)) == NULL)
fatalerror("Symbol \"%s\" isn't defined.", tzSym1);
if ((nsym2 = sym_FindSymbol(tzSym2)) == NULL)
fatalerror("Symbol \"%s\" isn't defined.", tzSym2);
int s1reloc = (nsym1->nType & SYMF_RELOC) != 0;
int s2reloc = (nsym2->nType & SYMF_RELOC) != 0;
/* Both are non-relocatable */
if (!s1reloc && !s2reloc) return 1;
/* One of them relocatable, the other one not. */
if (s1reloc ^ s2reloc) return 0;
/* Both of them are relocatable. Make sure they are defined (internal
* coherency with sym_AddReloc and sym_AddLocalReloc). */
if (!(nsym1->nType & SYMF_DEFINED))
fatalerror("Relocatable symbol \"%s\" isn't defined.", tzSym1);
if (!(nsym2->nType & SYMF_DEFINED))
fatalerror("Relocatable symbol \"%s\" isn't defined.", tzSym2);
/* Both of them must be in the same section for the difference to be
* defined. */
return nsym1->pSection == nsym2->pSection;
}
/*
* Export a symbol
*/
void
void
sym_Export(char *tzSym)
{
if (nPass == 1) {
@@ -638,28 +701,10 @@ sym_Export(char *tzSym)
}
/*
* Import a symbol
*/
void
sym_Import(char *tzSym)
{
if (nPass == 1) {
/* only import symbols in pass 1 */
struct sSymbol *nsym;
if (findsymbol(tzSym, NULL)) {
yyerror("'%s' already defined", tzSym);
}
if ((nsym = createsymbol(tzSym)) != NULL)
nsym->nType |= SYMF_IMPORT;
}
}
/*
* Globalize a symbol (export if defined, import if not)
*/
void
void
sym_Global(char *tzSym)
{
if (nPass == 2) {
@@ -684,7 +729,7 @@ sym_Global(char *tzSym)
/*
* Add a macro definition
*/
void
void
sym_AddMacro(char *tzSym)
{
if ((nPass == 1)
@@ -709,10 +754,17 @@ sym_AddMacro(char *tzSym)
}
}
/*
* Set whether to export all relocable symbols by default
*/
void sym_SetExportAll(BBOOL set) {
exportall = set;
}
/*
* Prepare for pass #1
*/
void
void
sym_PrepPass1(void)
{
sym_Init();
@@ -721,7 +773,7 @@ sym_PrepPass1(void)
/*
* Prepare for pass #2
*/
void
void
sym_PrepPass2(void)
{
SLONG i;
@@ -746,23 +798,25 @@ sym_PrepPass2(void)
sym_AddString("__TIME__", SavedTIME);
sym_AddString("__DATE__", SavedDATE);
sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
sym_AddSet("_RS", 0);
sym_AddEqu("_NARG", 0);
p_NARGSymbol = findsymbol("_NARG", NULL);
p_NARGSymbol->Callback = Callback_NARG;
math_DefinePI();
}
/*
* Initialize the symboltable
*/
void
void
sym_Init(void)
{
SLONG i;
time_t tod;
time_t now;
for (i = 0; i < MAXMACROARGS; i += 1) {
currentmacroargs[i] = NULL;
@@ -780,15 +834,32 @@ sym_Init(void)
sym_AddSet("_RS", 0);
if (time(&tod) != -1) {
struct tm *tptr;
if (time(&now) != -1) {
struct tm *time_local = localtime(&now);
tptr = localtime(&tod);
strftime(SavedTIME, sizeof(SavedTIME), "%H:%M:%S", tptr);
strftime(SavedDATE, sizeof(SavedDATE), "%d %B %Y", tptr);
sym_AddString("__TIME__", SavedTIME);
sym_AddString("__DATE__", SavedDATE);
strftime(SavedTIME, sizeof(SavedTIME), "\"%H:%M:%S\"", time_local);
strftime(SavedDATE, sizeof(SavedDATE), "\"%d %B %Y\"", time_local);
strftime(SavedTIMESTAMP_ISO8601_LOCAL,
sizeof(SavedTIMESTAMP_ISO8601_LOCAL), "\"%FT%T%z\"", time_local);
struct tm *time_utc = gmtime(&now);
strftime(SavedTIMESTAMP_ISO8601_UTC,
sizeof(SavedTIMESTAMP_ISO8601_UTC), "\"%FT%TZ\"", time_utc);
} else {
warnx("Couldn't determine current time.");
/* The '?' have to be escaped or they will be treated as
* trigraphs... */
strcpy(SavedTIME, "\"\?\?:\?\?:\?\?\"");
strcpy(SavedDATE, "\"\?\? \?\?\? \?\?\?\?\"");
strcpy(SavedTIMESTAMP_ISO8601_LOCAL, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?+\?\?\?\?\"");
strcpy(SavedTIMESTAMP_ISO8601_UTC, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?Z\"");
}
sym_AddString("__TIME__", SavedTIME);
sym_AddString("__DATE__", SavedDATE);
sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
pScope = NULL;
math_DefinePI();

28
src/extern/err.c vendored
View File

@@ -26,34 +26,46 @@
#include <stdlib.h>
#include "extern/err.h"
extern char *progname;
void rgbds_vwarn(const char *fmt, va_list ap)
{
fprintf (stderr, "%s: ", progname);
fprintf (stderr, "warning");
if (fmt) {
vfprintf(stderr, fmt, ap);
fputs (": ", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
perror(0);
}
void rgbds_vwarnx(const char *fmt, va_list ap)
{
fprintf (stderr, "%s: ", progname);
if (fmt) vfprintf(stderr, fmt, ap);
fprintf (stderr, "warning");
if (fmt) {
fputs (": ", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
}
noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
{
vwarn(fmt, ap);
fprintf (stderr, "error");
if (fmt) {
fputs (": ", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
exit(status);
}
noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
{
vwarnx(fmt, ap);
fprintf (stderr, "error");
if (fmt) {
fputs (": ", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
exit(status);
}

View File

@@ -23,8 +23,6 @@
#include "extern/err.h"
char *progname;
static void
usage(void)
{
@@ -71,8 +69,6 @@ main(int argc, char *argv[])
int version; /* mask ROM version number */
int padvalue; /* to pad the rom with if it changes size */
progname = argv[0];
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) {
switch (ch) {
case 'C':

View File

@@ -1,4 +1,18 @@
.Dd February 26, 2015
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 16, 2017
.Dt RGBFIX 1
.Os RGBDS Manual
.Sh NAME
@@ -88,7 +102,10 @@ Set the title string
to a given string, truncated to at most 16 characters.
It is recommended to use 15 characters instead, to avoid clashing with the CGB
flag
.Pq Fl c No or Fl C .
.Po Fl c
or
.Fl C
.Pc .
If both this and the game ID are set, the game ID will overwrite the
overlapping portion of the title.
.It Fl v
@@ -135,5 +152,5 @@ SurvivalKids.gbc
.Sh HISTORY
.Nm
was originally released by Carsten S\(/orensen as a standalone program called
gbfix.
It was later integrated with the ASMotor package, which became RGBDS.
gbfix, and was later packaged in RGBDS by Justin Lloyd. It is now maintained by
a number of contributors at https://github.com/rednex/rgbds.

1824
src/gbz80.7 Normal file

File diff suppressed because it is too large Load Diff

203
src/gfx/gb.c Normal file
View File

@@ -0,0 +1,203 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include "gfx/main.h"
void
transpose_tiles(struct GBImage *gb, int width)
{
uint8_t *newdata;
int i;
int newbyte;
newdata = calloc(gb->size, 1);
for (i = 0; i < gb->size; i++) {
newbyte = i / (8 * depth) * width * 8 * depth;
newbyte = newbyte % gb->size + 8 * depth * (newbyte / gb->size) + i % (8 * depth);
newdata[newbyte] = gb->data[i];
}
free(gb->data);
gb->data = newdata;
}
void
png_to_gb(struct PNGImage png, struct GBImage *gb)
{
int x, y, byte;
png_byte index;
for (y = 0; y < png.height; y++) {
for (x = 0; x < png.width; x++) {
index = png.data[y][x];
index &= (1 << depth) - 1;
if (!gb->horizontal) {
byte = y * depth + x / 8 * png.height / 8 * 8 * depth;
} else {
byte = y * depth + x / 8 * png.height / 8 * 8 * depth;
}
gb->data[byte] |= (index & 1) << (7 - x % 8);
if (depth == 2) {
gb->data[byte + 1] |= (index >> 1) << (7 - x % 8);
}
}
}
if (!gb->horizontal) {
transpose_tiles(gb, png.width / 8);
}
}
void
output_file(struct Options opts, struct GBImage gb)
{
FILE *f;
f = fopen(opts.outfile, "wb");
if (!f) {
err(1, "Opening output file '%s' failed", opts.outfile);
}
fwrite(gb.data, 1, gb.size - gb.trim * 8 * depth, f);
fclose(f);
}
int
get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size)
{
int i, j;
for (i = 0; i < num_tiles; i++) {
for (j = 0; j < tile_size; j++) {
if (tile[j] != tiles[i][j]) {
break;
}
}
if (j >= tile_size) {
return i;
}
}
return -1;
}
void
create_tilemap(struct Options opts, struct GBImage *gb, struct Tilemap *tilemap)
{
int i, j;
int gb_i;
int tile_size;
int max_tiles;
int num_tiles;
int index;
int gb_size;
uint8_t *tile;
uint8_t **tiles;
tile_size = sizeof(uint8_t) * depth * 8;
gb_size = gb->size - (gb->trim * tile_size);
max_tiles = gb_size / tile_size;
tiles = malloc(sizeof(uint8_t*) * max_tiles);
num_tiles = 0;
tilemap->data = malloc(sizeof(uint8_t) * max_tiles);
tilemap->size = 0;
gb_i = 0;
while (gb_i < gb_size) {
tile = malloc(tile_size);
for (i = 0; i < tile_size; i++) {
tile[i] = gb->data[gb_i];
gb_i++;
}
if (opts.unique) {
index = get_tile_index(tile, tiles, num_tiles, tile_size);
if (index < 0) {
index = num_tiles;
tiles[num_tiles] = tile;
num_tiles++;
}
} else {
index = num_tiles;
tiles[num_tiles] = tile;
num_tiles++;
}
tilemap->data[tilemap->size] = index;
tilemap->size++;
}
if (opts.unique) {
free(gb->data);
gb->data = malloc(tile_size * num_tiles);
for (i = 0; i < num_tiles; i++) {
tile = tiles[i];
for (j = 0; j < tile_size; j++) {
gb->data[i * tile_size + j] = tile[j];
}
}
gb->size = i * tile_size;
}
for (i = 0; i < num_tiles; i++) {
free(tiles[i]);
}
free(tiles);
}
void
output_tilemap_file(struct Options opts, struct Tilemap tilemap)
{
FILE *f;
f = fopen(opts.mapfile, "wb");
if (!f) {
err(1, "Opening tilemap file '%s' failed", opts.mapfile);
}
fwrite(tilemap.data, 1, tilemap.size, f);
fclose(f);
if (opts.mapout) {
free(opts.mapfile);
}
}
void
output_palette_file(struct Options opts, struct PNGImage png)
{
FILE *f;
int i, colors, color;
png_color *palette;
if (png_get_PLTE(png.png, png.info, &palette, &colors)) {
f = fopen(opts.palfile, "wb");
if (!f) {
err(1, "Opening palette file '%s' failed", opts.palfile);
}
for (i = 0; i < colors; i++) {
color = palette[i].blue >> 3 << 10 | palette[i].green >> 3 << 5 | palette[i].red >> 3;
fwrite(&color, 2, 1, f);
}
fclose(f);
}
if (opts.palout) {
free(opts.palfile);
}
}

251
src/gfx/main.c Normal file
View File

@@ -0,0 +1,251 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include "gfx/main.h"
static void
usage(void)
{
printf(
"usage: rgbgfx [-DFfhPTuv] [-d #] [-o outfile] [-p palfile] [-t mapfile]\n"
"[-x #] infile\n");
exit(1);
}
int
main(int argc, char *argv[])
{
int ch, size;
struct Options opts = {0};
struct PNGImage png = {0};
struct GBImage gb = {0};
struct Tilemap tilemap = {0};
char *ext;
const char *errmsg = "Warning: The PNG's %s setting is not the same as the setting defined on the command line.";
if (argc == 1) {
usage();
}
opts.mapfile = "";
opts.palfile = "";
opts.outfile = "";
depth = 2;
while((ch = getopt(argc, argv, "DvFfd:hx:Tt:uPp:o:")) != -1) {
switch(ch) {
case 'D':
opts.debug = true;
break;
case 'v':
opts.verbose = true;
break;
case 'F':
opts.hardfix = true;
case 'f':
opts.fix = true;
break;
case 'd':
depth = strtoul(optarg, NULL, 0);
break;
case 'h':
opts.horizontal = true;
break;
case 'x':
opts.trim = strtoul(optarg, NULL, 0);
break;
case 'T':
opts.mapout = true;
break;
case 't':
opts.mapfile = optarg;
break;
case 'u':
opts.unique = true;
break;
case 'P':
opts.palout = true;
break;
case 'p':
opts.palfile = optarg;
break;
case 'o':
opts.outfile = optarg;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc == 0) {
usage();
}
opts.infile = argv[argc - 1];
if (depth != 1 && depth != 2) {
errx(1, "Depth option must be either 1 or 2.");
}
colors = 1 << depth;
input_png_file(opts, &png);
png.mapfile = "";
png.palfile = "";
get_text(&png);
if (png.horizontal != opts.horizontal) {
if (opts.verbose) {
warnx(errmsg, "horizontal");
}
if (opts.hardfix) {
png.horizontal = opts.horizontal;
}
}
if (png.horizontal) {
opts.horizontal = png.horizontal;
}
if (png.trim != opts.trim) {
if (opts.verbose) {
warnx(errmsg, "trim");
}
if (opts.hardfix) {
png.trim = opts.trim;
}
}
if (png.trim) {
opts.trim = png.trim;
}
if (opts.trim > png.width / 8 - 1) {
errx(1, "Trim (%i) for input png file '%s' too large (max: %i)", opts.trim, opts.infile, png.width / 8 - 1);
}
if (strcmp(png.mapfile, opts.mapfile) != 0) {
if (opts.verbose) {
warnx(errmsg, "tilemap file");
}
if (opts.hardfix) {
png.mapfile = opts.mapfile;
}
}
if (!*opts.mapfile) {
opts.mapfile = png.mapfile;
}
if (png.mapout != opts.mapout) {
if (opts.verbose) {
warnx(errmsg, "tilemap file");
}
if (opts.hardfix) {
png.mapout = opts.mapout;
}
}
if (png.mapout) {
opts.mapout = png.mapout;
}
if (strcmp(png.palfile, opts.palfile) != 0) {
if (opts.verbose) {
warnx(errmsg, "palette file");
}
if (opts.hardfix) {
png.palfile = opts.palfile;
}
}
if (!*opts.palfile) {
opts.palfile = png.palfile;
}
if (png.palout != opts.palout) {
if (opts.verbose) {
warnx(errmsg, "palette file");
}
if (opts.hardfix) {
png.palout = opts.palout;
}
}
if (png.palout) {
opts.palout = png.palout;
}
if (!*opts.mapfile && opts.mapout) {
if ((ext = strrchr(opts.infile, '.')) != NULL) {
size = ext - opts.infile + 9;
opts.mapfile = malloc(size);
strncpy(opts.mapfile, opts.infile, size);
*strrchr(opts.mapfile, '.') = '\0';
strcat(opts.mapfile, ".tilemap");
} else {
opts.mapfile = malloc(strlen(opts.infile) + 9);
strcpy(opts.mapfile, opts.infile);
strcat(opts.mapfile, ".tilemap");
}
}
if (!*opts.palfile && opts.palout) {
if ((ext = strrchr(opts.infile, '.')) != NULL) {
size = ext - opts.infile + 5;
opts.palfile = malloc(size);
strncpy(opts.palfile, opts.infile, size);
*strrchr(opts.palfile, '.') = '\0';
strcat(opts.palfile, ".pal");
} else {
opts.palfile = malloc(strlen(opts.infile) + 5);
strcpy(opts.palfile, opts.infile);
strcat(opts.palfile, ".pal");
}
}
gb.size = png.width * png.height * depth / 8;
gb.data = calloc(gb.size, 1);
gb.trim = opts.trim;
gb.horizontal = opts.horizontal;
if (*opts.outfile || *opts.mapfile) {
png_to_gb(png, &gb);
create_tilemap(opts, &gb, &tilemap);
}
if (*opts.outfile) {
output_file(opts, gb);
}
if (*opts.mapfile) {
output_tilemap_file(opts, tilemap);
}
if (*opts.palfile) {
output_palette_file(opts, png);
}
if (opts.fix || opts.debug) {
set_text(&png);
output_png_file(opts, &png);
}
free_png_data(&png);
free(gb.data);
return 0;
}

339
src/gfx/makepng.c Normal file
View File

@@ -0,0 +1,339 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "gfx/main.h"
void
input_png_file(struct Options opts, struct PNGImage *img)
{
FILE *f;
int i, y, num_trans;
bool has_palette = false;
png_byte *trans_alpha;
png_color_16 *trans_values;
bool *full_alpha;
png_color *palette;
f = fopen(opts.infile, "rb");
if (!f) {
err(1, "Opening input png file '%s' failed", opts.infile);
}
img->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!img->png) {
errx(1, "Creating png structure failed");
}
img->info = png_create_info_struct(img->png);
if (!img->info) {
errx(1, "Creating png info structure failed");
}
/* Better error handling here? */
if (setjmp(png_jmpbuf(img->png))) {
exit(1);
}
png_init_io(img->png, f);
png_read_info(img->png, img->info);
img->width = png_get_image_width(img->png, img->info);
img->height = png_get_image_height(img->png, img->info);
img->depth = png_get_bit_depth(img->png, img->info);
img->type = png_get_color_type(img->png, img->info);
if (img->type & PNG_COLOR_MASK_ALPHA) {
png_set_strip_alpha(img->png);
}
if (img->depth != depth) {
if (opts.verbose) {
warnx("Image bit depth is not %i (is %i).", depth,
img->depth);
}
}
if (img->type == PNG_COLOR_TYPE_GRAY) {
if (img->depth < 8) {
png_set_expand_gray_1_2_4_to_8(img->png);
}
png_set_gray_to_rgb(img->png);
} else {
if (img->depth < 8) {
png_set_expand_gray_1_2_4_to_8(img->png);
}
has_palette = png_get_PLTE(img->png, img->info, &palette,
&colors);
}
if (png_get_tRNS(img->png, img->info, &trans_alpha, &num_trans,
&trans_values)) {
if (img->type == PNG_COLOR_TYPE_PALETTE) {
full_alpha = malloc(sizeof(bool) * num_trans);
for (i = 0; i < num_trans; i++) {
if (trans_alpha[i] > 0) {
full_alpha[i] = false;
} else {
full_alpha[i] = true;
}
}
for (i = 0; i < num_trans; i++) {
if (full_alpha[i]) {
palette[i].red = 0xFF;
palette[i].green = 0x00;
palette[i].blue = 0xFF;
/*
* Set to the lightest color in the
* palette.
*/
}
}
free(full_alpha);
} else {
/* Set to the lightest color in the image. */
}
png_free_data(img->png, img->info, PNG_FREE_TRNS, -1);
}
if (has_palette) {
/* Make sure palette only has the amount of colors you want. */
} else {
/*
* Eventually when this copies colors from the image itself,
* make sure order is lightest to darkest.
*/
palette = malloc(sizeof(png_color) * colors);
if (strcmp(opts.infile, "rgb.png") == 0) {
palette[0].red = 0xFF;
palette[0].green = 0xEF;
palette[0].blue = 0xFF;
palette[1].red = 0xF7;
palette[1].green = 0xF7;
palette[1].blue = 0x8C;
palette[2].red = 0x94;
palette[2].green = 0x94;
palette[2].blue = 0xC6;
palette[3].red = 0x39;
palette[3].green = 0x39;
palette[3].blue = 0x84;
} else {
palette[0].red = 0xFF;
palette[0].green = 0xFF;
palette[0].blue = 0xFF;
palette[1].red = 0xA9;
palette[1].green = 0xA9;
palette[1].blue = 0xA9;
palette[2].red = 0x55;
palette[2].green = 0x55;
palette[2].blue = 0x55;
palette[3].red = 0x00;
palette[3].green = 0x00;
palette[3].blue = 0x00;
}
}
/*
* Also unfortunately, this sets it at 8 bit, and I can't find any
* option to reduce to 2 or 1 bit.
*/
#if PNG_LIBPNG_VER < 10402
png_set_dither(img->png, palette, colors, colors, NULL, 1);
#else
png_set_quantize(img->png, palette, colors, colors, NULL, 1);
#endif
if (!has_palette) {
png_set_PLTE(img->png, img->info, palette, colors);
free(palette);
}
/*
* If other useless chunks exist (sRGB, bKGD, pHYs, gAMA, cHRM, iCCP,
* etc.) offer to remove?
*/
png_read_update_info(img->png, img->info);
img->data = malloc(sizeof(png_byte *) * img->height);
for (y = 0; y < img->height; y++) {
img->data[y] = malloc(png_get_rowbytes(img->png, img->info));
}
png_read_image(img->png, img->data);
png_read_end(img->png, img->info);
fclose(f);
}
void
get_text(struct PNGImage *png)
{
png_text *text;
int i, numtxts, numremoved;
png_get_text(png->png, png->info, &text, &numtxts);
for (i = 0; i < numtxts; i++) {
if (strcmp(text[i].key, "h") == 0 && !*text[i].text) {
png->horizontal = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "x") == 0) {
png->trim = strtoul(text[i].text, NULL, 0);
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "t") == 0) {
png->mapfile = text[i].text;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "T") == 0 && !*text[i].text) {
png->mapout = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "p") == 0) {
png->palfile = text[i].text;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "P") == 0 && !*text[i].text) {
png->palout = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
}
}
/* TODO: Remove this and simply change the warning function not to warn instead. */
for (i = 0, numremoved = 0; i < numtxts; i++) {
if (text[i].key == NULL) {
numremoved++;
}
text[i].key = text[i + numremoved].key;
text[i].text = text[i + numremoved].text;
text[i].compression = text[i + numremoved].compression;
}
png_set_text(png->png, png->info, text, numtxts - numremoved);
}
void
set_text(struct PNGImage *png)
{
png_text *text;
char buffer[3];
text = malloc(sizeof(png_text));
if (png->horizontal) {
text[0].key = "h";
text[0].text = "";
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
if (png->trim) {
text[0].key = "x";
snprintf(buffer, 3, "%d", png->trim);
text[0].text = buffer;
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
if (*png->mapfile) {
text[0].key = "t";
text[0].text = "";
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
if (png->mapout) {
text[0].key = "T";
text[0].text = "";
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
if (*png->palfile) {
text[0].key = "p";
text[0].text = "";
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
if (png->palout) {
text[0].key = "P";
text[0].text = "";
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png->png, png->info, text, 1);
}
free(text);
}
void
output_png_file(struct Options opts, struct PNGImage *png)
{
FILE *f;
char *outfile;
png_struct *img;
/* Variable outfile is for debugging purposes. Eventually, opts.infile will be used directly. */
if (opts.debug) {
outfile = malloc(strlen(opts.infile) + 5);
strcpy(outfile, opts.infile);
strcat(outfile, ".out");
} else {
outfile = opts.infile;
}
f = fopen(outfile, "wb");
if (!f) {
err(1, "Opening output png file '%s' failed", outfile);
}
img = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!img) {
errx(1, "Creating png structure failed");
}
/* Better error handling here? */
if (setjmp(png_jmpbuf(img))) {
exit(1);
}
png_init_io(img, f);
png_write_info(img, png->info);
png_write_image(img, png->data);
png_write_end(img, NULL);
fclose(f);
if (opts.debug) {
free(outfile);
}
}
void
free_png_data(struct PNGImage *png)
{
int y;
for (y = 0; y < png->height; y++) {
free(png->data[y]);
}
free(png->data);
}

106
src/gfx/rgbgfx.1 Normal file
View File

@@ -0,0 +1,106 @@
.\" Copyright © 2013 stag019 <stag019@gmail.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 8, 2017
.Dt RGBGFX 1
.Os RGBDS Manual
.Sh NAME
.Nm rgbgfx
.Nd Game Boy graphics converter
.Sh SYNOPSIS
.Nm rgbgfx
.Op Fl DfFhPTv
.Op Fl o Ar outfile
.Op Fl d Ar depth
.Op Fl p Ar palfile
.Op Fl t Ar mapfile
.Op Fl x Ar tiles
.Ar file
.Sh DESCRIPTION
The
.Nm
program converts PNG images into the Nintendo Game Boy's planar tile format.
The arguments are as follows:
.Bl -tag -width Ds
.It Fl D
Debug features are enabled.
.It Fl f
Fix the input PNG file to be a correctly indexed image.
.It Fl F
Same as
.Fl f ,
but additionally, the input PNG file is fixed to have its parameters match the
command line's parameters.
.It Fl d Ar depth
The bitdepth of the output image (either 1 or 2).
By default, the bitdepth is 2 (two bits per pixel).
.It Fl h
Lay out tiles horizontally rather than vertically.
.It Fl o Ar outfile
The name of the output file.
.It Fl p Ar palfile
Raw bytes (8 bytes for two bits per pixel, 4 bytes for one bit per pixel)
containing the RGB15 values in the little-endian byte order and then ordered
from lightest to darkest.
.It Fl P
Same as
.Fl p ,
but the pallete file output name is made by taking the input filename,
removing the file extension, and appending
.Pa .pal .
.It Fl t Ar mapfile
If any tiles are the same, don't place the repeat tiles in the output file, and
make a tilemap file.
.It Fl T
Same as
.Fl t ,
but the tilemap file output name is made by taking the input filename,
removing the file extension, and appending
.Pa .tilemap .
.It Fl u
Truncate repeated tiles. Useful with tilemaps.
.It Fl v
Verbose.
Print errors when the command line parameters and the parameters in
the PNG file don't match.
.It Fl x Ar tiles
Trim the end of the output file by this many tiles.
.El
.Sh EXAMPLES
The following will take a PNG file with a bitdepth of 1, 2, or 8, and output
planar 2bpp data:
.Pp
.D1 $ rgbgfx -o out.2bpp in.png
.Pp
The following creates a planar 2bpp file with only unique tiles, and its tilemap
.Pa out.tilemap :
.Pp
.D1 $ rgbgfx -T -u -o out.2bpp in.png
.Pp
The following will do nothing:
.Pp
.D1 $ rgbgfx in.png
.Sh SEE ALSO
.Xr rgbds 7 ,
.Xr rgbasm 1 ,
.Xr rgblink 1 ,
.Xr rgbfix 1 ,
.Xr gbz80 7
.Sh HISTORY
.Nm
was created by
.An stag019
to be included in RGBDS.
It is now maintained by a number of contributors at
https://github.com/rednex/rgbds.

2
src/link/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
parser.c
parser.h

File diff suppressed because it is too large Load Diff

192
src/link/lexer.l Normal file
View File

@@ -0,0 +1,192 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
%option noinput
%option yylineno
%{
#include <stdarg.h>
#include <unistd.h>
#include "extern/err.h"
#include "link/mylink.h"
#include "link/script.h"
#include "parser.h"
extern int yyparse();
/* File include stack. */
#define MAX_INCLUDE_DEPTH 8
static int include_stack_ptr = 0;
static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
static char include_path[MAX_INCLUDE_DEPTH][_MAX_PATH + 1];
static int include_line[MAX_INCLUDE_DEPTH];
static char linkerscript_path[_MAX_PATH + 1]; /* Base file */
%}
%%
\"([^\\\"]|\\.)*\" {
if (strlen(yytext) > sizeof(yylval.s) - 1)
script_fatalerror("String is too long: %s\n.", yytext);
if (strlen(yytext) < 3) /* 2 quotes + 1 character */
script_fatalerror("String %s is invalid\n.", yytext);
yytext++; /* ignore first quote */
strcpy(yylval.s, yytext);
yylval.s[strlen(yylval.s)-1] = '\0'; /* remove end quote */
return STRING;
}
\$[a-fA-F0-9]+ {
yytext++; /* Skip prefix */
yylval.i = strtol(yytext, NULL, 16);
return INTEGER;
}
[0-9]+ {
yylval.i = strtol(yytext, NULL, 10);
return INTEGER;
}
(?i:ROM0) { strcpy(yylval.s, "ROM0"); return SECTION_NONBANKED; }
(?i:ROMX) { strcpy(yylval.s, "ROMX"); return SECTION_BANKED; }
(?i:VRAM) { strcpy(yylval.s, "VRAM"); return SECTION_BANKED; }
(?i:WRAM0) { strcpy(yylval.s, "WRAM0"); return SECTION_NONBANKED; }
(?i:WRAMX) { strcpy(yylval.s, "WRAMX"); return SECTION_BANKED; }
(?i:SRAM) { strcpy(yylval.s, "SRAM"); return SECTION_BANKED; }
(?i:OAM) { strcpy(yylval.s, "OAM"); return SECTION_NONBANKED; }
(?i:HRAM) { strcpy(yylval.s, "HRAM"); return SECTION_NONBANKED; }
(?i:ALIGN) { return COMMAND_ALIGN; }
(?i:ORG) { return COMMAND_ORG; }
(?i:INCLUDE) { return COMMAND_INCLUDE; }
"\n" { return NEWLINE; }
;.* { /* Ignore comments. A dot doesn't match newline. */ }
[[:space:]] { /* Ignore whitespace. */ }
. { script_fatalerror("Invalid character [%s]\n.", yytext); }
%%
extern FILE *yyin;
void script_Parse(const char * path)
{
yyin = fopen(path, "r");
if (!yyin)
errx(1, "Error opening file! \"%s\"\n", path);
strncpy(linkerscript_path, path, sizeof(linkerscript_path));
linkerscript_path[sizeof(linkerscript_path) - 1] = '\0';
do {
yyparse();
} while (!feof(yyin));
fclose(yyin);
}
void script_IncludeFile(const char * path)
{
if (include_stack_ptr == (MAX_INCLUDE_DEPTH-1))
script_fatalerror("Includes nested too deeply.");
include_line[include_stack_ptr] = yylineno;
include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
include_stack_ptr++;
yyin = fopen(path, "r" );
if (!yyin)
script_fatalerror("Couldn't open file \"%s\"", path);
strncpy(include_path[include_stack_ptr], path, sizeof(include_path[0]));
include_path[include_stack_ptr][sizeof(include_path[0])-1] = '\0';
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
yylineno = 1;
/*
* The INCLUDE keyword is handled before reaching a newline token, it's
* handled right after parsing the string with the file name that has to
* be included. It isn't actually needed to include a newline after the
* path, the last line of the linkerscript doesn't need to have a
* newline character but it can have a command.
*
* This means that, when opening a new file, we must tell the parser
* that what it is going to start at a new line or it will think that
* the first line of the included script is the continuation of the
* INCLUDE line of the parent script. If this is not done, the first
* line of an included linkerscript can only be a comment (or empty).
*/
unput('\n');
}
int script_IncludeDepthGet(void)
{
return include_stack_ptr;
}
void script_IncludePop(void)
{
fclose(yyin);
include_stack_ptr--;
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(include_stack[include_stack_ptr]);
yylineno = include_line[include_stack_ptr];
}
void script_PrintFileStack(void)
{
int i = include_stack_ptr;
include_line[i] = yylineno;
while (i > 0) {
fprintf(stderr, "%s(%d) -> ", include_path[i], include_line[i]);
i--;
}
fprintf(stderr, "%s(%d)", linkerscript_path, include_line[i]);
}
noreturn void script_fatalerror(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "error: ");
script_PrintFileStack();
fprintf(stderr, ":\n\t");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
exit(1);
}

View File

@@ -7,7 +7,7 @@
#include "link/mylink.h"
#include "link/main.h"
static BBOOL
static BBOOL
symboldefined(char *name)
{
struct sSection *pSect;
@@ -15,7 +15,7 @@ symboldefined(char *name)
pSect = pSections;
while (pSect) {
ULONG i;
int i;
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
if ((pSect->tSymbols[i]->Type == SYM_EXPORT)
@@ -31,7 +31,7 @@ symboldefined(char *name)
return (0);
}
static BBOOL
static BBOOL
addmodulecontaining(char *name)
{
struct sSection **ppLSect;
@@ -39,7 +39,7 @@ addmodulecontaining(char *name)
ppLSect = &pLibSections;
while (*ppLSect) {
ULONG i;
int i;
for (i = 0; i < (*ppLSect)->nNumberOfSymbols; i += 1) {
if (((*ppLSect)->tSymbols[i]->Type == SYM_EXPORT)
@@ -66,7 +66,7 @@ addmodulecontaining(char *name)
return (0);
}
void
void
AddNeededModules(void)
{
struct sSection *pSect;
@@ -101,7 +101,7 @@ AddNeededModules(void)
pSect = pSections;
while (pSect) {
ULONG i;
int i;
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
if ((pSect->tSymbols[i]->Type == SYM_IMPORT)

View File

@@ -22,21 +22,19 @@ enum eBlockType {
SLONG options = 0;
SLONG fillchar = 0;
char smartlinkstartsymbol[256];
char *progname;
char *smartlinkstartsymbol;
/*
* Print the usagescreen
*
*/
static void
static void
usage(void)
{
printf(
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-p pad_value]\n"
" [-s symbol] file [...]\n");
"usage: rgblink [-twd] [-l linkerscript] [-m mapfile] [-n symfile] [-O overlay]\n"
" [-o outfile] [-p pad_value] [-s symbol] file [...]\n");
exit(1);
}
@@ -45,7 +43,7 @@ usage(void)
*
*/
int
int
main(int argc, char *argv[])
{
int ch;
@@ -54,10 +52,11 @@ main(int argc, char *argv[])
if (argc == 1)
usage();
progname = argv[0];
while ((ch = getopt(argc, argv, "m:n:o:p:s:t")) != -1) {
while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:twd")) != -1) {
switch (ch) {
case 'l':
SetLinkerscriptName(optarg);
break;
case 'm':
SetMapfileName(optarg);
break;
@@ -67,6 +66,10 @@ main(int argc, char *argv[])
case 'o':
out_Setname(optarg);
break;
case 'O':
out_SetOverlayname(optarg);
options |= OPT_OVERLAY;
break;
case 'p':
fillchar = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') {
@@ -79,10 +82,29 @@ main(int argc, char *argv[])
break;
case 's':
options |= OPT_SMART_C_LINK;
strcpy(smartlinkstartsymbol, optarg);
smartlinkstartsymbol = optarg;
break;
case 't':
options |= OPT_SMALL;
options |= OPT_TINY;
break;
case 'd':
/*
* Set to set WRAM as a single continuous block as on
* DMG. All WRAM sections must be WRAM0 as bankable WRAM
* sections do not exist in this mode. A WRAMX section
* will raise an error. VRAM bank 1 can't be used if
* this option is enabled either.
*
* This option implies OPT_CONTWRAM.
*/
options |= OPT_DMG_MODE;
/* fallthrough */
case 'w':
/* Set to set WRAM as a single continuous block as on
* DMG. All WRAM sections must be WRAM0 as bankable WRAM
* sections do not exist in this mode. A WRAMX section
* will raise an error. */
options |= OPT_CONTWRAM;
break;
default:
usage();

View File

@@ -13,7 +13,7 @@ FILE *sf = NULL;
SLONG currentbank = 0;
SLONG sfbank;
void
void
SetMapfileName(char *name)
{
mf = fopen(name, "w");
@@ -23,7 +23,7 @@ SetMapfileName(char *name)
}
}
void
void
SetSymfileName(char *name)
{
sf = fopen(name, "w");
@@ -35,7 +35,7 @@ SetSymfileName(char *name)
fprintf(sf, ";File generated by rgblink\n\n");
}
void
void
CloseMapfile(void)
{
if (mf) {
@@ -48,7 +48,7 @@ CloseMapfile(void)
}
}
void
void
MapfileInitBank(SLONG bank)
{
if (mf) {
@@ -65,6 +65,8 @@ MapfileInitBank(SLONG bank)
fprintf(mf, "HRAM:\n");
else if (bank == BANK_VRAM || bank == BANK_VRAM + 1)
fprintf(mf, "VRAM Bank #%ld:\n", bank - BANK_VRAM);
else if (bank == BANK_OAM)
fprintf(mf, "OAM:\n");
else if (bank < MAXBANKS)
fprintf(mf, "SRAM Bank #%ld:\n", bank - BANK_SRAM);
}
@@ -79,6 +81,8 @@ MapfileInitBank(SLONG bank)
sfbank = 0;
else if (bank == BANK_VRAM || bank == BANK_VRAM + 1)
sfbank = bank - BANK_VRAM;
else if (bank == BANK_OAM)
sfbank = 0;
else if (bank < MAXBANKS)
sfbank = bank - BANK_SRAM;
else
@@ -86,15 +90,20 @@ MapfileInitBank(SLONG bank)
}
}
void
void
MapfileWriteSection(struct sSection * pSect)
{
SLONG i;
if (mf) {
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
pSect->nByteSize);
if (pSect->nByteSize > 0) {
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes) [\"%s\"]\n",
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
pSect->nByteSize, pSect->pzName);
} else {
fprintf(mf, " SECTION: $%04lX ($0 bytes) [\"%s\"]\n",
pSect->nOrg, pSect->pzName);
}
}
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
@@ -116,7 +125,7 @@ MapfileWriteSection(struct sSection * pSect)
}
}
void
void
MapfileCloseBank(SLONG slack)
{
if (!mf)

View File

@@ -9,6 +9,7 @@
#include <string.h>
#include "extern/err.h"
#include "link/assign.h"
#include "link/mylink.h"
#include "link/main.h"
@@ -23,7 +24,7 @@ BBOOL oReadLib = 0;
*
*/
SLONG
SLONG
readlong(FILE * f)
{
SLONG r;
@@ -36,7 +37,7 @@ readlong(FILE * f)
return (r);
}
UWORD
UWORD
readword(FILE * f)
{
UWORD r;
@@ -46,21 +47,41 @@ readword(FILE * f)
return (r);
}
/*
* Read a NULL terminated string from a file
*
*/
SLONG
readasciiz(char *s, FILE * f)
SLONG
readasciiz(char **dest, FILE *f)
{
SLONG r = 0;
size_t r = 0;
while (((*s++) = fgetc(f)) != 0)
size_t bufferLength = 16;
char *start = malloc(bufferLength);
char *s = start;
if (!s) {
err(1, NULL);
}
while (((*s++) = fgetc(f)) != 0) {
r += 1;
if (r >= bufferLength) {
bufferLength *= 2;
start = realloc(start, bufferLength);
if (!start) {
err(1, NULL);
}
s = start + r;
}
}
*dest = start;
return (r + 1);
}
/*
* Allocate a new section and link it into the list
*
@@ -97,7 +118,6 @@ AllocSection(void)
struct sSymbol *
obj_ReadSymbol(FILE * f)
{
char s[256];
struct sSymbol *pSym;
pSym = malloc(sizeof *pSym);
@@ -105,194 +125,50 @@ obj_ReadSymbol(FILE * f)
err(1, NULL);
}
readasciiz(s, f);
pSym->pzName = malloc(strlen(s) + 1);
if (!pSym->pzName) {
err(1, NULL);
}
strcpy(pSym->pzName, s);
readasciiz(&pSym->pzName, f);
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
pSym->nSectionID = readlong(f);
pSym->nOffset = readlong(f);
}
return pSym;
}
/*
* RGB0 object reader routines
* RGB object reader routines
*
*/
struct sSection *
obj_ReadRGB0Section(FILE * f)
obj_ReadRGBSection(FILE * f)
{
struct sSection *pSection;
char *pzName;
readasciiz(&pzName, f);
if (IsSectionNameInUse(pzName))
errx(1, "Section name \"%s\" is already in use.", pzName);
pSection = AllocSection();
pSection->pzName = pzName;
pSection->nByteSize = readlong(f);
pSection->Type = (enum eSectionType) fgetc(f);
pSection->nOrg = -1;
pSection->nBank = -1;
/* does the user want the -s mode? */
if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) {
pSection->Type = SECT_ROM0;
}
if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
/*
* These sectiontypes contain data...
*
*/
if (pSection->nByteSize) {
pSection->pData = malloc(pSection->nByteSize);
if (!pSection->pData) {
err(1, NULL);
}
SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch;
char s[256];
fread(pSection->pData, sizeof(UBYTE),
pSection->nByteSize, f);
nNumberOfPatches = readlong(f);
ppPatch = &pSection->pPatches;
/*
* And patches...
*
*/
while (nNumberOfPatches--) {
pPatch = malloc(sizeof *pPatch);
if (!pPatch) {
err(1, NULL);
}
*ppPatch = pPatch;
readasciiz(s, f);
pPatch->pzFilename = malloc(strlen(s) + 1);
if (!pPatch->pzFilename) {
err(1, NULL);
}
strcpy(pPatch->pzFilename, s);
pPatch->nLineNo =
readlong(f);
pPatch->nOffset =
readlong(f);
pPatch->Type =
(enum ePatchType)
fgetc(f);
if ((pPatch->nRPNSize = readlong(f)) > 0) {
pPatch->pRPN = malloc(pPatch->nRPNSize);
if (!pPatch->pRPN) {
err(1, NULL);
}
fread(pPatch->pRPN, sizeof(UBYTE),
pPatch->nRPNSize, f);
} else
pPatch->pRPN = NULL;
pPatch->pNext = NULL;
ppPatch = &(pPatch->pNext);
}
} else {
/* Skip number of patches */
readlong(f);
pSection->pData = &dummymem;
}
}
return pSection;
}
void
obj_ReadRGB0(FILE * pObjfile)
{
struct sSection *pFirstSection;
SLONG nNumberOfSymbols, nNumberOfSections, i;
nNumberOfSymbols = readlong(pObjfile);
nNumberOfSections = readlong(pObjfile);
/* First comes the symbols */
if (nNumberOfSymbols) {
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
if (!tSymbols) {
err(1, NULL);
}
for (i = 0; i < nNumberOfSymbols; i += 1)
tSymbols[i] = obj_ReadSymbol(pObjfile);
} else
tSymbols = (struct sSymbol **) & dummymem;
/* Next we have the sections */
pFirstSection = NULL;
while (nNumberOfSections--) {
struct sSection *pNewSection;
pNewSection = obj_ReadRGB0Section(pObjfile);
pNewSection->nNumberOfSymbols = nNumberOfSymbols;
if (pFirstSection == NULL)
pFirstSection = pNewSection;
}
/*
* Fill in the pSection entry in the symbolstructure.
* This REALLY needs some cleaning up... but, hey, it works
*
*/
for (i = 0; i < nNumberOfSymbols; i += 1) {
struct sSection *pConvSect = pFirstSection;
if (tSymbols[i]->Type != SYM_IMPORT
&& tSymbols[i]->nSectionID != -1) {
SLONG j = 0;
while (j != tSymbols[i]->nSectionID) {
j += 1;
pConvSect = pConvSect->pNext;
}
tSymbols[i]->pSection = pConvSect;
} else
tSymbols[i]->pSection = NULL;
}
}
/*
* RGB1 object reader routines
*
*/
struct sSection *
obj_ReadRGB1Section(FILE * f)
{
struct sSection *pSection;
pSection = AllocSection();
pSection->nByteSize = readlong(f);
pSection->Type = (enum eSectionType) fgetc(f);
/*
* And because of THIS new feature I'll have to rewrite loads and
* loads of stuff... oh well it needed to be done anyway
*
*/
pSection->nOrg = readlong(f);
pSection->nBank = readlong(f);
pSection->nAlign = readlong(f);
/* does the user want the -s mode? */
if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) {
pSection->Type = SECT_ROM0;
if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
errx(1, "ROMX sections can't be used with option -t.");
}
if ((options & OPT_CONTWRAM) && (pSection->Type == SECT_WRAMX)) {
errx(1, "WRAMX sections can't be used with option -w.");
}
if (options & OPT_DMG_MODE) {
/* WRAMX sections are checked for OPT_CONTWRAM */
if (pSection->Type == SECT_VRAM && pSection->nBank == 1) {
errx(1, "VRAM bank 1 can't be used with option -w.");
}
}
if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
/*
* These sectiontypes contain data...
@@ -306,7 +182,6 @@ obj_ReadRGB1Section(FILE * f)
SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch;
char s[256];
fread(pSection->pData, sizeof(UBYTE),
pSection->nByteSize, f);
@@ -324,13 +199,7 @@ obj_ReadRGB1Section(FILE * f)
}
*ppPatch = pPatch;
readasciiz(s, f);
pPatch->pzFilename = malloc(strlen(s) + 1);
if (!pPatch->pzFilename) {
err(1, NULL);
}
strcpy(pPatch->pzFilename, s);
readasciiz(&pPatch->pzFilename, f);
pPatch->nLineNo = readlong(f);
pPatch->nOffset = readlong(f);
pPatch->Type = (enum ePatchType) fgetc(f);
@@ -357,8 +226,8 @@ obj_ReadRGB1Section(FILE * f)
return pSection;
}
void
obj_ReadRGB1(FILE * pObjfile)
void
obj_ReadRGB(FILE * pObjfile)
{
struct sSection *pFirstSection;
SLONG nNumberOfSymbols, nNumberOfSections, i;
@@ -385,7 +254,7 @@ obj_ReadRGB1(FILE * pObjfile)
while (nNumberOfSections--) {
struct sSection *pNewSection;
pNewSection = obj_ReadRGB1Section(pObjfile);
pNewSection = obj_ReadRGBSection(pObjfile);
pNewSection->nNumberOfSymbols = nNumberOfSymbols;
if (pFirstSection == NULL)
pFirstSection = pNewSection;
@@ -417,7 +286,7 @@ obj_ReadRGB1(FILE * pObjfile)
*
*/
void
void
obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
{
char tzHeader[8];
@@ -426,23 +295,19 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
tzHeader[4] = 0;
if (strncmp(tzHeader, "RGB", 3) == 0) {
switch (tzHeader[3]) {
case '0':
obj_ReadRGB0(pObjfile);
break;
case '1':
case '2':
//V2 is really the same but the are new patch types
obj_ReadRGB1(pObjfile);
case '3':
case '4': // V4 supports OAM sections, but is otherwise identical
obj_ReadRGB(pObjfile);
break;
default:
errx(1, "'%s' is an unsupported version", tzObjectfile);
errx(1, "'%s' uses an unsupported object file version (%s). Please reassemble it.", tzObjectfile, tzHeader);
}
} else {
errx(1, "'%s' is not a valid object", tzObjectfile);
}
}
void
void
obj_Readfile(char *tzObjectfile)
{
FILE *pObjfile;
@@ -462,7 +327,7 @@ obj_Readfile(char *tzObjectfile)
oReadLib = 0;
}
SLONG
SLONG
file_Length(FILE * f)
{
ULONG r, p;
@@ -475,16 +340,16 @@ file_Length(FILE * f)
return (r);
}
void
void
lib_ReadXLB0(FILE * f)
{
SLONG size;
size = file_Length(f) - 4;
while (size) {
char name[256];
char *name;
size -= readasciiz(name, f);
size -= readasciiz(&name, f);
readword(f);
size -= 2;
readword(f);
@@ -492,5 +357,6 @@ lib_ReadXLB0(FILE * f)
size -= readlong(f);
size -= 4;
obj_ReadOpenFile(f, name);
free(name);
}
}

View File

@@ -8,9 +8,12 @@
#include "link/assign.h"
char *tzOutname;
char *tzOverlayname = NULL;
void
writehome(FILE * f)
SLONG MaxOverlayBank;
void
writehome(FILE * f, FILE * f_overlay)
{
struct sSection *pSect;
UBYTE *mem;
@@ -19,14 +22,19 @@ writehome(FILE * f)
if (!mem)
return;
memset(mem, fillchar, MaxAvail[BANK_ROM0]);
if (f_overlay != NULL) {
fseek(f_overlay, 0L, SEEK_SET);
fread(mem, 1, MaxAvail[BANK_ROM0], f_overlay);
} else {
memset(mem, fillchar, MaxAvail[BANK_ROM0]);
}
MapfileInitBank(0);
pSect = pSections;
while (pSect) {
if (pSect->Type == SECT_ROM0) {
memcpy(mem + pSect->nOrg, pSect->pData,
pSect->nByteSize);
pSect->nByteSize);
MapfileWriteSection(pSect);
}
pSect = pSect->pNext;
@@ -38,8 +46,8 @@ writehome(FILE * f)
free(mem);
}
void
writebank(FILE * f, SLONG bank)
void
writebank(FILE * f, FILE * f_overlay, SLONG bank)
{
struct sSection *pSect;
UBYTE *mem;
@@ -48,14 +56,19 @@ writebank(FILE * f, SLONG bank)
if (!mem)
return;
memset(mem, fillchar, MaxAvail[bank]);
if (f_overlay != NULL && bank <= MaxOverlayBank) {
fseek(f_overlay, bank*0x4000, SEEK_SET);
fread(mem, 1, MaxAvail[bank], f_overlay);
} else {
memset(mem, fillchar, MaxAvail[bank]);
}
MapfileInitBank(bank);
pSect = pSections;
while (pSect) {
if (pSect->Type == SECT_ROMX && pSect->nBank == bank) {
memcpy(mem + pSect->nOrg - 0x4000, pSect->pData,
pSect->nByteSize);
pSect->nByteSize);
MapfileWriteSection(pSect);
}
pSect = pSect->pNext;
@@ -67,24 +80,57 @@ writebank(FILE * f, SLONG bank)
free(mem);
}
void
void
out_Setname(char *tzOutputfile)
{
tzOutname = tzOutputfile;
}
void
void
out_SetOverlayname(char *tzOverlayfile)
{
tzOverlayname = tzOverlayfile;
}
void
Output(void)
{
SLONG i;
FILE *f;
FILE *f_overlay = NULL;
if ((f = fopen(tzOutname, "wb"))) {
writehome(f);
if (tzOverlayname) {
f_overlay = fopen(tzOverlayname, "rb");
if (!f_overlay) {
fprintf(stderr, "Failed to open overlay file %s\n", tzOverlayname);
exit(1);
}
fseek(f_overlay, 0, SEEK_END);
if (ftell(f_overlay) % 0x4000 != 0) {
fprintf(stderr, "Overlay file must be aligned to 0x4000 bytes\n");
exit(1);
}
MaxOverlayBank = (ftell(f_overlay) / 0x4000) - 1;
if (MaxOverlayBank < 1) {
fprintf(stderr, "Overlay file be at least 0x8000 bytes\n");
exit(1);
}
if (MaxOverlayBank > MaxBankUsed) {
MaxBankUsed = MaxOverlayBank;
}
}
writehome(f, f_overlay);
for (i = 1; i <= MaxBankUsed; i += 1)
writebank(f, i);
writebank(f, f_overlay, i);
fclose(f);
if (tzOverlayname) {
fclose(f_overlay);
}
}
for (i = BANK_WRAM0; i < MAXBANKS; i++) {
struct sSection *pSect;

120
src/link/parser.y Normal file
View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
%{
#include <stdio.h>
#include "extern/err.h"
#include "link/script.h"
int yylex();
void yyerror(char *);
extern int yylineno;
%}
%union { int i; char s[512]; }
%token<i> INTEGER
%token<s> STRING
%token<s> SECTION_NONBANKED
%token<s> SECTION_BANKED
%token COMMAND_ALIGN
%token COMMAND_ORG
%token COMMAND_INCLUDE
%token NEWLINE
%start lines
%%
lines:
/* empty */
| lines line NEWLINE
;
line:
/* empty */
| statement
;
statement:
/* Statements to set the current section */
SECTION_NONBANKED {
script_SetCurrentSectionType($1, 0);
}
| SECTION_NONBANKED INTEGER {
script_fatalerror("Trying to assign a bank to a non-banked section.\n");
}
| SECTION_BANKED {
script_fatalerror("Banked section without assigned bank.\n");
}
| SECTION_BANKED INTEGER {
script_SetCurrentSectionType($1, $2);
}
/* Commands to adjust the address inside the current section */
| COMMAND_ALIGN INTEGER {
script_SetAlignment($2);
}
| COMMAND_ALIGN {
script_fatalerror("ALIGN keyword needs an argument.\n");
}
| COMMAND_ORG INTEGER {
script_SetAddress($2);
}
| COMMAND_ORG {
script_fatalerror("ORG keyword needs an argument.\n");
}
/* Section name */
| STRING {
script_OutputSection($1);
}
/* Include file */
| COMMAND_INCLUDE STRING {
script_IncludeFile($2);
}
/* End */
;
%%
extern int yylex();
extern int yyparse();
int yywrap(void)
{
if (script_IncludeDepthGet() == 0)
return 1;
script_IncludePop();
return 0;
}
void yyerror(char *s)
{
script_fatalerror("Linkerscript parse error: \"%s\"\n", s);
}

View File

@@ -13,19 +13,19 @@ SLONG rpnstack[256];
SLONG rpnp;
SLONG nPC;
void
void
rpnpush(SLONG i)
{
rpnstack[rpnp++] = i;
}
SLONG
SLONG
rpnpop(void)
{
return (rpnstack[--rpnp]);
}
SLONG
SLONG
getsymvalue(SLONG symid)
{
switch (pCurrentSection->tSymbols[symid]->Type) {
@@ -51,7 +51,7 @@ getsymvalue(SLONG symid)
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
}
SLONG
SLONG
getsymbank(SLONG symid)
{
SLONG nBank;
@@ -68,17 +68,21 @@ getsymbank(SLONG symid)
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
}
if (nBank >= BANK_WRAMX && nBank <= (BANK_WRAMX+6))
if (nBank == BANK_WRAM0 || nBank == BANK_ROM0 || nBank == BANK_OAM ||
nBank == BANK_HRAM) {
return 0;
} else if (nBank >= BANK_WRAMX && nBank < (BANK_WRAMX + BANK_COUNT_WRAMX)) {
return nBank - BANK_WRAMX + 1;
if (nBank >= BANK_VRAM && nBank <= (BANK_VRAM+1))
} else if (nBank >= BANK_VRAM && nBank < (BANK_VRAM + BANK_COUNT_VRAM)) {
return nBank - BANK_VRAM;
if (nBank >= BANK_SRAM && nBank <= (BANK_SRAM+3))
} else if (nBank >= BANK_SRAM && nBank < (BANK_SRAM + BANK_COUNT_SRAM)) {
return nBank - BANK_SRAM;
}
return nBank;
}
SLONG
SLONG
calcrpn(struct sPatch * pPatch)
{
SLONG t, size;
@@ -174,15 +178,6 @@ calcrpn(struct sPatch * pPatch)
pPatch->pzFilename, pPatch->nLineNo);
}
break;
case RPN_PCEZP:
t = rpnpop();
rpnpush(t & 0xFF);
if (t < 0x2000 || t > 0x20FF) {
errx(1,
"%s(%ld) : Value must be in the ZP area",
pPatch->pzFilename, pPatch->nLineNo);
}
break;
case RPN_CONST:
/* constant */
t = (*rpn++);
@@ -211,35 +206,12 @@ calcrpn(struct sPatch * pPatch)
rpnpush(getsymbank(t));
size -= 4;
break;
case RPN_RANGECHECK:
{
SLONG low, high;
low = (*rpn++);
low |= (*rpn++) << 8;
low |= (*rpn++) << 16;
low |= (*rpn++) << 24;
high = (*rpn++);
high |= (*rpn++) << 8;
high |= (*rpn++) << 16;
high |= (*rpn++) << 24;
t = rpnpop();
if (t < low || t > high) {
errx(1,
"%s(%ld) : Value must be in the range [%ld;%ld]",
pPatch->pzFilename,
pPatch->nLineNo, low, high);
}
rpnpush(t);
size -= 8;
break;
}
}
}
return (rpnpop());
}
void
void
Patch(void)
{
struct sSection *pSect;
@@ -269,22 +241,12 @@ Patch(void)
}
break;
case PATCH_WORD_L:
case PATCH_WORD_B:
if (t >= -32768 && t <= 65535) {
t &= 0xFFFF;
if (pPatch->Type == PATCH_WORD_L) {
pSect->pData[pPatch->nOffset] =
t & 0xFF;
pSect->pData[pPatch->nOffset +
1] =
(t >> 8) & 0xFF;
} else {
//Assume big endian
pSect->pData[pPatch->nOffset] =
(t >> 8) & 0xFF;
pSect->pData[pPatch->nOffset +
1] = t & 0xFF;
}
pSect->pData[pPatch->nOffset] =
t & 0xFF;
pSect->pData[pPatch->nOffset + 1] =
(t >> 8) & 0xFF;
} else {
errx(1,
"%s(%ld) : Value must be 16-bit",
@@ -301,15 +263,6 @@ Patch(void)
pSect->pData[pPatch->nOffset + 3] =
(t >> 24) & 0xFF;
break;
case PATCH_LONG_B:
pSect->pData[pPatch->nOffset + 0] =
(t >> 24) & 0xFF;
pSect->pData[pPatch->nOffset + 1] =
(t >> 16) & 0xFF;
pSect->pData[pPatch->nOffset + 2] =
(t >> 8) & 0xFF;
pSect->pData[pPatch->nOffset + 3] = t & 0xFF;
break;
}
pPatch = pPatch->pNext;

View File

@@ -1,4 +1,18 @@
.Dd February 26, 2015
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 17, 2017
.Dt RGBLINK 1
.Os RGBDS Manual
.Sh NAME
@@ -7,11 +21,15 @@
.Sh SYNOPSIS
.Nm rgblink
.Op Fl t
.Op Fl w
.Op Fl d
.Op Fl m Ar mapfile
.Op Fl n Ar symfile
.Op Fl O Ar overlayfile
.Op Fl o Ar outfile
.Op Fl p Ar pad_value
.Op Fl s Ar symbol
.Op Fl l Ar linkerscript
.Ar
.Sh DESCRIPTION
The
@@ -26,12 +44,29 @@ If your ROM will only be 32KiB, you can use the
.Fl t
option to override this.
.Pp
Similarly, WRAM0 sections are placed in the first 4KiB of WRAM bank 0 and WRAMX
sections are placed in any bank except bank 0.
If your ROM doesn't use banked WRAM you can use option
.Fl w
option to override this.
.Pp
Also, if your ROM is designed for DMG, you can make sure that you don't use any
prohibited section by using the option
.Fl d ,
which implies
.Fl w
but also prohibits the use of VRAM bank 1.
.Pp
The arguments are as follows:
.Bl -tag -width Ds
.It Fl m Ar mapfile
Write a mapfile to the given filename.
.It Fl n Ar symfile
Write a symbol file to the given filename.
.It Fl O Ar overlayfile
The ROM image to overlay sections over.
When an overlay ROM is provided, all sections must be fixed.
This may be used to patch an existing binray.
.It Fl o Ar outfile
Write ROM image to the given filename.
.It Fl p Ar pad_value
@@ -39,12 +74,27 @@ When padding an image, pad with this value.
The default is 0x00.
.It Fl s Ar symbol
???
.It Fl w
Expand the WRAM0 section size from 4KiB to the full 8KiB assigned to WRAM and
prohibit the use of WRAMX sections.
.It Fl d
Enable DMG mode.
Prohibit the use of sections that doesn't exist on a DMG, such as WRAMX and VRAM
bank 1.
This option automatically enables
.Fl w .
.It Fl t
Write a tiny
.Pq 32KiB
ROM file.
This forces all ROMX sections to be of type ROM0, and increases the ROM0
section size from 16KiB to 32KiB.
Expand the ROM0 section size from 16KiB to the full 32KiB assigned to ROM and
prohibit the use of ROMX sections.
Useful for ROMs that fit in 32 KiB.
.It Fl l Ar linkerscript
Specify a linkerscript file that tells the linker how sections must be placed in
the ROM.
This file has priority over the attributes assigned in the source code, but they
have to be consistent.
See
.Xr rgblink 5
for more information about its format.
.El
.Sh EXAMPLES
All you need for a basic ROM is an object file, which can be made into a ROM
@@ -61,9 +111,12 @@ to fix these so that the program will actually run in a Game Boy:
.D1 $ rgbfix -v bar.gb
.Sh SEE ALSO
.Xr rgbasm 1 ,
.Xr rgblink 5 ,
.Xr rgbfix 1 ,
.Xr rgbds 5 ,
.Xr rgbds 7
.Sh HISTORY
.Nm
was originally written by Carsten S\(/orensen as part of the ASMotor package,
and was later packaged in RGBDS by Justin Lloyd.
and was later packaged in RGBDS by Justin Lloyd. It is now maintained by a
number of contributors at https://github.com/rednex/rgbds.

101
src/link/rgblink.5 Normal file
View File

@@ -0,0 +1,101 @@
.\" Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 17, 2017
.Dt RGBLINK 5
.Os RGBDS Manual
.Sh NAME
.Nm rgblink
.Nd linkerscript file format
.Sh DESCRIPTION
The linkerscript is an external file that allows the user to specify the
order of sections without the need for doing so before assembling each object
file.
.Pp
The placement of sections specified in the linkerscript is done before the
sections whose placement is defined in the source code.
.Pp
A linkerscript consists on a series of banks followed by a list of sections
and, optionally, commands.
They can be lowercase or uppercase, it is ignored.
Any line can contain a comment starting with
.Ql \&;
that ends at the end of the line:
.Pp
.Bd -literal -offset indent
ROMX $F ; This is a comment
"Functions to read array"
ALIGN 8
"Array aligned to 256 bytes"
WRAMX 2
"Some variables"
.Ed
.Pp
Numbers can be in decimal or hexadecimal format (the prefix is
.Ql $ ) .
It is an error if any bank or command is found before setting a bank.
.Pp
Files can be included by using the
.Ar INCLUDE
keyword followed by a string with the path of the file that has to be included.
.Pp
The possible bank types are:
.Sy ROM0 , ROMX , VRAM , WRAM0 , WRAMX , OAM
and
.Sy HRAM .
Types
.Sy ROMX , VRAM , WRAMX
and
.Sy SRAM
are banked, which means that it is needed to specify a bank after the type.
.Pp
When a new bank statement is found, sections found after it will be placed
right from the beginning of that bank.
If the linkerscript switches to a different bank and then it comes back to the
previous one it will continue from the last address that was used.
.Pp
The only two commands are
.Ar ORG
and
.Ar ALIGN :
.Bl -bullet
.It
.Ar ORG
sets the address in which new sections will be placed.
It can not be lower than the current address.
.It
.Ar ALIGN
will increase the address until it is aligned to the specified boundary (it
tries to set to 0 the number of bits specified after the command:
.Sy ALIGN 8
will align to $100).
.El
.Pp
Note: The bank, alignment, address and type of sections can be specified both
in the source code and in the linkerscript.
For a section to be able to be placed with the linkerscript the bank must be
left unassigned in the source code or be the same as the one specified in the
linkerscript. The address and alignment musn't be set.
.Sh SEE ALSO
.Xr rgbasm 1 ,
.Xr rgblink 1 ,
.Xr rgbfix 1 ,
.Xr rgbds 5 ,
.Xr rgbds 7
.Sh HISTORY
.Nm
was originally written by Carsten S\(/orensen as part of the ASMotor package,
and was later packaged in RGBDS by Justin Lloyd. It is now maintained by a
number of contributors at https://github.com/rednex/rgbds.

216
src/link/script.c Normal file
View File

@@ -0,0 +1,216 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <string.h>
#include "extern/err.h"
#include "link/assign.h"
#include "link/mylink.h"
static struct {
unsigned int address; /* current address to write sections to */
unsigned int top_address; /* not inclusive */
enum eSectionType type;
} bank[MAXBANKS];
static int current_bank = -1; /* Bank as seen by the bank array */
static int current_real_bank = -1; /* bank as seen by the GB */
void script_InitSections(void)
{
int i;
for (i = 0; i < MAXBANKS; i++) {
if (i == BANK_ROM0) {
/* ROM0 bank */
bank[i].address = 0x0000;
if (options & OPT_TINY) {
bank[i].top_address = 0x8000;
} else {
bank[i].top_address = 0x4000;
}
bank[i].type = SECT_ROM0;
} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
/* Swappable ROM bank */
bank[i].address = 0x4000;
bank[i].top_address = 0x8000;
bank[i].type = SECT_ROMX;
} else if (i == BANK_WRAM0) {
/* WRAM */
bank[i].address = 0xC000;
if (options & OPT_CONTWRAM) {
bank[i].top_address = 0xE000;
} else {
bank[i].top_address = 0xD000;
}
bank[i].type = SECT_WRAM0;
} else if (i >= BANK_SRAM && i < BANK_SRAM + BANK_COUNT_SRAM) {
/* Swappable SRAM bank */
bank[i].address = 0xA000;
bank[i].top_address = 0xC000;
bank[i].type = SECT_SRAM;
} else if (i >= BANK_WRAMX && i < BANK_WRAMX + BANK_COUNT_WRAMX) {
/* Swappable WRAM bank */
bank[i].address = 0xD000;
bank[i].top_address = 0xE000;
bank[i].type = SECT_WRAMX;
} else if (i >= BANK_VRAM && i < BANK_VRAM + BANK_COUNT_VRAM) {
/* Swappable VRAM bank */
bank[i].address = 0x8000;
bank[i].type = SECT_VRAM;
if (options & OPT_DMG_MODE && i != BANK_VRAM) {
/* In DMG the only available bank is bank 0. */
bank[i].top_address = 0x8000;
} else {
bank[i].top_address = 0xA000;
}
} else if (i == BANK_OAM) {
/* OAM */
bank[i].address = 0xFE00;
bank[i].top_address = 0xFEA0;
bank[i].type = SECT_OAM;
} else if (i == BANK_HRAM) {
/* HRAM */
bank[i].address = 0xFF80;
bank[i].top_address = 0xFFFF;
bank[i].type = SECT_HRAM;
} else {
errx(1, "(INTERNAL) Unknown bank type!");
}
}
}
void script_SetCurrentSectionType(const char *type, unsigned int bank)
{
if (strcmp(type, "ROM0") == 0) {
if (bank != 0)
errx(1, "(Internal) Trying to assign a bank number to ROM0.\n");
current_bank = BANK_ROM0;
current_real_bank = 0;
return;
} else if (strcmp(type, "ROMX") == 0) {
if (bank == 0)
errx(1, "ROMX index can't be 0.\n");
if (bank > BANK_COUNT_ROMX)
errx(1, "ROMX index too big (%d > %d).\n", bank, BANK_COUNT_ROMX);
current_bank = BANK_ROMX + bank - 1;
current_real_bank = bank;
return;
} else if (strcmp(type, "VRAM") == 0) {
if (bank >= BANK_COUNT_VRAM)
errx(1, "VRAM index too big (%d >= %d).\n", bank, BANK_COUNT_VRAM);
current_bank = BANK_VRAM + bank;
current_real_bank = bank;
return;
} else if (strcmp(type, "WRAM0") == 0) {
if (bank != 0)
errx(1, "(Internal) Trying to assign a bank number to WRAM0.\n");
current_bank = BANK_WRAM0;
current_real_bank = 0;
return;
} else if (strcmp(type, "WRAMX") == 0) {
if (bank == 0)
errx(1, "WRAMX index can't be 0.\n");
if (bank > BANK_COUNT_WRAMX)
errx(1, "WRAMX index too big (%d > %d).\n", bank, BANK_COUNT_WRAMX);
current_bank = BANK_WRAMX + bank - 1;
current_real_bank = bank - 1;
return;
} else if (strcmp(type, "SRAM") == 0) {
if (bank >= BANK_COUNT_SRAM)
errx(1, "SRAM index too big (%d >= %d).\n", bank, BANK_COUNT_SRAM);
current_bank = BANK_SRAM + bank;
current_real_bank = bank;
return;
} else if (strcmp(type, "OAM") == 0) {
if (bank != 0)
errx(1, "(Internal) Trying to assign a bank number to OAM.\n");
current_bank = BANK_OAM;
current_real_bank = 0;
return;
} else if (strcmp(type, "HRAM") == 0) {
if (bank != 0)
errx(1, "(Internal) Trying to assign a bank number to HRAM.\n");
current_bank = BANK_HRAM;
current_real_bank = 0;
return;
}
errx(1, "(Internal) Unknown section type \"%s\".\n", type);
}
void script_SetAddress(unsigned int addr)
{
if (current_bank == -1) {
errx(1, "Trying to set an address without assigned bank\n");
}
/* Make sure that we don't go back. */
if (bank[current_bank].address > addr) {
errx(1, "Trying to go to a previous address (0x%04X to 0x%04X)\n",
bank[current_bank].address, addr);
}
bank[current_bank].address = addr;
/* Make sure we don't overflow */
if (bank[current_bank].address >= bank[current_bank].top_address) {
errx(1, "Bank overflowed (0x%04X >= 0x%04X)\n",
bank[current_bank].address, bank[current_bank].top_address);
}
}
void script_SetAlignment(unsigned int alignment)
{
if (current_bank == -1) {
errx(1, "Trying to set an alignment without assigned bank\n");
}
if (alignment > 15) {
errx(1, "Trying to set an alignment too big: %d\n", alignment);
}
unsigned int size = 1 << alignment;
unsigned int mask = size - 1;
if (bank[current_bank].address & mask) {
bank[current_bank].address &= ~mask;
bank[current_bank].address += size;
}
/* Make sure we don't overflow */
if (bank[current_bank].address >= bank[current_bank].top_address) {
errx(1, "Bank overflowed (0x%04X >= 0x%04X)\n",
bank[current_bank].address, bank[current_bank].top_address);
}
}
void script_OutputSection(const char *section_name)
{
if (current_bank == -1) {
errx(1, "Trying to place section \"%s\" without assigned bank\n", section_name);
}
if (!IsSectionSameTypeBankAndFloating(section_name, bank[current_bank].type,
current_real_bank)) {
errx(1, "Different attributes for \"%s\" in source and linkerscript\n",
section_name);
}
/* Move section to its place. */
bank[current_bank].address +=
AssignSectionAddressAndBankByName(section_name,
bank[current_bank].address, current_real_bank);
}

View File

@@ -19,7 +19,7 @@ struct ISymbol {
struct ISymbol *tHash[HASHSIZE];
SLONG
SLONG
calchash(char *s)
{
SLONG r = 0;
@@ -29,7 +29,7 @@ calchash(char *s)
return (r % HASHSIZE);
}
void
void
sym_Init(void)
{
SLONG i;
@@ -37,7 +37,7 @@ sym_Init(void)
tHash[i] = NULL;
}
SLONG
SLONG
sym_GetValue(char *tzName)
{
if (strcmp(tzName, "@") == 0) {
@@ -58,7 +58,7 @@ sym_GetValue(char *tzName)
}
}
SLONG
SLONG
sym_GetBank(char *tzName)
{
struct ISymbol **ppSym;
@@ -75,7 +75,7 @@ sym_GetBank(char *tzName)
errx(1, "Unknown symbol '%s'", tzName);
}
void
void
sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
{
if (strcmp(tzName, "@") == 0)

190
src/rgbds.5 Normal file
View File

@@ -0,0 +1,190 @@
.\" Copyright (c) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 17, 2017
.Dt RGBDS 5
.Os RGBDS Manual
.Sh NAME
.Nm rgbds
.Nd object file format documentation
.Sh DESCRIPTION
This is the description of the object files used by
.Xr rgbasm 1
and
.Xr rgblink 1 .
Please, note that the specifications may change.
This toolchain is in development and new features may require adding more
information to the current format, or modifying some fields, which would break
compatibility with older versions.
.Pp
.Sh FILE STRUCTURE
The following types are used:
.Pp
.Ar LONG
is a 32bit integer stored in littleendian format (Intel).
.Ar BYTE
is an 8bit integer.
.Ar STRING
is a 0terminated string of
.Ar BYTE .
.Pp
.Bd -literal
; Header
BYTE ID[4] ; "RGB4"
LONG NumberOfSymbols ; The number of symbols used in this file
LONG NumberOfSections ; The number of sections used in this file
; Symbols
REPT NumberOfSymbols ; Number of symbols defined in this object file.
STRING Name ; The name of this symbol. Local symbols are stored
; as "Scope.Symbol".
BYTE Type ; 0 = LOCAL symbol only used in this file.
; 1 = IMPORT this symbol from elsewhere (unused).
; 2 = EXPORT this symbol to other objects.
IF Type != 1 ; If symbol is defined in this object file.
LONG SectionID ; The section number (of this object file) in which
; this symbol is defined.
LONG Value ; The symbols value. It's the offset into that
; symbol's section.
ENDC
ENDR
; Sections
REPT NumberOfSections
STRING Name ; Name of the section
LONG Size ; Size in bytes of this section
BYTE Type ; 0 = WRAM0
; 1 = VRAM
; 2 = ROMX
; 3 = ROM0
; 4 = HRAM
; 5 = WRAMX
; 6 = SRAM
; 7 = OAM
LONG Org ; Address to fix this section at. -1 if the linker should
; decide (floating address).
LONG Bank ; Bank to load this section into. -1 if the linker should
; decide (floating bank). This field is only valid for ROMX,
; VRAM, WRAMX and SRAM sections.
LONG Align ; Alignment of this section (expressed as number of low bits
; to leave as 0). -1 if not defined.
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.
BYTE Data[Size] ; Raw data of the section.
LONG NumberOfPatches ; Number of patches to apply.
; These types of sections may have patches
REPT NumberOfPatches
STRING SourceFile ; Name of the source file (for printing error
; messages).
LONG Line ; The line of the source file.
LONG Offset ; Offset into the section where patch should
; be applied (in bytes).
BYTE Type ; 0 = BYTE patch.
; 1 = little endian WORD patch.
; 2 = little endian LONG patch.
LONG RPNSize ; Size of the buffer with the RPN.
; expression.
BYTE RPN[RPNSize] ; RPN expression. Definition below.
ENDR
ENDC
ENDR
.Ed
.Ss RPN DATA
Expressions in the object file are stored as RPN.
This is an expression of the form
.Do 2 5 + Dc .
This will first push the value
.Do 2 Dc to the stack.
Then
.Do 5 Dc .
The
.Do + Dc operator pops two arguments from the stack, adds them, and then pushes
the result on the stack, effectively replacing the two top arguments with their
sum.
In the RGB format, RPN expressions are stored as BYTEs with some bytes being
special prefixes for integers and symbols.
.Pp
.Bl -column -offset indent ".Sy String" ".Sy String"
.It Sy Value Ta Sy Meaning
.It Li $00 Ta Li + operator
.It Li $01 Ta Li - operator
.It Li $02 Ta Li * operator
.It Li $03 Ta Li / operator
.It Li $04 Ta Li % operator
.It Li $05 Ta Li unary -
.It Li $06 Ta Li | operator
.It Li $07 Ta Li & operator
.It Li $08 Ta Li ^ operator
.It Li $09 Ta Li unary ~
.It Li $0A Ta Li && comparison
.It Li $0B Ta Li || comparison
.It Li $0C Ta Li unary !
.It Li $0D Ta Li == comparison
.It Li $0E Ta Li != comparison
.It Li $0F Ta Li > comparison
.It Li $10 Ta Li < comparison
.It Li $11 Ta Li >= comparison
.It Li $12 Ta Li <= comparison
.It Li $13 Ta Li << comparison
.It Li $14 Ta Li >> comparison
.It Li $15 Ta Li BANK()
function.
A symbol ID follows.
.It Li $16 Ta Li HRAMCheck.
Check if the value is in HRAM, AND it with 0xFF.
.It Li $80 Ta Ar LONG
integer follows.
.It Li $81 Ta Ar LONG
Symbol ID follows.
.El
.Pp
.Sh SEE ALSO
.Xr rgbasm 1 ,
.Xr rgblink 1 ,
.Xr rgbds 7 ,
.Xr gbz80 7
.Sh HISTORY
.Nm rgbds
was originally written by Carsten S\(/orensen as part of the ASMotor package,
and was later packaged in RGBDS by Justin Lloyd.
It is now maintained by a number of contributors at
https://github.com/rednex/rgbds.

View File

@@ -1,4 +1,18 @@
.Dd $Mdocdate$
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 17, 2017
.Dt RGBDS 7
.Os RGBDS Manual
.Sh NAME
@@ -14,8 +28,24 @@ To get a working ROM image from a single assembly source file:
.Xr rgbasm 1 ,
.Xr rgbfix 1 ,
.Xr rgblink 1 ,
.Xr rgbds 5 ,
.Xr gbz80 7
.Sh HISTORY
.Nm
grew out of the ASMotor package released by Carsten S\(/orensen.
It was first released as a Game Boy software package by Justin Lloyd.
.Bl -ohang
.It
1997, Carsten S\(/orensen (AKA SurfSmurf) writes ASMotor as a general-purpose
assembler/linker system for DOS/Win32.
.It
1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and produce GBZ80
assembly/machine code, and releases this version as RGBDS.
.It
2009, Vegard Nossum adapts the code to be more UNIX-like and releases this
version as rgbds-linux on GitHub.
.It
2010, Anthony J. Bentley forks that repository. The fork becomes the reference
implementation of rgbds.
.It
2017, Bentley's repository is moved to a neutral name.
It is now maintained by a number of contributors at
https://github.com/rednex/rgbds
.El

Some files were not shown because too many files have changed in this diff Show More