Skip to content

Commit

Permalink
Merge branch 'v0.9-dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/cc64/scanner.fth
#	tests/unit/Makefile
#	tests/unit/build-run-test.sh
#	tests/unit/scanner-test.fth
#	tests/unit/scanner-test.golden
  • Loading branch information
pzembrod committed May 2, 2021
2 parents 0e62182 + 8bf6608 commit d22b2af
Show file tree
Hide file tree
Showing 185 changed files with 6,518 additions and 656 deletions.
8 changes: 4 additions & 4 deletions C-lang-subset.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ accordingly.
- No implicit `int f(int i)` function declaration.
All functions must be declared or defined before first calling them.
- No real preprocessor.
- - `#define` just defines a constant on the compiler level. There's no
- `#define` just defines a constant on the compiler level. There's no
text substitution as such.
- - Accordingly no macros with parameters. No #undef. No #ifdef/#ifndef.
- - `#include` works as expected, with max 4 levels of include files.
- - `#pragma cc64` defines the memory layout for the code generator and is
- Accordingly no macros with parameters. No #undef. No #ifdef/#ifndef.
- `#include` works as expected, with max 4 levels of include files.
- `#pragma cc64` defines the memory layout for the code generator and is
described in [runtime libraries](Runtime-libs.md).


Expand Down
72 changes: 37 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ c16: cc64-c16-t64 $(c16dir_files) cc64-c16files.zip cc64-c16files.d64

x16: $(x16dir_files) cc64-x16files.zip cc64-x16files-sdcard.zip

cc64-c64-t64: $(cc64_c64_t64_files)
cc64-c64-t64: $(cc64_c64_t64_files) autostart-c64/cc64prof.T64

cc64-c16-t64: $(cc64_c16_t64_files)

Expand All @@ -84,10 +84,6 @@ cc64-x16files.zip: $(x16dir_files) COPYING
rm -f $@
zip -r $@ $^

$(recompile_dir).zip: $(recompile_srcs) $(recompile_forths) COPYING
rm -f $@
zip -r $@ $^

cc64-c64files.d64: $(c64dir_files) tmp/copying
rm -f $@
c1541 -format cc64-c64,cc d64 $@
Expand Down Expand Up @@ -190,10 +186,10 @@ clean:
rm -f c64files/*.fth c16files/*.fth x16files/*.fth
rm -f c64files/*.log c16files/*.log x16files/*.log
rm -f x16files.img recompile-readme
rm -f [cx][16][64]files/notdone
rm -f emulator/sdcard.img tmp/* cc64-doc.zip
rm -rf release
rm -f [cx][16][64]files/notdone cc64-doc.zip
rm -rf release tmp/*
rm -rf $(recompile_dir) $(recompile_dir).zip
$(MAKE) -C emulator clean
$(MAKE) -C tests/e2e clean
$(MAKE) -C tests/integration clean
$(MAKE) -C tests/peddi clean
Expand All @@ -210,10 +206,14 @@ veryclean: clean
rm -f autostart-c64/*.T64 autostart-c16/*.T64
rm -f runtime/*

# Convenience rule for interactive debugging/developing:
# Provide all Forth sources in c64files/ in PETSCII format.
petscii64: $(cc64srcs_c64) $(peddisrcs_c64)


test64: autostart-c64/cc64.T64
$(MAKE) -C tests/e2e fasttests64
$(MAKE) -C tests/unit tests
$(MAKE) -C tests/e2e fasttests64
$(MAKE) -C tests/integration tests

alltests: sut
Expand All @@ -234,33 +234,41 @@ slowtests: sut
$(MAKE) -C tests/integration tests
$(MAKE) -C tests/peddi tests

sut: autostart-c64/cc64.T64 autostart-c16/cc64.T64 x16files/cc64

sut: autostart-c64/cc64.T64 autostart-c16/cc64.T64 x16files/cc64 \
autostart-c64/cc64pe.T64 autostart-c16/cc64pe.T64 \
autostart-c64/peddi.T64 autostart-c16/peddi.T64 \
autostart-c64/cc64prof.T64

# cc64 build rules

%files/cc64: $(cc64srcs_c64) $(cc64srcs_c16) \
build/build-cc64.sh emulator/run-in-vice.sh \
emulator/build-binary.sh emulator/run-in-vice.sh \
autostart-%/vf-build-base.T64
build/build-cc64.sh $*
emulator/build-binary.sh $* cc64

%files/cc64pe: \
$(cc64srcs_c64) $(cc64srcs_c16) \
$(peddisrcs_c64) $(peddisrcs_c16) \
build/build-cc64pe.sh emulator/run-in-vice.sh \
emulator/build-binary.sh emulator/run-in-vice.sh \
autostart-%/vf-build-base.T64
build/build-cc64pe.sh $*
emulator/build-binary.sh $* cc64pe

%files/peddi: $(peddisrcs_c64) $(peddisrcs_c16) \
build/build-peddi.sh emulator/run-in-vice.sh \
emulator/build-binary.sh emulator/run-in-vice.sh \
autostart-%/vf-build-base.T64
build/build-peddi.sh $*
emulator/build-binary.sh $* peddi


x16files/cc64: $(cc64srcs_x16) \
build/build-cc64.sh emulator/run-in-x16emu.sh \
x16files/vf-build-base emulator/sdcard.img
build/build-cc64.sh x16
emulator/build-binary.sh emulator/run-in-x16emu.sh \
x16files/vf-build-base
emulator/build-binary.sh x16 cc64


c64files/cc64prof: $(cc64srcs_c64) \
emulator/build-binary.sh emulator/run-in-vice.sh \
autostart-c64/vf-build-base.T64
emulator/build-binary.sh c64 cc64prof


# build base rule
Expand All @@ -281,28 +289,28 @@ $(recompile_dir)/%: forth/%
# Runtime module rules

runtime/rt-c64-0801.o runtime/rt-c64-0801.h: \
src/runtime/rt-c64-0801.a build/generate_pragma_cc64.awk
src/runtime/rt-c64-0801.a src/runtime/generate_pragma_cc64.awk
test -d tmp || mkdir tmp
acme -f cbm -l tmp/rt-c64-0801.sym -o runtime/rt-c64-0801.o \
src/runtime/rt-c64-0801.a
awk -f build/generate_pragma_cc64.awk -F '$$' tmp/rt-c64-0801.sym \
> runtime/rt-c64-0801.h
awk -f src/runtime/generate_pragma_cc64.awk -F '$$' \
tmp/rt-c64-0801.sym > runtime/rt-c64-0801.h

runtime/rt-c16-1001.o runtime/rt-c16-1001.h: \
src/runtime/rt-c16-1001.a build/generate_pragma_cc64.awk
src/runtime/rt-c16-1001.a src/runtime/generate_pragma_cc64.awk
test -d tmp || mkdir tmp
acme -f cbm -l tmp/rt-c16-1001.sym -o runtime/rt-c16-1001.o \
src/runtime/rt-c16-1001.a
awk -f build/generate_pragma_cc64.awk -F '$$' tmp/rt-c16-1001.sym \
> runtime/rt-c16-1001.h
awk -f src/runtime/generate_pragma_cc64.awk -F '$$' \
tmp/rt-c16-1001.sym > runtime/rt-c16-1001.h

runtime/rt-x16-0801.o runtime/rt-x16-0801.h: \
src/runtime/rt-x16-0801.a build/generate_pragma_cc64.awk
src/runtime/rt-x16-0801.a src/runtime/generate_pragma_cc64.awk
test -d tmp || mkdir tmp
acme -f cbm -l tmp/rt-x16-0801.sym -o runtime/rt-x16-0801.o \
src/runtime/rt-x16-0801.a
awk -f build/generate_pragma_cc64.awk -F '$$' tmp/rt-x16-0801.sym \
> runtime/rt-x16-0801.h
awk -f src/runtime/generate_pragma_cc64.awk -F '$$' \
tmp/rt-x16-0801.sym > runtime/rt-x16-0801.h

runtime/rt-c64-0801.i:
awk 'BEGIN{ printf("\x00\x90");}' > $@
Expand Down Expand Up @@ -390,12 +398,6 @@ autostart-x16/%.T64: x16files/%
bin2t64 $< $@


# X16 emulator rules

emulator/sdcard.img: emulator/sdcard.sfdisk emulator/mk-sdcard.sh
emulator/mk-sdcard.sh emulator/sdcard.sfdisk $@


# Generic rules to populate c64files/, c16files/, x16files/

c64files/%.fth: src/*/%.fth
Expand Down
38 changes: 19 additions & 19 deletions Runtime-libs.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ in hex, and one string parameter, a file base name. It has the following form:
*statics-start*, *statics-end*, *rt-basename*

- *cc-sp*:
- - a zero page address pair used as stack pointer for C local variables
- a zero page address pair used as stack pointer for C local variables
- *zp*:
- - a second zero page address pair that the compiled code may use
- a second zero page address pair that the compiled code may use
- *rt-start*:
- - the first code address of the runtime module
- the first code address of the runtime module
- *rt-jumplist*:
- - the address of the runtime modules jump list (see below)
- the address of the runtime modules jump list (see below)
- *rt-end*:
- - the first free code address after the end of the runtime module
- the first free code address after the end of the runtime module
- *statics-start*:
- - the lowest address of the runtime module's static vars
- the lowest address of the runtime module's static vars
- *statics-end*:
- - the hightest address + 1 of the runtime module's static vars
- the hightest address + 1 of the runtime module's static vars
- *rt-basename*:
- - the base filename of the runtime module. *basename*.o is then the
- the base filename of the runtime module. *basename*.o is then the
code, *basename*.i the initialzation values of the module's static vars. (Of
course *basename*.h is the header file containing the module's symbol
definitions and the #pragma cc64 directive.)
Expand All @@ -125,17 +125,17 @@ statics_last .word 0
The first part of the jumplist is a list of 4 addresses:

- `rt_jumplist`
- - This address (equal to main_addr, of course) is #pragma cc64's 4th param
- This address (equal to main_addr, of course) is #pragma cc64's 4th param
and the runtime module's anchor for the compiler.
- `main_adr`
- - Here the main()-function's address is inserted by the compiler. The
- Here the main()-function's address is inserted by the compiler. The
runtime module's initialization calls main() with a jmp (main.adr).
- `code_last`
- - Here the last address + 1 of the generated code is inserted by the compiler.
- Here the last address + 1 of the generated code is inserted by the compiler.
- `statics_first`
- - Here the first address of the generated code is inserted by the compiler.
- Here the first address of the generated code is inserted by the compiler.
- `statics_last`
- - Here the last address + 1 of the generated code is inserted by the compiler.
- Here the last address + 1 of the generated code is inserted by the compiler.

As described above, statics are allocated from the end of the used memory
downwards. The statics' initialization values are placed by the
Expand All @@ -147,10 +147,10 @@ In case of no static variables, init_first will be equal to init_last.
After the addresses follows a list of 6 jmp instructions:

- `jmp (zp)`
- - This it is used to emulate `jsr (zp)`. zp is the second zero
- This it is used to emulate `jsr (zp)`. zp is the second zero
page pointer used by the compiler.
- `jmp switch`
- - Code generated for switch statements consists of loading into a/x
- Code generated for switch statements consists of loading into a/x
the 16 bit value to match to case statements and a jsr to this address.
Following the calling jsr-instruction will be an array of pairs of 16 bit
values, one pair per case statement. The second value in each pair is the case
Expand All @@ -163,15 +163,15 @@ It then compares a/x to the 2nd value of each pair, jumps to the pair's first
address in case of match, and in case of no match jumps behind the terminating
0 at the end of the list.
- jmp mult
- - Multiplies (signed) the content of a/x with the integer in zp/zp+1,
- Multiplies (signed) the content of a/x with the integer in zp/zp+1,
leaving the result in a/x.
- jmp divmod
- - Divides (signed) zp/zp+1 by a/x, leaving the result in a/x and the
- Divides (signed) zp/zp+1 by a/x, leaving the result in a/x and the
remainder in zp/zp+1.
- jmp shl
- - Arithmetically shifts left a/x by y bits.
- Arithmetically shifts left a/x by y bits.
- jmp shr
- - Arithmetically shifts right a/x by y bits.
- Arithmetically shifts right a/x by y bits.

The jumplist may be positioned anywhere in the library.

Expand Down
66 changes: 42 additions & 24 deletions Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,72 +107,72 @@ can be given either in decimal or, with a preceeding $, in hex.
### Main commands

- `help`
- - shows a list of all commands
- shows a list of all commands
- `cc` _file.c_
- - compiles _file.c_, producing
- - - a binary executable _file_ if _file.c_ contains a `main()` function
- - - an extended runtime library consisting of _file.h_, _file.i_, _file.o_
- compiles _file.c_, producing
- a binary executable _file_ if _file.c_ contains a `main()` function
- an extended runtime library consisting of _file.h_, _file.i_, _file.o_
otherwise
- `ed` _file_
- - opens _file_ in the text editor
- opens _file_ in the text editor
- `cat` _file_
- - displays the content of _file_ on the screen
- displays the content of _file_ on the screen
- `bye`
- - exits cc64
- exits cc64

### Disk commands

- `dos`
- - reads and prints the error channel of the cc64's configured main disk drive
- reads and prints the error channel of the cc64's configured main disk drive
(see `device?` and `device` below)
- `dos` _xxx_
- - sends the command _xxx_ to cc64's configured main disk drive
- sends the command _xxx_ to cc64's configured main disk drive
- `dir`
- - lists the directory of cc64's configured main disk drive
- lists the directory of cc64's configured main disk drive
- `device?`
- - shows the device number of the disk drive cc64 uses for source files and
- shows the device number of the disk drive cc64 uses for source files and
compilation outputs, and the device number of the auxiliary disk drive where
cc64 places temporary files during compile. By default these are the same,
and there's only a reason to change that if space on the main drive becomes
an issue. Note: Currently the `dos` command only works on the main drive.
- _n_ `device`
- - configures cc64 to use device _n_ as main disk drive
- configures cc64 to use device _n_ as main disk drive
- _n_ `auxdev`
- - configures cc64 to use device _n_ as auxiliary disk drive for temp files
- configures cc64 to use device _n_ as auxiliary disk drive for temp files

### Memory commands

- `mem`
- - displays the compiler's memory setup
- displays the compiler's memory setup
- _nnn_ `set-himem`
- - sets the upper limit of the compiler's memory to _nnn_. Default value is
- sets the upper limit of the compiler's memory to _nnn_. Default value is
$cbd0. The memory $cbd0-$cfff is needed by [c-charset](#c-charset) which cc64
recognizes and activates if it is installed. If a c-chargen rom generated by
[c-char-rom-gen](#c-char-rom-gen) is used, e.g. in an emulator, or if no C
charset (which provides the characters \^_{|}~) is desired, then himem can be
set to $d000.
- _nnn_ `set-heap`
- - sets the heap to _nnn_ elements. One heap element is needed for each forward
- sets the heap to _nnn_ elements. One heap element is needed for each forward
function reference, i.e. for each function that is called before it is defined.
A prototype, i.e. a declaraion, must exist before a function can be called.
- _nnn_ `set-hash`
- - sets the hash table size for global symbols. Needs at least one element per
- sets the hash table size for global symbols. Needs at least one element per
compiled global symbol and should be sized reasonably generous for hasing to
be efficient. I'm sorry to say I don't have data yet, though.
- _nnn_ `set-symtab`
- - sets the symbol table size in bytes. This is used both for local and
- sets the symbol table size in bytes. This is used both for local and
global symbols and must be increased if a symbol table overflow error occurs.
- _nnn_ `set-code`
- - sets the size of the code buffer in bytes. The compiled code for each
- sets the size of the code buffer in bytes. The compiled code for each
individual compiled function must fit completely into this buffer. Otherwise,
a function too long error is thrown.
- - The remaining memory aka staticbuffer is used to buffer initialization values
- The remaining memory aka staticbuffer is used to buffer initialization values
of static variables. Its size isn't critical as it is flushed to file when full;
it just needs to be positive.
- - Not available on the X16 where a fixed code buffer of 8 kB lives in
- Not available on the X16 where a fixed code buffer of 8 kB lives in
banked RAM.
- _nnn_ _mmm_ `set-stacks`
- - sets the size of data stack (_nnn_ bytes) and return stack (_mmm_ bytes)
- sets the size of data stack (_nnn_ bytes) and return stack (_mmm_ bytes)
and resets the system. Note that the sizes shown by `mem` will be _nnn_ minus 6
and _mmm_ plus 6.
The stack sizes determine the maximum depth of arithmetic expressions and the
Expand All @@ -183,9 +183,19 @@ are, and alas again I don't have any data to guide by yet.
Should the compiler behave strangely on some deeply nested code, it should
be reloaded freshly from disk, and the stack sizes set to higher values.
- `saveall` _name_
- - saves the complete compiler together with its actual memory settings to a
f- saves the complete compiler together with its actual memory settings to a
new file _name_

### Misc commands

- `1 list!`
- `0 list!`
- switches listing the C source while compiling on respectively off. Default is off. Listing can cause ~25% increase in pass1 compile time.
- `list?`
- shows whether listing is currently on or off.
- `exec` _file_
- reads _file_ and executes the commands therein. This can be used e.g. to script compile operations.


## Peddi

Expand All @@ -194,7 +204,7 @@ There's no limit in line length (exept memory).
Memory overflow is signalled by a double flash of the screen border.
Peddi is called with

`ed filename`
`ed` _file_

Inside the editor, there are these key bindings:
```
Expand Down Expand Up @@ -370,3 +380,11 @@ run, will the ROM charset into RAM (at $c000), patch the needed characters,
and then save the RAM $c000-$cfff to disk in a file named `c-chargen` which
then can be used by an emulator as chargen or programmed into an (E)EPROM and
used in a real C64.

## Keyboard

There are two custom keyboard maps for VICE available in the
[emulator/](https://github.com/pzembrod/cc64/tree/master/emulator) directory that I use under Linux to map the C characters \^_{|}~ symbolically to the respective keys on the host keymap, one for the
[C64](https://github.com/pzembrod/cc64/blob/master/emulator/x11_sym_c64_vf_de.vkm) and one for the [C16](https://github.com/pzembrod/cc64/blob/master/emulator/x11_sym_c16_vf_de.vkm). The options I use are visible [here](https://github.com/pzembrod/cc64/blob/master/emulator/which-vice.sh), and I should add the disclaimer that I use German keyboard layouts, though I believe this should not matter since the key mapping used is symbolic, not positional.

For x16emu I currently actually don't know how to type those keys in PETSCII mode. The right thing to do is likely anyway to compile an ISO version of cc64 - which is on my road map.
Loading

0 comments on commit d22b2af

Please sign in to comment.