|
1 | 1 | = Abersoft Forth _disassembled_ README
|
2 | 2 | :author: Marcos Cruz (programandala.net)
|
3 |
| -:revdate: 2015-05-23 |
| 3 | +:revdate: 2015-11-13 |
4 | 4 |
|
5 |
| -How to disassemble Abersoft Forth. |
| 5 | +// This file is written in AsciDoc/Asciidoctor format |
| 6 | +// (see <http://asciidoctor.org>). |
6 | 7 |
|
7 |
| -The file <abersoft_forth.disassembled.z80s> contains the Z80 source |
8 |
| -code of Abersoft Forth. |
| 8 | +Project webpage: |
9 | 9 |
|
| 10 | +http://programandala.net/en.program.abersoft_forth.html |
10 | 11 |
|
| 12 | +== How to disassemble Abersoft Forth |
11 | 13 |
|
12 |
| -// XXX OLD |
13 |
| -// XXX TODO rewrite! |
| 14 | +You don't have to, I already did it. |
14 | 15 |
|
15 |
| -0. Create or update "dis_compiling.tap" with `make dis`, if needed. |
| 16 | +The file <abersoft_forth.disassembled.z80s> contains the tidy Z80 |
| 17 | +source code of Abersoft Forth, even with some comments about known |
| 18 | +bugs or possible improvements. |
16 | 19 |
|
17 |
| -1. Open "dis_compiling.tap" with your ZX Spectrum emulator of choice |
18 |
| -(Fuse recommended). Abersoft Forth will start. |
| 20 | +As said, you don't have to disassemble Abersoft Forth, but you can if |
| 21 | +you wish. If so, keep on reading. |
19 | 22 |
|
20 |
| -2. Configure your emulator to send the printer output to a new empty |
21 |
| -text file of the host system. |
| 23 | +== Requiriments |
22 | 24 |
|
23 |
| -3. Compile dis with `LOADT 1 LOAD`. The process will be slow. Set your |
24 |
| -emulator to its maximun speed. |
| 25 | +The following programs are needed to disassemble Abersoft Forth: |
25 | 26 |
|
26 |
| -4. When the compilation is finished, a welcome message will be printed |
27 |
| -on screen. Then follow the simple instructions: give the command |
28 |
| -`dis`. Maybe you need to slow down the emulator to be able to type it. |
29 |
| -The process will start. Set your emulator to its maximun speed. At the |
30 |
| -end, the program will print "Done!". |
| 27 | +- http://worldofspectrum.org[bas2tap], by Martijn van der Heide. |
| 28 | +- http://programandala.net/en.program.fsb.html[fsb], by Marcos Cruz |
| 29 | + (programandala.net). |
| 30 | +- GNU make, by the Free Software Foundation. |
| 31 | +- head, cat and sort, from the GNU coreutils. |
| 32 | +- http://pasmo.speccy.org/[Pasmo], by Julián Albo. |
| 33 | +- http://vim.org[Vim], by Bram Moolenaar. |
| 34 | +- http://www.tablix.org/~avian/z80dasm/[z80dasm], by Tomaž Šolc. |
31 | 35 |
|
32 |
| -5. Overwrite the file <dis_printout.txt> with the new printout |
33 |
| -produced by dis, wherever it is (it depends on the configuration of |
34 |
| -your emulator). |
| 36 | +== Files |
| 37 | + |
| 38 | +A detailed description of the files included in the tarball of this |
| 39 | +project seems the simplest way to explain how the whole complex thing |
| 40 | +works, for the improbable case someone needs to modify something... |
| 41 | + |
| 42 | +=== Misc files |
| 43 | + |
| 44 | +README.adoc :: |
| 45 | + This file you are reading. |
| 46 | +TO-DO.adoc :: |
| 47 | + Some little things to do. (Nothing as of 2015-08-14). |
| 48 | + |
| 49 | +=== Disassembling tools written in Abersoft Forth |
| 50 | + |
| 51 | +Three tools written in Abersoft Forth are used to print out system |
| 52 | +information in the format required by z80dasm or Vim. The printer |
| 53 | +output of the ZX Spectrum emulator (Fuse is used by default) is |
| 54 | +redirected to the correspondent host system file. Four files are |
| 55 | +created this way. Some of them are ready to be used, the rest have to |
| 56 | +be modified first by other programs, during the automatic |
| 57 | +disassembling process. |
| 58 | + |
| 59 | +In order to compile and execute these Forth tools, |
| 60 | +use the command `LOADT 1 LOAD` at the Forth prompt and follow the instructions. |
| 61 | + |
| 62 | +==== AbersoftForth2branches |
| 63 | + |
| 64 | +This tool creates two files: |
| 65 | +<tidy_branches.vim> and <z80dasm_symbols.branches.z80s>. |
| 66 | + |
| 67 | +abersoftforth2branches.boot.symbols-output.sh :: |
| 68 | + The program loader for the Fuse emulator, |
| 69 | + that sets its printer output file to <tidy_branches.vim>. |
| 70 | + If you use other emulator, adapt this file or manually copy its printout to <tidy_branches.vim>. |
| 71 | +abersoftforth2branches.boot.vim-output.sh :: |
| 72 | + The program loader for the Fuse emulator, |
| 73 | + that sets its printer output file to <tidy_branches.vim>. |
| 74 | + If you use other emulator, adapt this file or manually copy its printout to <tidy_branches.vim>. |
| 75 | +abersoftforth2branches_compiling.tap :: |
| 76 | + TAP file ready to be loaded with the emulator and compile the program. |
| 77 | + It contains Abersoft Forth, Afera library modules and the program itself. |
| 78 | + Use the command `LOADT 1 LOAD` at the Forth prompt and follow the instructions. |
| 79 | +abersoftforth2branches.fsb :: |
| 80 | + Source of the program. |
| 81 | +tidy_branches.vim :: |
| 82 | + One of the two files created by the program. |
| 83 | + This is done automatically when <abersoftforth2branches.boot.vim-output.sh> is used to run it, |
| 84 | + using the Fuse emulator. |
| 85 | + This file is a Vim program that tidies the Forth branches in the Z80 source. |
| 86 | +z80dasm_symbols.branches.z80s :: |
| 87 | + One of the two files created by the program. |
| 88 | + This is done automatically when <abersoftforth2branches.boot.symbols-output.sh> is used to run it, |
| 89 | + using the Fuse emulator. |
| 90 | + This file contains the z80dasm block definitions of the Forth branches destinations. |
| 91 | + |
| 92 | +==== AbersoftForth2nfa4vim |
| 93 | + |
| 94 | +This tool creates the file <abersoftforth2nfa4vim_printout.txt> (that Vim will |
| 95 | +convert to <tidy_name_fields.vim>). |
| 96 | + |
| 97 | +abersoftforth2nfa4vim.boot.sh :: |
| 98 | + The program loader for the Fuse emulator, |
| 99 | + that sets its printer output file to <abersoftforth2nfa4vim_printout.txt>. |
| 100 | + If you use other emulator, |
| 101 | + adapt this file or manually copy its printout to <abersoftforth2nfa4vim_printout.txt>. |
| 102 | +abersoftforth2nfa4vim_compiling.tap :: |
| 103 | + TAP file ready to be loaded with the emulator and compile the program. |
| 104 | + It contains Abersoft Forth, Afera library modules and the program itself. |
| 105 | + Use the command `LOADT 1 LOAD` at the Forth prompt and follow the instructions. |
| 106 | +abersoftforth2nfa4vim.fsb :: |
| 107 | + Source of the program. |
| 108 | +abersoftforth2nfa4vim_printout.txt :: |
| 109 | + The file created by the program. |
| 110 | + This is done automatically when <abersoftforth2nfa4vim.boot.sh> is used to run it, |
| 111 | + using the Fuse emulator. |
| 112 | + This file contains a raw program for Vim that will be tidied before executed. |
| 113 | + |
| 114 | +==== AbersoftForth2z80dasmblocks |
| 115 | + |
| 116 | +This tool creates the file <abersoftforth2z80dasmblocks_printout.txt>. |
| 117 | + |
| 118 | +abersoftforth2z80dasmblocks.boot.sh :: |
| 119 | + The program loader for the Fuse emulator, |
| 120 | + that sets its printer output file to <abersoftforth2z80dasmblocks_printout.txt>. |
| 121 | + If you use other emulator, |
| 122 | + adapt this file or manually copy its printout to <abersoftforth2z80dasmblocks_printout.txt>. |
| 123 | +abersoftforth2z80dasmblocks_compiling.tap :: |
| 124 | + TAP file ready to be loaded with the emulator and compile the program. |
| 125 | + It contains Abersoft Forth, Afera library modules and the program itself. |
| 126 | + Use the command `LOADT 1 LOAD` at the Forth prompt and follow the instructions. |
| 127 | +abersoftforth2z80dasmblocks.fsb :: |
| 128 | + Source of the program. |
| 129 | +abersoftforth2z80dasmblocks_printout.txt :: |
| 130 | + The file created by the program. |
| 131 | + This is done automatically when <abersoftforth2z80dasmblocks.boot.sh> is used to run it, |
| 132 | + using the Fuse emulator. |
| 133 | + This file contains a raw blocks file for z80dasm that will be tidied before used. |
| 134 | +abersoftforth2z80dasmblocks_printout.tidy.txt :: |
| 135 | + The tidy version of <abersoftforth2z80dasmblocks_printout.txt>, created by Vim |
| 136 | + with the commands in <word_labels.z80dasm_blocks.vim>. |
| 137 | + |
| 138 | +==== Afera library |
| 139 | + |
| 140 | +The http://programandala.net/en.program.afera[Afera library] makes |
| 141 | +Abersoft Forth a much more powerful system. It is used by the |
| 142 | +disassembling tools written in Abersoft Forth. |
| 143 | + |
| 144 | +lib/ :: |
| 145 | + This directory contains some modules from the Afera library, |
| 146 | + needed by the tools written in Abersoft Forth. |
| 147 | +afera_for_disassembling.fsb :: |
| 148 | + This is a modified version of <afera.fsb>, the main file of the Afera |
| 149 | + library. It does the same than the original one except some |
| 150 | + modifications to the original words that would cause an output |
| 151 | + different than with the original system. In order to disassemble |
| 152 | + Abersoft Forth, an original binary is used, not the one patched by |
| 153 | + Afera, so it doesn't make any difference if the original words have |
| 154 | + been patched by Afera or not -- unless their apparent size has been |
| 155 | + changed by a patch (e.g. by moving the final `(;S)` of the word). |
| 156 | + That is what this version of <afera.fsb> avoids. |
| 157 | +afera_for_disassembling.tap :: |
| 158 | + TAP version of <afera_for_disassembling.fsb>, |
| 159 | + ready to be used by the tools written in Abersoft Forth. |
| 160 | +patches.fsb :: |
| 161 | + A little program written in Abersoft Forth that |
| 162 | + modifies some patches created by modules of the |
| 163 | + Afera library, in order to make the patched words the same |
| 164 | + size than their original versions. |
| 165 | + Otherwise the disassembling tools written in Abersoft |
| 166 | + Forth would make wrong calculations. |
| 167 | +patches.tap :: |
| 168 | + The TAP version of <patches.fsb>, |
| 169 | + ready to be used by the tools written in Abersoft Forth. |
| 170 | + |
| 171 | +=== Original binary |
| 172 | + |
| 173 | +abersoft_forth.original.bin :: |
| 174 | + Original binary of Abersoft Forth, without any file header. |
| 175 | +abersoft_forth.original.tap :: |
| 176 | + Original binary of Abersoft Forth, in TAP format. |
| 177 | +abersoft_forth.padded.bin :: |
| 178 | + Modified version of <abersoft_forth.original.bin>. |
| 179 | + The original binary must be padded with zeroes, both at the start (because of |
| 180 | + the way Abersoft Forth stores some values at the start, before the actual |
| 181 | + loading address of the binary) and at the end (to prevent errors caused by |
| 182 | + patched words that use words that don't belong to the original system). |
| 183 | + This is the file disassembled by z80dasm. |
| 184 | + |
| 185 | +=== Main files |
| 186 | + |
| 187 | +Makefile :: |
| 188 | + The core of the disassembling process. |
| 189 | + Beside the three tools written in Abersoft Forth, |
| 190 | + that are needed only once to create four files, |
| 191 | + the whole process is automatic. Just use the `make` command. |
| 192 | + |
| 193 | +tidy_name_fields.vim :: |
| 194 | + File created by Vim from <abersoftforth2nfa4vim_printout.txt>, |
| 195 | + by executing <word_labels.name_fields.vim>. |
| 196 | + It contains the Vim program that tidies the name fields |
| 197 | + of all Forth words in the final Z80 source. |
| 198 | + |
| 199 | +tidy_z80.vim :: |
| 200 | + This file contains the Vim program that does all the |
| 201 | + non-automatic tidy task in the final final Z80 source. |
| 202 | + |
| 203 | +word_labels.name_fields.vim :: |
| 204 | + This Vim program translates the temporary Z80 labels |
| 205 | + used in <abersoftforth2nfa4vim_printout.txt> |
| 206 | + (the file created by AbersoftForth2nfa4vim), |
| 207 | + in order to create the file <tidy_name_fields.vim>. |
| 208 | + |
| 209 | +word_labels.z80dasm_blocks.vim :: |
| 210 | + This Vim program translates the temporary Z80 labels |
| 211 | + used in <abersoftforth2z80dasmblocks_printout.txt> |
| 212 | + (the file created by AbersoftForth2z80dasmblocks), |
| 213 | + in order to create the file <abersoftforth2z80dasmblocks_printout.tidy.txt>. |
| 214 | + |
| 215 | +z80dasm_blocks.custom.txt :: |
| 216 | + This file contains block definitions for z80dasm that can not be calculated |
| 217 | + by AbersoftForth2z80dasmblocks. |
| 218 | + |
| 219 | +z80dasm_blocks.txt :: |
| 220 | + This is the blocks definitions file used as input for z80dasm. |
| 221 | + It's simply a concatenation of |
| 222 | + <abersoftforth2z80dasmblocks_printout.tidy.txt> and |
| 223 | + <z80dasm_blocks.custom.txt>. It is needed because z80dasm accepts only one file with |
| 224 | + block definitions. |
| 225 | + |
| 226 | +z80dasm_symbols.z80s :: |
| 227 | + The main symbols file used as input for z80dasm. |
| 228 | + |
| 229 | +zx_spectrum_rom_routines.z80s :: |
| 230 | + Labels of ZX Spectrum ROM routines. |
| 231 | + |
| 232 | +zx_spectrum_system_variables.z80s :: |
| 233 | + Labels of ZX Spectrum system variables. |
| 234 | + |
| 235 | +=== Result |
| 236 | + |
| 237 | +abersoft_forth.disassembled.raw.z80s :: |
| 238 | + Source file created by z80dasm from <abersoft_forth.padded.bin>. |
| 239 | +abersoft_forth.disassembled.z80s :: |
| 240 | + Final result, created by Vim from <abersoft_forth.disassembled.raw.z80s> |
| 241 | + with the commands in <tidy_z80.vim>. |
| 242 | + |
| 243 | +=== The rebuilt sytem |
| 244 | + |
| 245 | +In order to check that the disassembling is perfect, |
| 246 | +<abersoft_forth.disassembled.z80s> is compiled by Pasmo. |
| 247 | + |
| 248 | +abersoft_forth_loader.bas :: |
| 249 | + The source of the new BASIC loader. |
| 250 | +abersoft_forth_loader.tap :: |
| 251 | + The new BASIC loader in TAP format. |
| 252 | +abersoft_forth.rebuilt.bin.tap :: |
| 253 | + The new recompiled binary in TAP format. |
| 254 | +abersoft_forth.rebuilt.symbols.z80s :: |
| 255 | + The symbols file created by Pasmo during the compilation. |
| 256 | +abersoft_forth.rebuilt.tap :: |
| 257 | + The new system, ready to be loaded by an emulator. |
35 | 258 |
|
36 |
| -6. Command `make z80`. |
|
0 commit comments