commit 5930b958b45f25f519251a668c8d81801f3a2c94 Author: brad Arant Date: Mon Nov 30 18:09:18 2026 -0800 Basys 3 RISC-V computer The Basys 3 Z-80 computer with the Z-80 replaced by an RV32IM processor written from scratch (rtl/rv32_cpu.v): multi-cycle, 90 MHz, CSRs and traps, interrupts, two hardware triggers and a resumable NMI for the monitor. Passes riscv-tests rv32ui/um/mi. rv32_system.v keeps all the Z-80 machine's peripherals, with I/O port N at FFFFFF00h + N, 80 KB of RAM with BASIC preloaded, and a 32 KB monitor ROM. BASIC, the five games and the monitor (with an RV32 disassembler, assembler, breakpoints and single step) are ported to RISC-V GCC. Python emulator and tests in tools/; full-system simulation in sim/. Co-Authored-By: Claude Opus 5.5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d659ee9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +build/ +sim/work/ +sim/cpu/ +.Xil/ +*.jou +*.log +*.pb +__pycache__/ +third_party/ +*_out.txt +sim_time.txt +out/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e82a92f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Brad Arant + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4325fa4 --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +# Basys 3 RISC-V Computer + +The [Basys 3 Z-80 computer](https://git.barant.com/barant/Basys3Terminal) with +the Z-80 replaced by a RISC-V processor written from scratch in Verilog. The +rest is the same machine: a VT220 terminal with ANSI colour on 1280×1024 VGA, +320×240 graphics in 16 colours with hardware scrolling and 32 sprites, a +three-voice sound chip (PmodAMP2 on JA), the keyboard on the USB host port +(with a keys-held port for games), files in the configuration flash, +Dartmouth-style BASIC, a machine-code monitor and five games. + +Flip **SW15** up and the terminal is the computer's console. BASIC and the +monitor are described in [docs/basic-manual.md](docs/basic-manual.md); the +terminal itself (SW15 down) works exactly as in the Z-80 project, whose README +covers it. + +## The processor (`rtl/rv32_cpu.v`) + +RV32IM in machine mode: the base integer set, multiply/divide, CSRs, counters +(`cycle`, `time`, `instret`), `fence.i`, `ecall`/`ebreak`/`mret`/`wfi`, traps +and interrupts (`mtvec`, `mepc`, `mcause`, `mtval`; software, timer, external +and 16 local interrupt lines), two hardware triggers for execute, load and +store breakpoints, and a resumable NMI (after the Smrnmi extension: `mnepc`, +`mnstatus`, `mnret`) with a single-step input, for the monitor. + +It is a multi-cycle design with the next instruction fetched while the current +one decodes: 2 clocks for most instructions, 3 for taken branches, jumps, loads +and stores, 4 for multiplies, 35 for divides; BASIC averages about 2.5. It +runs at 90 MHz (the Z-80's clock) and takes about 2,100 LUTs, 900 flip-flops +and 4 DSP slices. + +## The machine (`rtl/rv32_system.v`) + +| Addresses | | +|---|---| +| 0000_0000–0001_3FFF | RAM, 80 KB of block RAM, BASIC preloaded; writes below A000h (BASIC's code) are ignored | +| 0002_0000–0002_7FFF | the monitor's ROM (32 KB of block RAM); the NMI enters at 20000h, traps at 20004h | +| 0002_8000–0002_9FFF | the monitor's RAM (8 KB of distributed RAM, data only) | +| FFFF_FE00–FFFF_FEFF | 32-bit registers: milliseconds, microseconds, the timer interrupt's compare, breakpoints | +| FFFF_FF00–FFFF_FFFF | the Z-80 machine's I/O ports: port *N* at FFFF_FF00 + *N*, one instruction from `x0` (`sb a0,-255(zero)` is `OUT (1),A`) | + +The peripherals are the Z-80 machine's, unchanged in function: `term_ctrl.v`, +`text_display.v`, `sprites.v`, `sound.v`, `flash_spi.v`, `uart.v`, +`ps2_keyboard.v`, `sevenseg.v`. To make room in block RAM for the wider +processor's memory, the text screen and the graphics framebuffer are each +split into a power-of-two array and a small one (Vivado builds an array of +16,896 or 76,800 entries as 32K or 96K deep); that saves 10.5 block RAMs and +changes nothing else. + +Resources at 90 MHz: see `build/utilization.rpt` and `build/timing.rpt` after a +build. + +## Software + +All in C (plus a little assembly), compiled with GCC for `rv32im`: + +- `basic/` — BASIC, ported from the Z-80 version: the same language, the same + manual. `lib/` has the few C library functions it needs (small string + functions, `setjmp`, and single-precision `sinf` … `sqrtf`), since newlib's + bring in its stdio and malloc. Floating point is IEEE single precision from + libgcc, correctly rounded (the Z-80's SDCC library wasn't, so the last digit + of a result can differ). +- `monitor/` — the machine-code monitor, with a RISC-V disassembler and a + two-pass assembler in place of the Z-80 ones. +- `games/` — The Iron Keep, Bastion Raid, Star Warden, Star Swarm and Crystal + Cavern, recompiled; they load at A200h (`CALL 41472`). + +## Building + +```bash +export VIVADO=~/vivado/2025.2/Vivado +``` + +```bash +basic/build.sh && monitor/build.sh && for g in keep raid warden swarm cavern; do games/build-game.sh $g; done +``` + +```bash +scripts/build.sh +``` + +`scripts/build.sh program` loads the bitstream over JTAG; `flash` writes it to +the configuration flash. + +Games go onto the board as in the Z-80 project: `tools/send-hex.py +games/keep/keep.ihx --save KEEPGAME --baud 3000000`, then `tools/send-bas.py +games/keep/keep.bas` and `SAVE "KEEP"` in BASIC. + +## Tests + +| | | +|---|---| +| `scripts/cputest.sh` | the official [riscv-tests](https://github.com/riscv-software-src/riscv-tests) (`rv32ui`, `rv32um`, `rv32mi`, fetched into `third_party/`) and `tests/` (interrupts, the NMI and single step) on `rv32_cpu.v` in xsim, with random wait states on the data bus. Two riscv-tests don't apply: `ma_data` expects misaligned loads and stores to work (here they trap, as the spec allows) and `pmpaddr` needs PMP. | +| `scripts/sim.sh` | the whole design in xsim: the terminal, BASIC, graphics, sprites, scrolling, flash files, the monitor (step, breakpoint, Pause, memory files, the assembler, Intel HEX), 3 Mbaud. `scripts/sim.sh quick` skips the terminal and the monitor. | +| `monitor/test-disasm.py`, `test-asm.py` | the disassembler against GNU objdump on thousands of random instructions, and the assembler against GNU as | +| `basic/test-*.py`, `games/*/test-*.py` | BASIC's line editor, RENUM and string arrays, and each game, on `tools/rv32emu.py` (a Python RV32IM emulator of the machine; `tools/boardemu.py` models the game hardware). They need `pyte` and Pillow. | +| `bench/` | the processor alone with 64 KB of RAM, for timing | + +## Toolchain + +- Vivado (2025.2 is the licensed install here). +- RISC-V GCC: Vivado ships one for MicroBlaze V (`~/vivado/*/gnu/riscv/lin/bin/riscv64-unknown-elf-gcc`, + GCC 13 with an `rv32im/ilp32` multilib), which `scripts/rv_env.sh` finds + if there is no `riscv64-unknown-elf-gcc` on the PATH. `RV_PREFIX` overrides. diff --git a/basic/basic-hi.mem b/basic/basic-hi.mem new file mode 100644 index 0000000..e3e3f06 --- /dev/null +++ b/basic/basic-hi.mem @@ -0,0 +1,4096 @@ +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 diff --git a/basic/basic.bin b/basic/basic.bin new file mode 100755 index 0000000..15c19be Binary files /dev/null and b/basic/basic.bin differ diff --git a/basic/basic.c b/basic/basic.c new file mode 100644 index 0000000..34b2bf1 --- /dev/null +++ b/basic/basic.c @@ -0,0 +1,2381 @@ +/* + * Dartmouth-style BASIC for the Basys 3 RISC-V computer. + * + * Numbered program lines, LET PRINT INPUT IF..THEN GOTO GOSUB RETURN + * FOR..TO..STEP NEXT DIM DEF FN READ DATA RESTORE ON..GOTO/GOSUB END STOP REM + * RANDOMIZE, the classic functions SIN COS TAN ATN EXP LOG ABS SQR INT RND SGN + * TAB, plus string variables A$..Z$ with LEN VAL ASC CHR$ STR$ LEFT$ RIGHT$ + * MID$, PEEK/POKE, INP/OUT and TIM. Commands: RUN LIST NEW (SCRATCH) and any + * statement typed without a line number runs at once. Ctrl-C stops a program. + * + * Graphics: 320x240 in 16 colours over the text, origin top left, colour 0 + * transparent. CLS COLOR PLOT LINE RECT FILL CIRCLE and POINT(x,y); LOCATE and + * INK place and colour text. + * + * Files: SAVE "NAME", LOAD "NAME", RUN "NAME", DIR, DEL "NAME" keep programs + * in the spare part of the configuration flash (see the file system below). + * + * Builds with GCC for RV32IM (console on I/O ports 0/1, memory-mapped) or with + * a host C compiler for testing (stdin/stdout). + */ +#include +#include +#include +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef uint32_t u32; + +/* ------------------------------------------------------------- platform */ +#ifdef __riscv +#include "basys3.h" +#define con_stat IO8(0x00) /* bit 0: key waiting, bit 1: can send */ +#define con_data IO8(0x01) + +static void out_c(u8 c) { while (!(con_stat & 2)); con_data = c; } +static int poll_c(void) { return con_stat & 1 ? con_data : -1; } +static u8 wait_c(void) { while (!(con_stat & 1)); return con_data; } +static i32 millis(void) { return (i32)IO_MS; } +/* PEEK and POKE take any address: RAM is 0-65535, port N is -256 + N */ +static u8 peek(u32 a) { return *(volatile u8 *)a; } +static void poke(u32 a, u8 v) { *(volatile u8 *)a = v; } +static u8 io_in(u8 p) { return IO8(p); } +static void io_out(u8 p, u8 v) { IO8(p) = v; } +static void bye(void) { } + +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) /* write plots and moves right; read gives the colour */ +#define gfill IO8(0x34) +static void g_at(u16 x, u8 y) { gx_lo = x; gx_hi = x >> 8; gy_p = y; } +static void g_put(u8 c) { gpix = c; } +static u8 g_get(void) { return gpix; } +static void g_clear(u8 c) { gfill = c; while (gfill & 1); } + +/* SPI flash: port 40h opens/ends a command (bit 1 reads back "refused"), + 41h shifts a byte. The hardware refuses to write below the file area. */ +#define fl_ctl IO8(0x40) +#define fl_dat IO8(0x41) +static u8 spi(u8 b) { fl_dat = b; while (fl_ctl & 1); return fl_dat; } +static void fl_open(u8 cmd) { fl_ctl = 1; spi(cmd); } +static void fl_close(void) { fl_ctl = 0; } +static void fl_addr(u32 a) { spi(a >> 16); spi(a >> 8); spi(a); } +static u8 fl_busy(void) +{ + u8 st; + fl_open(0x05); st = spi(0); fl_close(); + return st & 1; +} +static u8 fl_present(void) /* Macronix MX25L3273F, 4 KB sectors */ +{ + u8 a, b, c; + fl_open(0x9F); a = spi(0); b = spi(0); c = spi(0); fl_close(); + return a == 0xC2 && b == 0x20 && c == 0x16; +} +static void fl_read(u32 a, u8 *p, u16 n) +{ + fl_open(0x03); fl_addr(a); + while (n--) *p++ = spi(0); + fl_close(); +} +/* page program (02) or sector erase (20); returns 0 if the hardware refused */ +static u8 fl_write_op(u8 cmd, u32 a, const u8 *p, u16 n) +{ + u8 ok; + fl_open(0x06); fl_close(); + fl_open(cmd); fl_addr(a); + while (n--) spi(*p++); + ok = !(fl_ctl & 2); + fl_close(); + return ok; +} +#else +#include +#include +#include +static void out_c(u8 c) { if (c != '\r') putchar(c); } +static int poll_c(void) { return -1; } +static u8 wait_c(void) +{ + int c; + fflush(stdout); + c = getchar(); + if (c == EOF) exit(0); + return c == '\n' ? '\r' : c; +} +static i32 millis(void) { return (i32)(clock() / (CLOCKS_PER_SEC / 1000)); } +static u8 fake_mem[65536]; +static u8 peek(u32 a) { return fake_mem[a & 0xFFFF]; } +static void poke(u32 a, u8 v) { fake_mem[a & 0xFFFF] = v; } +static u8 io_in(u8 p) { (void)p; return 0xFF; } +static void io_out(u8 p, u8 v) { (void)p; (void)v; } +static void close_all(void); +static void bye(void) { close_all(); exit(0); } +static u8 gmem[240][320]; +static u16 hgx; +static u8 hgy; +static void g_at(u16 x, u8 y) { hgx = x; hgy = y; } +static void g_put(u8 c) { if (hgx < 320 && hgy < 240) gmem[hgy][hgx] = c; hgx++; } +static u8 g_get(void) { return hgx < 320 && hgy < 240 ? gmem[hgy][hgx] : 0; } +static void g_clear(u8 c) { memset(gmem, c, sizeof gmem); } + +/* flash file area kept in basic-flash.img */ +#define HOST_BASE 0x240000UL +static u8 hflash[0x1C0000]; +static u8 hflash_loaded; +static void hflash_load(void) +{ + FILE *f; + if (hflash_loaded) return; + hflash_loaded = 1; + memset(hflash, 0xFF, sizeof hflash); + if ((f = fopen("basic-flash.img", "rb"))) { fread(hflash, 1, sizeof hflash, f); fclose(f); } +} +static void hflash_store(void) +{ + FILE *f = fopen("basic-flash.img", "wb"); + if (f) { fwrite(hflash, 1, sizeof hflash, f); fclose(f); } +} +static u8 fl_busy(void) { return 0; } +static u8 fl_present(void) { hflash_load(); return 1; } +static void fl_read(u32 a, u8 *p, u16 n) { hflash_load(); memcpy(p, hflash + a - HOST_BASE, n); } +static u8 fl_write_op(u8 cmd, u32 a, const u8 *p, u16 n) +{ + u8 *d; + hflash_load(); + if (a < HOST_BASE || a >= HOST_BASE + sizeof hflash) return 0; + d = hflash + a - HOST_BASE; + if (cmd == 0x20) memset(hflash + ((a - HOST_BASE) & ~4095UL), 0xFF, 4096); + else while (n--) *d++ &= *p++; + hflash_store(); + return 1; +} +#endif + +/* ---------------------------------------------------------- file channels */ +#define FBLK 8 /* blocks per file: 32 KB */ +#define NCHAN 4 /* 0 is SAVE and LOAD's, 1-3 are for OPEN */ +struct chan { + u8 mode; /* 0 closed, 'I' reading, 'O' writing */ + char name[8]; + u16 len, pos, pg; /* reading: length, position, page held in buf */ + u16 blk[FBLK]; + u8 col; /* PRINT # column */ + u8 buf[256]; +}; +static struct chan ch[NCHAN]; +static struct chan *chan_arg(u8 mode); +static u8 chan_line(struct chan *c); + +/* ----------------------------------------------------------------- tokens */ +enum { + T_LET = 0x80, T_PRINT, T_INPUT, T_IF, T_THEN, T_GOTO, T_GOSUB, T_RETURN, T_FOR, + T_TO, T_STEP, T_NEXT, T_DIM, T_DEF, T_END, T_STOP, T_REM, T_READ, T_DATA, + T_RESTORE, T_ON, T_RANDOMIZE, T_POKE, T_OUT, T_RUN, T_LIST, T_NEW, T_SCRATCH, + T_BYE, T_CLS, T_COLOR, T_PLOT, T_LINE, T_RECT, T_FILL, T_CIRCLE, T_LOCATE, T_INK, + T_SAVE, T_LOAD, T_DIR, T_DEL, T_DATE, T_OPEN, T_CLOSE, T_MONITOR, T_CALL, T_BSAVE, T_BLOAD, T_OUTPUT, T_APPEND, T_AND, T_OR, T_NOT, T_SIN, T_COS, T_TAN, T_ATN, T_EXP, T_LOG, T_ABS, + T_SQR, T_INT, T_RND, T_SGN, T_FN, T_TAB, T_PEEK, T_INP, T_LEN, T_VAL, T_ASC, T_EOF, + T_CHRS, T_STRS, T_LEFTS, T_RIGHTS, T_MIDS, T_DATES, T_TIM, T_POINT, T_LE, T_GE, T_NE, T_RENUM, T_LAST +}; + +static const char *const kw[] = { + "LET", "PRINT", "INPUT", "IF", "THEN", "GOTO", "GOSUB", "RETURN", "FOR", + "TO", "STEP", "NEXT", "DIM", "DEF", "END", "STOP", "REM", "READ", "DATA", + "RESTORE", "ON", "RANDOMIZE", "POKE", "OUT", "RUN", "LIST", "NEW", "SCRATCH", + "BYE", "CLS", "COLOR", "PLOT", "LINE", "RECT", "FILL", "CIRCLE", "LOCATE", "INK", + "SAVE", "LOAD", "DIR", "DEL", "DATE", "OPEN", "CLOSE", "MONITOR", "CALL", "BSAVE", "BLOAD", "OUTPUT", "APPEND", "AND", "OR", "NOT", "SIN", "COS", "TAN", "ATN", "EXP", "LOG", "ABS", + "SQR", "INT", "RND", "SGN", "FN", "TAB", "PEEK", "INP", "LEN", "VAL", "ASC", "EOF", + "CHR$", "STR$", "LEFT$", "RIGHT$", "MID$", "DATE$", "TIM", "POINT", "<=", ">=", "<>", "RENUM" +}; + +/* ----------------------------------------------------------------- memory */ +#define ARENA 20664 /* program text grows up, arrays grow down */ +#define STRMAX 80 +#define NVARS (26 * 11) +#define FORMAX 16 +#define GOSUBMAX 32 + +#ifdef __riscv +/* at 8000h (basic.ld), where machine-code programs know to load into it */ +static u8 arena[ARENA] __attribute__((section(".arena"))); +#else +static u8 arena[ARENA]; +#endif +static char ed_last[256]; /* the last line typed, for Up */ +static u8 *prog_end; /* end-of-program marker (a zero length byte) */ +static u8 *arr_low; /* lowest byte used by arrays */ +static float vars[NVARS]; +static char svars[26][STRMAX]; + +struct array { u8 *p; u16 d1, d2; }; +static struct array arrays[52]; /* A()-Z(), then A$()-Z$() */ + +struct fn { u8 *body; u8 var; }; +static struct fn fns[26]; + +struct forent { u8 var; float limit, step; u8 *tp, *ln; }; +static struct forent fors[FORMAX]; +static u8 nfor; + +struct subent { u8 *tp, *ln; }; +static struct subent subs[GOSUBMAX]; +static u8 nsub; + +static u8 *tp; /* text pointer */ +static u8 *curln; /* line being run, 0 in direct mode */ +static u8 *datap; /* next DATA item, 0 = search from the start */ +static u8 *dataln; +static jmp_buf errjmp; +static u8 col; /* print column */ +static u32 seed = 12345; +static char linebuf[256]; +static u8 tokbuf[256]; +static u8 running; +static u8 jumped; /* tp was moved to another statement */ + +/* ----------------------------------------------------------------- output */ +static u8 out_ch; /* PRINT # channel, 0 = the screen */ +static u8 scr_col; /* the screen's column while out_ch is set */ +static void file_putc(u8 c); + +static void putch(char c) +{ + if (c == '\n') { + col = 0; + if (out_ch) file_putc('\n'); + else { out_c('\r'); out_c('\n'); } + return; + } + if (c == '\b') { if (col) col--; } + else if ((u8)c >= ' ') col++; + if (out_ch) file_putc(c); + else out_c(c); +} + +static void puts_(const char *s) { while (*s) putch(*s++); } +static void newline(void) { putch('\n'); } + +static void put_u16(u16 v) +{ + char b[6], *p = b + 5; + *p = 0; + do { *--p = '0' + v % 10; v /= 10; } while (v); + puts_(p); +} + +/* ----------------------------------------------------------------- errors */ +enum { + E_SYNTAX, E_LINE, E_RETURN, E_NEXT, E_DATA, E_SUBSCRIPT, E_DIV0, E_MEMORY, + E_TYPE, E_STRING, E_FUNC, E_UNDEF_FN, E_FOR, E_GOSUB, E_NOFILE, E_DISKFULL, + E_DIRFULL, E_NAME, E_FLASH, E_TOOBIG, E_OPEN, E_NOTOPEN, E_EOF, E_BREAK, E_STOP +}; +static const char *const errmsg[] = { + "SYNTAX ERROR", "UNDEFINED LINE NUMBER", "RETURN WITHOUT GOSUB", + "NEXT WITHOUT FOR", "OUT OF DATA", "SUBSCRIPT OUT OF RANGE", "DIVISION BY ZERO", + "OUT OF MEMORY", "TYPE MISMATCH", "STRING TOO LONG", "ILLEGAL FUNCTION CALL", + "UNDEFINED FUNCTION", "FOR NESTED TOO DEEPLY", "GOSUB NESTED TOO DEEPLY", + "FILE NOT FOUND", "DISK FULL", "TOO MANY FILES", "BAD FILE NAME", "FLASH ERROR", + "FILE TOO BIG", "FILE ALREADY OPEN", "FILE NOT OPEN", "INPUT PAST END", + "BREAK", "STOP" +}; + +static u16 line_no(u8 *ln) { return ln[1] | (u16)ln[2] << 8; } + +static void error(u8 e) +{ + if (out_ch) { out_ch = 0; col = scr_col; } + if (col) newline(); + if (e < E_BREAK) putch('?'); + puts_(errmsg[e]); + if (curln) { puts_(" IN "); put_u16(line_no(curln)); } + newline(); + longjmp(errjmp, 1); +} + +/* ------------------------------------------------------------------ clock */ +/* The date and time, set by DATE (the PC tools set it when they connect) and + kept from the millisecond counter until the power goes off. Held as seconds + since 2000-01-01 00:00; 0 means not set. */ +#ifdef __riscv +/* at a fixed address (above the stack) so the monitor can read the clock too */ +#define clk_sec CLK_SEC +#define clk_ms CLK_MS +#else +static u32 clk_sec; +static i32 clk_ms; +#endif + +static u32 now(void) +{ + i32 m; + u32 d; + if (!clk_sec) return 0; + m = millis(); + d = (u32)(m - clk_ms) / 1000; + clk_sec += d; + clk_ms += (i32)(d * 1000); + return clk_sec; +} + +static const u8 mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +static u8 leap(u16 y) { return !(y & 3) && (y % 100 || !(y % 400)); } +static u8 month_len(u16 y, u8 m) { return mdays[m - 1] + (m == 2 && leap(y)); } + +/* "YYYY-MM-DD HH:MM" (or with ":SS" when sec is set) for t; "" when t is 0. */ +static void fmt_date(u32 t, char *out, u8 sec) +{ + static const char sep[] = "-- ::"; + u16 y = 2000, days, mins; + u8 m = 1, i, v[6]; + if (!t) { *out = 0; return; } + days = t / 86400UL; + mins = (u16)(t % 86400UL / 60); + while (days >= 365 + leap(y)) days -= 365 + leap(y++); + while (days >= month_len(y, m)) days -= month_len(y, m++); + v[0] = y - 2000; v[1] = m; v[2] = days + 1; + v[3] = mins / 60; v[4] = mins % 60; v[5] = t % 60; + *out++ = '2'; *out++ = '0'; + for (i = 0; i < 5 + sec; i++) { + if (i) *out++ = sep[i - 1]; + *out++ = '0' + v[i] / 10; + *out++ = '0' + v[i] % 10; + } + *out = 0; +} + +static u16 date_field(const char **p, u8 n, u16 lo, u16 hi) +{ + u16 v = 0; + while (n--) { + if (**p < '0' || **p > '9') error(E_FUNC); + v = v * 10 + (*(*p)++ - '0'); + } + if (v < lo || v > hi) error(E_FUNC); + return v; +} + +/* Set the clock from "YYYY-MM-DD[ HH:MM[:SS]]". */ +static void set_date(const char *s) +{ + static const char sep[] = "-- ::"; + static const u8 hi[] = { 99, 12, 31, 23, 59, 59 }; + u8 v[6], i; + u32 days; + memset(v, 0, sizeof v); + if (*s++ != '2' || *s++ != '0') error(E_FUNC); + for (i = 0; i < 6; i++) { + if (i) { + if (!*s && (i == 3 || i == 5)) break; + if (*s++ != sep[i - 1]) error(E_FUNC); + } + v[i] = date_field(&s, 2, i == 1 || i == 2, + i == 2 ? month_len(2000 + v[0], v[1]) : hi[i]); + } + if (*s) error(E_FUNC); + days = v[2] - 1; + for (i = 0; i < v[0]; i++) days += 365 + leap(2000 + i); + for (i = 1; i < v[1]; i++) days += month_len(2000 + v[0], i); + clk_ms = millis(); + clk_sec = days * 86400UL + (u16)(v[3] * 60 + v[4]) * 60UL + v[5]; + if (!clk_sec) clk_sec = 1; +} + +/* ---------------------------------------------------------------- numbers */ +static const float p10[] = { 1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f }; +static const float m10[] = { 1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f }; + +static float scale10(float v, i16 e) +{ + u8 i; + u8 neg = e < 0; + if (neg) e = -e; + if (e > 63) e = 63; + for (i = 0; i < 6; i++, e >>= 1) + if (e & 1) v = neg ? v / p10[i] : v * p10[i]; + return v; +} + +/* Parse a number at *pp (digits, point, exponent); moves *pp past it. */ +static float parse_num(u8 **pp) +{ + u8 *p = *pp; + i32 m = 0; + i16 e = 0, ex = 0; + u8 nd = 0, any = 0, eneg = 0, dot = 0; + + for (;; p++) { /* up to 9 significant digits, and a point */ + if (*p == '.' && !dot) { dot = 1; continue; } + if (*p < '0' || *p > '9') break; + any = 1; + if (nd < 9) { m = m * 10 + (*p - '0'); if (m) nd++; e -= dot; } + else if (!dot) e++; + } + if (any && *p == 'E') { + u8 *q = p + 1; + if (*q == '+' || *q == '-') { eneg = *q == '-'; q++; } + if (*q >= '0' && *q <= '9') { + for (p = q; *p >= '0' && *p <= '9'; p++) + if (ex < 100) ex = ex * 10 + (*p - '0'); + e += eneg ? -ex : ex; + } + } + if (!any) error(E_SYNTAX); + *pp = p; + return scale10((float)m, e); +} + +/* v in decimal into b; returns the end of it (the zero byte). */ +static char *fmt_ul(u32 v, char *b) +{ + char t[10], *q = t; + do { *q++ = '0' + v % 10; v /= 10; } while (v); + while (q > t) *b++ = *--q; + *b = 0; + return b; +} + +/* Format like Dartmouth BASIC: up to 6 significant digits, E notation outside + 0.001 .. 999999, no leading zero before the point. */ +static void fmt_num(float v, char *out) +{ + char d[8]; + i32 n; + i8 e = 0, i, last, pt; + u8 k; + + if (v < 0) { *out++ = '-'; v = -v; } + if (v < 999999.5f) { /* whole numbers: no floating point needed */ + n = (i32)v; + if ((float)n == v) { fmt_ul(n, out); return; } + } + if (v >= 10) + for (k = 6; k-- > 0;) + if (v >= p10[k]) { v *= m10[k]; e += 1 << k; } + if (v < 1) + for (k = 6; k-- > 0;) + if (v * p10[k] < 10) { v *= p10[k]; e -= 1 << k; } + n = (i32)(v * 100000.0f + 0.5f); + if (n >= 1000000L) { n /= 10; e++; } + if (n < 100000L) n = 100000L; + fmt_ul(n, d); /* six digits */ + for (last = 5; last > 0 && d[last] == '0'; last--); + + /* pt digits before the point; outside 1E-4..999999 use E notation */ + pt = e + 1; + if (e < -3 || e > 5) pt = 1; + if (pt <= 0) { + *out++ = '.'; + for (k = -pt; k; k--) *out++ = '0'; /* not i = pt..-1: SDCC 4.5 makes that a djnz + that runs 256 times when pt is 0 */ + } + for (i = 0; i <= last || i < pt; i++) { + if (i == pt && i) *out++ = '.'; + *out++ = d[i]; + } + if (e < -3 || e > 5) { + *out++ = 'E'; + *out++ = e < 0 ? '-' : '+'; + if (e < 0) e = -e; + *out++ = '0' + e / 10; + *out++ = '0' + e % 10; + } + *out = 0; +} + +/* ------------------------------------------------------------ tokenizing */ +static u8 is_alpha(u8 c) { return c >= 'A' && c <= 'Z'; } +static u8 is_digit(u8 c) { return c >= '0' && c <= '9'; } + +/* Turn a typed line into tokens: keywords become single bytes, letters are + upper-cased outside quotes, REM and DATA text is kept as typed. */ +static void tokenize(const char *s, u8 *out) +{ + u8 i, best, blen, len, quote = 0, raw = 0; + const char *k; + while (*s) { + u8 c = *s; + if (raw) { *out++ = c; s++; continue; } + if (c == '"') quote = !quote; + if (quote) { *out++ = c; s++; continue; } + if (c >= 'a' && c <= 'z') c -= 32; + best = 0; blen = 0; + for (i = 0; i < T_LAST - T_LET; i++) { + k = kw[i]; + if ((u8)k[0] != c) continue; + for (len = 1; k[len]; len++) { + u8 t = s[len]; + if (t >= 'a' && t <= 'z') t -= 32; + if (t != (u8)k[len]) break; + } + if (!k[len] && len > blen) { blen = len; best = T_LET + i; } + } + if (blen) { + *out++ = best; + s += blen; + if (best == T_REM || best == T_DATA) raw = 1; + } else { + *out++ = c; + s++; + } + } + *out = 0; +} + +/* Write a program line as text, keywords spelled out, without a line end. */ +static void list_to(u8 *ln, void (*out)(char)) +{ + char b[6], *q = b; + const char *k; + u8 *p = ln + 3; + fmt_ul(line_no(ln), b); + while (*q) out(*q++); + out(' '); + for (; *p; p++) { + if (*p >= T_LET && *p < T_LAST) + for (k = kw[*p - T_LET]; *k; k++) out(*k); + else out(*p); + } +} + +static void list_line(u8 *ln) +{ + list_to(ln, putch); + newline(); +} + +/* -------------------------------------------------------- program storage */ +static u8 *find_line(u16 n) +{ + u8 *p = arena; + while (*p && line_no(p) < n) p += *p; + return p; +} + +static void clear_vars(void) +{ + memset(vars, 0, sizeof vars); + memset(svars, 0, sizeof svars); + memset(arrays, 0, sizeof arrays); + memset(fns, 0, sizeof fns); + arr_low = arena + ARENA; + nfor = nsub = 0; + datap = 0; +} + +static void new_prog(void) +{ + arena[0] = 0; + prog_end = arena; + clear_vars(); +} + +static void store_line(u16 n, u8 *toks) +{ + u8 *p = find_line(n); + u16 len = strlen((char *)toks); + u16 sz; + + while (len && toks[len - 1] == ' ') toks[--len] = 0; + clear_vars(); /* arrays may move */ + if (*p && line_no(p) == n) { /* delete the old copy */ + sz = *p; + memmove(p, p + sz, prog_end + 1 - (p + sz)); + prog_end -= sz; + } + if (!len) return; + sz = len + 4; + if (sz > 255) error(E_STRING); + if (prog_end + 1 + sz >= arr_low) error(E_MEMORY); + memmove(p + sz, p, prog_end + 1 - p); + p[0] = sz; + p[1] = n & 0xFF; + p[2] = n >> 8; + memcpy(p + 3, toks, len + 1); + prog_end += sz; +} + +/* -------------------------------------------------------------- scanning */ +static u8 peekc(void) +{ + while (*tp == ' ') tp++; + return *tp; +} + +static u8 accept(u8 c) +{ + if (peekc() == c) { tp++; return 1; } + return 0; +} + +static void expect(u8 c) +{ + if (!accept(c)) error(E_SYNTAX); +} + +static u8 at_end(void) +{ + u8 c = peekc(); + return c == 0 || c == ':'; +} + +static u16 get_lineno(void) +{ + u16 n = 0; + if (!is_digit(peekc())) error(E_SYNTAX); + while (is_digit(*tp)) n = n * 10 + (*tp++ - '0'); + return n; +} + +/* Numeric variable name: letter with an optional digit. Returns its index, or + 255 if the text is not a numeric variable (does not move tp then). */ +static u8 var_name(void) +{ + u8 c = peekc(), d; + if (!is_alpha(c)) return 255; + d = tp[1]; + if (d == '$') return 255; + if (is_digit(d)) { + if (tp[2] == '$') return 255; + tp += 2; + return (c - 'A') * 11 + 1 + d - '0'; + } + tp++; + return (c - 'A') * 11; +} + +static u8 is_str_start(void) +{ + u8 c = peekc(); + if (c == '"' || c == T_CHRS || c == T_STRS || c == T_LEFTS || c == T_RIGHTS || c == T_MIDS || + c == T_DATES) + return 1; + return is_alpha(c) && tp[1] == '$'; +} + +/* ------------------------------------------------------------- expressions */ +static float expr(void); +static void sexpr(char *out); + +static i16 to_int(float v) +{ + if (v > 32767.0f || v < -32768.0f) error(E_FUNC); + return (i16)v; +} + +/* Give array a (26 and up for strings) room for subscripts 0..d1, 0..d2. */ +static void arr_alloc(u8 a, u16 d1, u16 d2) +{ + struct array *ar = &arrays[a]; + u16 n = (d1 + 1) * (d2 + 1), sz; + u8 *np; + if ((i16)d1 < 0 || (i16)d2 < 0 || n > (a < 26 ? 6000 : 255)) error(E_SUBSCRIPT); + sz = n * (a < 26 ? sizeof(float) : STRMAX); + np = arr_low - sz; + if (np <= prog_end + 1) error(E_MEMORY); + arr_low = np; + memset(np, 0, sz); + ar->p = np; + ar->d1 = d1; + ar->d2 = d2; +} + +static u8 *array_elem(u8 a) +{ + struct array *ar = &arrays[a]; + i16 i, j = 0; + u8 two; + expect('('); + i = to_int(expr()); + two = accept(','); + if (two) j = to_int(expr()); + expect(')'); + if (!ar->p) arr_alloc(a, 10, two ? 10 : 0); /* undeclared: 0..10 */ + if (i < 0 || i > (i16)ar->d1 || j < 0 || j > (i16)ar->d2) error(E_SUBSCRIPT); + return ar->p + ((u16)i * (ar->d2 + 1) + j) * (a < 26 ? sizeof(float) : STRMAX); +} + +/* A string variable or string array element (tp on its letter). */ +static char *str_ref(void) +{ + u8 a = peekc() - 'A'; + tp += 2; + if (peekc() == '(') return (char *)array_elem(26 + a); + return svars[a]; +} + +/* A numeric variable or array element as an lvalue. */ +static float *num_ref(void) +{ + u8 v; + if (is_alpha(peekc()) && tp[1] == '(') { + v = *tp - 'A'; + tp++; + return (float *)array_elem(v); + } + v = var_name(); + if (v == 255) error(E_SYNTAX); + return &vars[v]; +} + +static float ipow(float x, float y) +{ + i16 n; + float r = 1; + u8 neg; + if (y == (float)(i16)y && y >= -64 && y <= 64) { + n = (i16)y; + neg = n < 0; + if (neg) n = -n; + for (; n; n >>= 1, x *= x) + if (n & 1) r *= x; + return neg ? 1 / r : r; + } + if (x < 0) error(E_FUNC); + if (x == 0) return 0; + return expf(y * logf(x)); +} + +static float rnd(void) +{ + seed = seed * 1103515245UL + 12345UL; + return (float)((seed >> 8) & 0xFFFFFF) / 16777216.0f; +} + +static float func(u8 t) +{ + char s[STRMAX]; + float v; + if (t == T_RND) { /* RND or RND(x): argument ignored */ + if (accept('(')) { expr(); expect(')'); } + return rnd(); + } + if (t == T_TIM) return (float)millis() / 1000.0f; + expect('('); + if (t == T_POINT) { + i16 x = to_int(expr()), y; + expect(','); + y = to_int(expr()); + expect(')'); + if ((u16)x >= 320 || (u16)y >= 240) return 0; + g_at(x, y); + return g_get(); + } + if (t == T_EOF) { + struct chan *c = chan_arg('I'); + expect(')'); + return c->pos >= c->len ? -1 : 0; + } + if (t == T_LEN || t == T_VAL || t == T_ASC) { + u8 *p = (u8 *)s; + sexpr(s); + expect(')'); + if (t == T_LEN) return strlen(s); + if (t == T_ASC) return (u8)s[0]; + while (*p == ' ') p++; + if (*p == '-') { p++; return -parse_num(&p); } + if (*p == '+') p++; + return *p ? parse_num(&p) : 0; + } + v = expr(); + expect(')'); + switch (t) { + case T_SIN: return sinf(v); + case T_COS: return cosf(v); + case T_TAN: return tanf(v); + case T_ATN: return atanf(v); + case T_EXP: return expf(v); + case T_LOG: if (v <= 0) error(E_FUNC); return logf(v); + case T_ABS: return v < 0 ? -v : v; + case T_SQR: if (v < 0) error(E_FUNC); return sqrtf(v); + case T_INT: return floorf(v); + case T_SGN: return v > 0 ? 1 : v < 0 ? -1 : 0; + case T_PEEK: return peek((u32)(i32)v); + case T_INP: return io_in((u8)to_int(v)); + } + error(E_SYNTAX); + return 0; +} + +static float call_fn(void) +{ + u8 f, *save_tp; + float arg, old, r; + struct fn *d; + f = peekc(); + if (!is_alpha(f)) error(E_SYNTAX); + tp++; + d = &fns[f - 'A']; + if (!d->body) error(E_UNDEF_FN); + expect('('); + arg = expr(); + expect(')'); + old = vars[d->var]; + vars[d->var] = arg; + save_tp = tp; + tp = d->body; + r = expr(); + tp = save_tp; + vars[d->var] = old; + return r; +} + +static float primary(void) +{ + u8 c = peekc(); + float v; + if (is_digit(c) || c == '.') return parse_num(&tp); + if (c == '(') { + tp++; + v = expr(); + expect(')'); + return v; + } + if (is_str_start()) error(E_TYPE); + if (c == T_FN) { tp++; return call_fn(); } + if (c >= T_SIN && c <= T_POINT && c != T_FN && c != T_TAB) { tp++; return func(c); } + if (is_alpha(c)) return *num_ref(); + error(E_SYNTAX); + return 0; +} + +static float unary(void); + +static float power(void) +{ + float v = primary(); + while (accept('^')) v = ipow(v, unary()); + return v; +} + +static float unary(void) +{ + if (accept('-')) return -unary(); + if (accept('+')) return unary(); + return power(); +} + +static float term(void) +{ + float v = unary(), d; + for (;;) { + if (accept('*')) v *= unary(); + else if (accept('/')) { + d = unary(); + if (d == 0) error(E_DIV0); + v /= d; + } else return v; + } +} + +static float sum(void) +{ + float v = term(); + for (;;) { + if (accept('+')) v += term(); + else if (accept('-')) v -= term(); + else return v; + } +} + +/* relational operator: bit 0 '<', bit 1 '=', bit 2 '>' */ +static u8 relop(void) +{ + u8 c = peekc(); + if (c == '=') { tp++; return 2; } + if (c == T_NE) { tp++; return 5; } + if (c == T_LE) { tp++; return 3; } + if (c == T_GE) { tp++; return 6; } + if (c == '<') { tp++; if (accept('>')) return 5; if (accept('=')) return 3; return 1; } + if (c == '>') { tp++; if (accept('=')) return 6; return 4; } + return 0; +} + +static float relation(void) +{ + u8 op; + i16 c; + if (is_str_start()) { + char a[STRMAX], b[STRMAX]; + sexpr(a); + op = relop(); + if (!op) error(E_TYPE); + sexpr(b); + c = strcmp(a, b); + } else { + float x = sum(), y; + op = relop(); + if (!op) return x; + y = sum(); + c = x < y ? -1 : x > y ? 1 : 0; + } + return ((c < 0 && (op & 1)) || (c == 0 && (op & 2)) || (c > 0 && (op & 4))) ? -1 : 0; +} + +static float notx(void) +{ + if (accept(T_NOT)) return (float)~to_int(notx()); + return relation(); +} + +static float andx(void) +{ + float v = notx(); + while (accept(T_AND)) v = (float)(to_int(v) & to_int(notx())); + return v; +} + +static float expr(void) +{ + float v = andx(); + while (accept(T_OR)) v = (float)(to_int(v) | to_int(andx())); + return v; +} + +/* ------------------------------------------------------------ strings */ +static void str_prim(char *out) +{ + u8 c = peekc(), n; + char s[STRMAX]; + i16 a, b; + if (c == '"') { + tp++; + n = 0; + while (*tp && *tp != '"') { + if (n >= STRMAX - 1) error(E_STRING); + out[n++] = *tp++; + } + out[n] = 0; + if (*tp) tp++; + return; + } + if (is_alpha(c) && tp[1] == '$') { + strcpy(out, str_ref()); + return; + } + tp++; + if (c == T_DATES) { fmt_date(now(), out, 1); return; } + expect('('); + switch (c) { + case T_CHRS: + out[0] = to_int(expr()); + out[1] = 0; + break; + case T_STRS: { + float v = expr(); + out[0] = ' '; + fmt_num(v, v < 0 ? out : out + 1); + break; + } + case T_LEFTS: + case T_RIGHTS: + case T_MIDS: + sexpr(s); + expect(','); + a = to_int(expr()); + n = strlen(s); + if (c == T_MIDS) { + b = accept(',') ? to_int(expr()) : 255; + if (a < 1 || b < 0) error(E_FUNC); + if (a > n) a = n + 1; + if (b > n - a + 1) b = n - a + 1; + memcpy(out, s + a - 1, b); + out[b] = 0; + } else { + if (a < 0) error(E_FUNC); + if (a > n) a = n; + if (c == T_LEFTS) { memcpy(out, s, a); out[a] = 0; } + else strcpy(out, s + n - a); + } + break; + default: + error(E_SYNTAX); + } + expect(')'); +} + +static void sexpr(char *out) +{ + char s[STRMAX]; + if (!is_str_start()) error(E_TYPE); + str_prim(out); + while (accept('+')) { + if (!is_str_start()) error(E_TYPE); + str_prim(s); + if (strlen(out) + strlen(s) >= STRMAX) error(E_STRING); + strcat(out, s); + } +} + +/* ------------------------------------------------------------ console in */ +static int held = -1; /* a key read while checking for Ctrl-C */ + +static u8 getkey(void) +{ + int c = held; + if (c >= 0) { held = -1; return c; } + return wait_c(); +} + +static void check_break(void) +{ + int c; + if (held >= 0) return; + c = poll_c(); + if (c == 3) error(E_BREAK); + if (c >= 0) held = c; +} + +/* ------------------------------------------------------------ line editor + The line being typed is linebuf[0..ed_n) with the cursor at ed_cur. Left + and Right move, Home and End (or Ctrl-A, Ctrl-E) jump, typing inserts, + Backspace and Delete take out, Ctrl-U clears, Up brings back the last line. + At the end of a line that is only a line number, Right copies that program + line one character at a time and End copies the rest of it; Delete there + skips a character of it. The screen is kept up to date with cursor moves + only, so a line may wrap: ed_sc is the column it starts in, ED_W the + screen width, ed_row the screen row (from the line's first) the + terminal's cursor is on and ed_at the place it is at. */ +#define ED_W 80 +static void esc_num(u8 n); +static u8 ed_sc, ed_row, ed_at, ed_pend, ed_n, ed_cur; +static u8 *ed_src; /* the program line being copied, or 0 */ +static const char *ed_kw; /* the keyword being copied out of it */ + +static void ed_csi(u8 n, char f) +{ + out_c(27); out_c('['); esc_num(n); out_c(f); +} + +/* Put the terminal's cursor at place i of the line. */ +static void ed_go(u8 i) +{ + u16 p = ed_sc + i; + u8 r = p / ED_W, c = p % ED_W; + if (i == ed_at && !ed_pend) return; + out_c('\r'); + if (r < ed_row) ed_csi(ed_row - r, 'A'); + for (; ed_row < r; ed_row++) out_c('\n'); + if (c) ed_csi(c, 'C'); + ed_row = r; ed_at = i; ed_pend = 0; +} + +/* Write the line from place i on, blank `gone` cells after it, then put the + cursor back. */ +static void ed_show(u8 i, u8 gone) +{ + u8 k = i; + ed_go(i); + for (; k < ed_n; k++) out_c(linebuf[k]); + for (; gone; gone--, k++) out_c(' '); + if (k > i) { + ed_row = (ed_sc + k - 1) / ED_W; + ed_at = k; + ed_pend = (ed_sc + k) % ED_W == 0; + } + ed_go(ed_cur); +} + +/* Start copying the program line whose number is all that has been typed. */ +static void ed_start(void) +{ + u8 i = 0; + u16 v = 0; + u8 *p; + if (ed_src || ed_cur < ed_n) return; + while (i < ed_n && linebuf[i] == ' ') i++; + if (i == ed_n) return; + for (; i < ed_n; i++) { + if (!is_digit(linebuf[i])) return; + v = v * 10 + linebuf[i] - '0'; + } + p = find_line(v); + if (*p && line_no(p) == v) { ed_src = p + 3; ed_kw = " "; } +} + +/* The next character of the line being copied, or 0. */ +static char ed_next(void) +{ + u8 c; + if (!ed_src) return 0; + if (*ed_kw) return *ed_kw++; + c = *ed_src; + if (!c) return 0; + ed_src++; + if (c >= T_LET && c < T_LAST) { ed_kw = kw[c - T_LET]; return *ed_kw++; } + return c; +} + +/* Copy up to n characters of it to the end of the line. */ +static void ed_copy(u8 n) +{ + u8 i = ed_n; + char c; + ed_start(); + for (; n && ed_n < 250 && (c = ed_next()); n--) linebuf[ed_n++] = c; + ed_cur = ed_n; + ed_show(i, 0); +} + +/* Take out the character at the cursor. */ +static void ed_del(void) +{ + memmove(linebuf + ed_cur, linebuf + ed_cur + 1, ed_n - ed_cur - 1); + ed_n--; + ed_show(ed_cur, 1); +} + +/* Read a line with echo and editing; returns 0 on Ctrl-C. */ +static u8 read_line(void) +{ + u8 c, k; + ed_sc = col % ED_W; + ed_row = ed_at = ed_pend = ed_n = ed_cur = 0; + ed_src = 0; + for (;;) { + c = getkey(); + if (c == '\r' || c == '\n') { + ed_cur = ed_n; ed_go(ed_n); + newline(); linebuf[ed_n] = 0; + if (ed_n) strcpy(ed_last, linebuf); + return 1; + } + if (c == 3) { ed_cur = ed_n; ed_go(ed_n); puts_("^C"); newline(); return 0; } + if (c == 27) { /* cursor and editing keys */ + c = getkey(); + k = 0; + if (c == '[' || c == 'O') + do { c = getkey(); if (is_digit(c)) k = c; } while (c < 0x40 || c > 0x7E); + if (c == '~') c = k == '1' ? 'H' : k == '4' ? 'F' : k == '3' ? 'P' : 0; + } else if (c == 1) c = 'H'; + else if (c == 5) c = 'F'; + else if (c == 21) { /* Ctrl-U */ + k = ed_n; + ed_n = ed_cur = 0; + ed_src = 0; + ed_show(0, k); + continue; + } else if (c == 8 || c == 127) { + if (ed_cur) { ed_cur--; ed_del(); } + continue; + } else { + if (c >= ' ' && c < 127 && ed_n < 250) { + memmove(linebuf + ed_cur + 1, linebuf + ed_cur, ed_n - ed_cur); + linebuf[ed_cur++] = c; + ed_n++; + ed_show(ed_cur - 1, 0); + } + continue; + } + if (c == 'A') { /* Up: the last line again */ + k = ed_n; + strcpy(linebuf, ed_last); + ed_n = ed_cur = strlen(linebuf); + ed_src = 0; + ed_show(0, k > ed_n ? k - ed_n : 0); + } else if (c == 'C') { + if (ed_cur < ed_n) ed_cur++; + else ed_copy(1); + } else if (c == 'D') { if (ed_cur) ed_cur--; } + else if (c == 'H') ed_cur = 0; + else if (c == 'F') { + if (ed_cur < ed_n) ed_cur = ed_n; + else ed_copy(250); + } else if (c == 'P') { + if (ed_cur < ed_n) ed_del(); + else { ed_start(); ed_next(); } + } + ed_go(ed_cur); + } +} + +/* ------------------------------------------------------------ statements */ +static void goto_line(u16 n) +{ + u8 *p = find_line(n); + if (!*p || line_no(p) != n) error(E_LINE); + curln = p; + tp = p + 3; + jumped = 1; +} + +static void skip_statement(void) +{ + u8 q = 0; + while (*tp && (q || *tp != ':')) { + if (*tp == '"') q = !q; + tp++; + } +} + +static void skip_line(void) +{ + while (*tp) tp++; +} + +static void print_items(void); + +static void st_print(void) +{ + struct chan *c; + if (!accept('#')) { print_items(); return; } + c = chan_arg('O'); + if (!at_end()) expect(','); + scr_col = col; + col = c->col; + out_ch = c - ch; + print_items(); + out_ch = 0; + c->col = col; + col = scr_col; +} + +static void print_items(void) +{ + char buf[STRMAX + 2]; + u8 sep = 0; + i16 n; + while (!at_end()) { + sep = 0; + if (accept(',')) { + do putch(' '); while (col % 15); + sep = 1; + } else if (accept(';')) { + sep = 1; + } else if (accept(T_TAB)) { + expect('('); + n = to_int(expr()); + expect(')'); + while (col < n) putch(' '); + } else if (is_str_start()) { + sexpr(buf); + puts_(buf); + } else { + float v = expr(); + if (v >= 0) putch(' '); + fmt_num(v, buf); + puts_(buf); + putch(' '); + } + } + if (!sep) newline(); +} + +static void st_let(void) +{ + u8 c = peekc(); + if (is_alpha(c) && tp[1] == '$') { + char *dst = str_ref(); + expect('='); + sexpr(dst); + } else { + float *ref = num_ref(); + expect('='); + *ref = expr(); + } +} + +/* Read one number or string item from *pp into the variable at tp. */ +static u8 assign_item(u8 **pp) +{ + u8 *p = *pp, c = peekc(), n = 0; + while (*p == ' ') p++; + if (is_alpha(c) && tp[1] == '$') { + char *dst = str_ref(); + if (*p == '"') { + for (p++; *p && *p != '"'; p++) if (n < STRMAX - 1) dst[n++] = *p; + if (*p) p++; + } else { + for (; *p && *p != ','; p++) if (n < STRMAX - 1) dst[n++] = *p; + while (n && dst[n - 1] == ' ') n--; + } + dst[n] = 0; + } else { + float *ref = num_ref(), v; + u8 neg = 0; + if (*p == '-') { neg = 1; p++; } + else if (*p == '+') p++; + if (!is_digit(*p) && *p != '.') return 0; + v = parse_num(&p); + *ref = neg ? -v : v; + } + while (*p == ' ') p++; + *pp = p; + return 1; +} + +/* INPUT #n, items: values separated by commas, over as many lines as needed */ +static void input_file(void) +{ + struct chan *c = chan_arg('I'); + u8 *p; + expect(','); + if (!chan_line(c)) error(E_EOF); + p = (u8 *)linebuf; + for (;;) { + if (!assign_item(&p)) error(E_TYPE); + if (!accept(',')) break; + if (*p == ',') p++; + else if (!*p) { + if (!chan_line(c)) error(E_EOF); + p = (u8 *)linebuf; + } + } +} + +/* LINE INPUT [#n,] ["prompt";] A$: a whole line, commas and quotes included */ +static void st_line_input(void) +{ + u8 v; + if (accept('#')) { + struct chan *c = chan_arg('I'); + expect(','); + if (!chan_line(c)) error(E_EOF); + } else { + if (peekc() == '"') { + char prompt[STRMAX]; + str_prim(prompt); + puts_(prompt); + if (!accept(';')) expect(','); + } + if (!read_line()) error(E_BREAK); + } + v = peekc(); + if (!is_alpha(v) || tp[1] != '$') error(E_TYPE); + if (strlen(linebuf) >= STRMAX) linebuf[STRMAX - 1] = 0; + strcpy(str_ref(), linebuf); +} + +static void st_input(void) +{ + u8 *p; + if (accept('#')) { input_file(); return; } + if (peekc() == '"') { + char prompt[STRMAX]; + str_prim(prompt); + puts_(prompt); + if (!accept(';')) expect(','); + } + puts_("? "); + if (!read_line()) error(E_BREAK); + p = (u8 *)linebuf; + for (;;) { + u8 *save = tp; + if (!assign_item(&p)) { + puts_("?REDO"); + newline(); + puts_("? "); + if (!read_line()) error(E_BREAK); + p = (u8 *)linebuf; + tp = save; + continue; + } + if (!accept(',')) break; + if (*p == ',') p++; + else if (!*p) { + puts_("?? "); + if (!read_line()) error(E_BREAK); + p = (u8 *)linebuf; + } + } +} + +/* Move datap to the next DATA item. datap is 0 before the first READ, + otherwise it points just past the last item read. */ +static void next_data(void) +{ + if (datap) { + while (*datap == ' ') datap++; + if (*datap == ',') { datap++; return; } + dataln += *dataln; + } else dataln = arena; + for (; *dataln; dataln += *dataln) { + u8 *p = dataln + 3, q = 0; + for (; *p; p++) { + if (*p == '"') q = !q; + else if (!q && *p == T_DATA) { datap = p + 1; return; } + } + } + error(E_DATA); +} + +static void st_read(void) +{ + do { + next_data(); + if (!assign_item(&datap)) error(E_SYNTAX); + if (*datap && *datap != ',') error(E_SYNTAX); + } while (accept(',')); +} + +static void st_for(void) +{ + struct forent *f; + u8 v = var_name(), i; + if (v == 255) error(E_SYNTAX); + expect('='); + vars[v] = expr(); + for (i = 0; i < nfor; i++) /* reusing a loop variable restarts it */ + if (fors[i].var == v) { nfor = i; break; } + if (nfor >= FORMAX) error(E_FOR); + f = &fors[nfor]; + f->var = v; + expect(T_TO); + f->limit = expr(); + f->step = accept(T_STEP) ? expr() : 1; + f->tp = tp; + f->ln = curln; + nfor++; + /* skip the body when the loop runs zero times */ + if ((f->step >= 0 && vars[v] > f->limit) || (f->step < 0 && vars[v] < f->limit)) { + u8 depth = 0; + nfor--; + for (;;) { + u8 c; + skip_statement(); + if (!*tp) { + if (!curln || !*(curln + *curln)) error(E_FOR); + curln += *curln; + tp = curln + 3; + } else tp++; + c = peekc(); + if (c == T_FOR) depth++; + else if (c == T_NEXT) { + if (!depth) { + tp++; + while (!at_end()) { var_name(); if (!accept(',')) break; } + return; + } + depth--; + } + } + } +} + +static void st_next(void) +{ + struct forent *f; + u8 v; + do { + v = var_name(); + if (!nfor) error(E_NEXT); + if (v != 255) { + while (nfor && fors[nfor - 1].var != v) nfor--; + if (!nfor) error(E_NEXT); + } + f = &fors[nfor - 1]; + vars[f->var] += f->step; + if ((f->step >= 0 && vars[f->var] <= f->limit) || + (f->step < 0 && vars[f->var] >= f->limit)) { + tp = f->tp; + curln = f->ln; + jumped = 1; + return; + } + nfor--; + } while (v != 255 && accept(',')); +} + +static void st_dim(void) +{ + do { + u8 a = peekc() - 'A'; + u16 d1, d2 = 0; + if (a >= 26) error(E_SYNTAX); + if (*++tp == '$') { tp++; a += 26; } + expect('('); + d1 = to_int(expr()); + if (accept(',')) d2 = to_int(expr()); + expect(')'); + arr_alloc(a, d1, d2); + } while (accept(',')); +} + +static void st_def(void) +{ + u8 f, v; + expect(T_FN); + f = peekc(); + if (!is_alpha(f)) error(E_SYNTAX); + tp++; + expect('('); + v = var_name(); + if (v == 255) error(E_SYNTAX); + expect(')'); + expect('='); + fns[f - 'A'].var = v; + fns[f - 'A'].body = tp; + skip_statement(); +} + +static void do_gosub(u16 n) +{ + if (nsub >= GOSUBMAX) error(E_GOSUB); + subs[nsub].tp = tp; + subs[nsub].ln = curln; + nsub++; + goto_line(n); +} + +static void st_list(void) +{ + u16 a = 0, b = 65535; + u8 *p; + if (is_digit(peekc())) { a = b = get_lineno(); } + if (accept('-')) b = is_digit(peekc()) ? get_lineno() : 65535; + for (p = find_line(a); *p && line_no(p) <= b; p += *p) { + list_line(p); + check_break(); + } +} + +static void run_prog(void) +{ + clear_vars(); + curln = arena; + tp = arena + 3; + jumped = 1; + if (!arena[0]) { curln = 0; tp = (u8 *)""; } +} + +/* ------------------------------------------------------------- graphics */ +static u8 gcolor = 15; + +/* Up to n comma-separated integer arguments; returns how many were given. */ +static u8 int_args(i16 *a, u8 min, u8 n) +{ + u8 i = 0; + do a[i++] = to_int(expr()); while (i < n && accept(',')); + if (i < min) error(E_SYNTAX); + return i; +} + +static u8 colour_arg(i16 *a, u8 given, u8 need) +{ + if (given > need) { + if ((u16)a[need] > 15) error(E_FUNC); + return a[need]; + } + return gcolor; +} + +static void hline(i16 x1, i16 x2, i16 y, u8 c) +{ + i16 t; + if (x1 > x2) { t = x1; x1 = x2; x2 = t; } + if ((u16)y >= 240 || x2 < 0 || x1 > 319) return; + if (x1 < 0) x1 = 0; + if (x2 > 319) x2 = 319; + g_at(x1, y); + for (; x1 <= x2; x1++) g_put(c); +} + +static void pset(i16 x, i16 y, u8 c) +{ + if ((u16)x < 320 && (u16)y < 240) { g_at(x, y); g_put(c); } +} + +static void line(i16 x1, i16 y1, i16 x2, i16 y2, u8 c) +{ + i16 dx = x2 > x1 ? x2 - x1 : x1 - x2, sx = x1 < x2 ? 1 : -1; + i16 dy = y2 > y1 ? y1 - y2 : y2 - y1, sy = y1 < y2 ? 1 : -1; + i16 err = dx + dy, e2; + if (y1 == y2) { hline(x1, x2, y1, c); return; } + for (;;) { + pset(x1, y1, c); + if (x1 == x2 && y1 == y2) return; + e2 = 2 * err; + if (e2 >= dy) { err += dy; x1 += sx; } + if (e2 <= dx) { err += dx; y1 += sy; } + } +} + +static void circle(i16 cx, i16 cy, i16 r, u8 c) +{ + i16 x = r, y = 0, err = 1 - r; + if (r < 0) error(E_FUNC); + while (x >= y) { + pset(cx + x, cy + y, c); pset(cx - x, cy + y, c); + pset(cx + x, cy - y, c); pset(cx - x, cy - y, c); + pset(cx + y, cy + x, c); pset(cx - y, cy + x, c); + pset(cx + y, cy - x, c); pset(cx - y, cy - x, c); + y++; + if (err < 0) err += 2 * y + 1; + else { x--; err += 2 * (y - x) + 1; } + } +} + +static void esc_num(u8 n) +{ + if (n >= 100) out_c('0' + n / 100); + if (n >= 10) out_c('0' + n / 10 % 10); + out_c('0' + n % 10); +} + +static void graphics(u8 t) +{ + i16 a[5]; + u8 n, c; + switch (t) { + case T_CLS: + out_c(27); out_c('['); out_c('2'); out_c('J'); + out_c(27); out_c('['); out_c('H'); + col = 0; + g_clear(0); + break; + case T_COLOR: + int_args(a, 1, 1); + if ((u16)a[0] > 15) error(E_FUNC); + gcolor = a[0]; + break; + case T_PLOT: + n = int_args(a, 2, 3); + pset(a[0], a[1], colour_arg(a, n, 2)); + break; + case T_LINE: + n = int_args(a, 4, 5); + line(a[0], a[1], a[2], a[3], colour_arg(a, n, 4)); + break; + case T_RECT: + n = int_args(a, 4, 5); + c = colour_arg(a, n, 4); + hline(a[0], a[2], a[1], c); + hline(a[0], a[2], a[3], c); + line(a[0], a[1], a[0], a[3], c); + line(a[2], a[1], a[2], a[3], c); + break; + case T_FILL: { + i16 y, y2; + n = int_args(a, 4, 5); + c = colour_arg(a, n, 4); + y = a[1] < a[3] ? a[1] : a[3]; + y2 = a[1] < a[3] ? a[3] : a[1]; + if (y < 0) y = 0; + if (y2 > 239) y2 = 239; + for (; y <= y2; y++) hline(a[0], a[2], y, c); + break; + } + case T_CIRCLE: + n = int_args(a, 3, 4); + circle(a[0], a[1], a[2], colour_arg(a, n, 3)); + break; + case T_LOCATE: /* LOCATE row, column (from 1) */ + int_args(a, 2, 2); + if (a[0] < 1 || a[0] > 64 || a[1] < 1 || a[1] > 132) error(E_FUNC); + out_c(27); out_c('['); esc_num(a[0]); out_c(';'); esc_num(a[1]); out_c('H'); + col = a[1] - 1; + break; + case T_INK: /* INK foreground [, background] */ + n = int_args(a, 1, 2); + if ((u16)a[0] > 15 || (n > 1 && (u16)a[1] > 15)) error(E_FUNC); + out_c(27); out_c('['); + esc_num(a[0] < 8 ? 30 + a[0] : 82 + a[0]); + if (n > 1) { out_c(';'); esc_num(a[1] < 8 ? 40 + a[1] : 92 + a[1]); } + out_c('m'); + break; + } +} + +/* ---------------------------------------------------------- file system + Programs are kept as plain text in the configuration flash from 2.25 MB to + the end (448 blocks of 4 KB). Blocks 0 and 1 hold the directory, written + alternately with a rising sequence number and a checksum, so a power cut + during SAVE or DEL leaves the previous directory intact. A file is saved + into free blocks before the directory names it. */ +#define FS_BASE 0x240000UL +#define FS_BLOCKS 448 +#define MAXFILES 64 + +struct dirent { char name[8]; u16 len; u16 blk[FBLK]; u16 date[2]; }; +#define OLD_DIRENT 26 /* BFS1 entries had no date */ +static struct { + char magic[4]; + u16 seq, next; + struct dirent e[MAXFILES]; + u16 sum; +} dir; +static u8 dir_cur; /* block holding the current directory */ +static u8 bmap[FS_BLOCKS / 8]; /* blocks in use */ +static u32 blk_addr(u16 b) { return FS_BASE + ((u32)b << 12); } +static u8 nblk(u16 len) { return (len + 4095) >> 12; } + +static u16 sum_of(u16 n) +{ + u8 *p = (u8 *)&dir; + u16 s = 0x5AA5; + while (n--) s = (s << 1 | s >> 15) + *p++; + return s; +} +static u16 dir_sum(void) { return sum_of(sizeof dir - 2); } + +static u32 e_date(u8 i) { return dir.e[i].date[0] | (u32)dir.e[i].date[1] << 16; } + +static void fl_wait(void) +{ + i32 t = millis(); + while (fl_busy()) + if (millis() - t > 3000) error(E_FLASH); +} + +static void fl_erase(u16 b) +{ + if (!fl_write_op(0x20, blk_addr(b), 0, 0)) error(E_FLASH); + fl_wait(); +} + +/* program up to 256 bytes within one flash page, then check them */ +static void fl_prog(u32 a, const u8 *p, u16 n) +{ + u8 chk[32]; + u16 i, k; + if (!fl_write_op(0x02, a, p, n)) error(E_FLASH); + fl_wait(); + for (i = 0; i < n; i += k) { + k = n - i < 32 ? n - i : 32; + fl_read(a + i, chk, k); + if (memcmp(chk, p + i, k)) error(E_FLASH); + } +} + +/* Read directory block b; a BFS1 directory is widened in memory, with no dates. */ +static u8 load_dir(u8 b) +{ + u8 *p = (u8 *)&dir, i; + u16 old = 8 + MAXFILES * OLD_DIRENT; + fl_read(blk_addr(b), p, sizeof dir); + if (!memcmp(dir.magic, "BFS2", 4)) return dir.sum == dir_sum(); + if (memcmp(dir.magic, "BFS1", 4) || (p[old] | p[old + 1] << 8) != sum_of(old)) return 0; + for (i = MAXFILES; i--; ) { + memmove(&dir.e[i], p + 8 + i * OLD_DIRENT, OLD_DIRENT); + dir.e[i].date[0] = dir.e[i].date[1] = 0; + } + memcpy(dir.magic, "BFS2", 4); + return 1; +} + +/* Read the newest valid directory, or start an empty one. */ +static void fs_mount(void) +{ + u8 va, vb; + u16 sa; + if (!fl_present()) error(E_FLASH); + va = load_dir(0); + sa = dir.seq; + vb = load_dir(1); + if (va && (!vb || (i16)(sa - dir.seq) > 0)) { load_dir(0); dir_cur = 0; } + else if (vb) dir_cur = 1; + else { + memset(&dir, 0, sizeof dir); + memcpy(dir.magic, "BFS2", 4); + dir.next = 2; + dir_cur = 1; /* the first directory goes in block 0 */ + } +} + +static void fs_commit(void) +{ + u8 b = dir_cur ^ 1, *p = (u8 *)&dir; + u16 i, n; + dir.seq++; + dir.sum = dir_sum(); + fl_erase(b); + for (i = 0; i < sizeof dir; i += 256) { + n = sizeof dir - i < 256 ? sizeof dir - i : 256; + fl_prog(blk_addr(b) + i, p + i, n); + } + dir_cur = b; +} + +static void build_bmap(void) +{ + u8 i, j, n; + memset(bmap, 0, sizeof bmap); + bmap[0] = 3; /* the two directory blocks */ + for (i = 0; i < MAXFILES; i++) + if (dir.e[i].name[0]) + for (j = 0, n = nblk(dir.e[i].len); j < n; j++) + bmap[dir.e[i].blk[j] >> 3] |= 1 << (dir.e[i].blk[j] & 7); + for (i = 0; i < NCHAN; i++) + if (ch[i].mode) + for (j = 0, n = nblk(ch[i].mode == 'O' ? ch[i].pos : ch[i].len); j < n; j++) + bmap[ch[i].blk[j] >> 3] |= 1 << (ch[i].blk[j] & 7); +} + +/* next free block after the last one handed out, spreading the wear */ +static u16 alloc_blk(void) +{ + u16 b = dir.next, k; + for (k = 0; k < FS_BLOCKS; k++, b++) { + if (b >= FS_BLOCKS) b = 2; + if (!(bmap[b >> 3] & (1 << (b & 7)))) { + bmap[b >> 3] |= 1 << (b & 7); + dir.next = b + 1; + return b; + } + } + error(E_DISKFULL); + return 0; +} + +/* File name: 1-8 letters and digits, from any string expression. */ +static void get_name(char *nm) +{ + char s[STRMAX]; + u8 i, c; + sexpr(s); + memset(nm, 0, 8); + for (i = 0; s[i]; i++) { + c = s[i]; + if (c >= 'a' && c <= 'z') c -= 32; + if (i >= 8 || !(is_alpha(c) || is_digit(c))) error(E_NAME); + nm[i] = c; + } + if (!i) error(E_NAME); +} + +static i16 find_file(const char *nm) +{ + u8 i; + for (i = 0; i < MAXFILES; i++) + if (!memcmp(dir.e[i].name, nm, 8)) return i; + return -1; +} + +static void put_name(const char *nm) +{ + u8 i; + for (i = 0; i < 8; i++) putch(nm[i] ? nm[i] : ' '); +} + +/* ------------------------------------------------------------- channels */ +static void chan_putc(struct chan *c, u8 b) +{ + if (!(c->pos & 4095)) { + u8 k = c->pos >> 12; + if (k >= FBLK) error(E_TOOBIG); + c->blk[k] = alloc_blk(); + fl_erase(c->blk[k]); + } + c->buf[c->pos & 255] = b; + c->pos++; + if (!(c->pos & 255)) + fl_prog(blk_addr(c->blk[(c->pos - 1) >> 12]) + ((c->pos - 256) & 4095), c->buf, 256); +} + +static void file_putc(u8 b) { chan_putc(&ch[out_ch], b); } +static void save_putc(char b) { chan_putc(&ch[0], b); } + +/* next byte of an input channel, -1 at the end */ +static int chan_getc(struct chan *c) +{ + if (c->pos >= c->len) return -1; + if ((c->pos >> 8) != c->pg) { + c->pg = c->pos >> 8; + fl_read(blk_addr(c->blk[c->pos >> 12]) + (c->pos & 0xF00), c->buf, 256); + } + return c->buf[c->pos++ & 255]; +} + +/* Read a line into linebuf (up to 250 characters); 0 if already at the end. */ +static u8 chan_line(struct chan *c) +{ + u8 n = 0; + int b = chan_getc(c); + if (b < 0) return 0; + while (b >= 0 && b != '\n') { + if (n < 250) linebuf[n++] = b; + b = chan_getc(c); + } + linebuf[n] = 0; + return 1; +} + +static void chan_open_in(struct chan *c, const char *nm) +{ + i16 i; + fs_mount(); + i = find_file(nm); + if (i < 0) error(E_NOFILE); + memcpy(c->name, nm, 8); + c->len = dir.e[i].len; + memcpy(c->blk, dir.e[i].blk, sizeof c->blk); + c->pos = 0; + c->pg = 0xFFFF; + c->mode = 'I'; +} + +/* Start writing a new copy of file nm; with append, it starts as the old one. + The directory only changes at chan_close, so until then the old file stays. */ +static void chan_open_out(struct chan *c, const char *nm, u8 append) +{ + i16 i; + u16 j, len; + u8 b; + fs_mount(); + build_bmap(); + i = find_file(nm); + if (i < 0) { + for (j = 0; j < MAXFILES && dir.e[j].name[0]; j++); + if (j == MAXFILES) error(E_DIRFULL); + } + memcpy(c->name, nm, 8); + c->pos = 0; + c->col = 0; + c->mode = 'O'; + if (append && i >= 0) { + struct dirent e = dir.e[i]; + len = e.len; + b = len >> 12; /* whole blocks are shared as they are */ + memcpy(c->blk, e.blk, b * 2); + c->pos = (u16)b << 12; + for (j = c->pos; j < len; j++) { /* the part block is copied */ + u8 v; + fl_read(blk_addr(e.blk[b]) + (j & 4095), &v, 1); + chan_putc(c, v); + } + } +} + +static void chan_close(struct chan *c) +{ + u16 n; + i16 i; + u8 m = c->mode; + c->mode = 0; + if (m != 'O') return; + n = c->pos & 255; + if (n) fl_prog(blk_addr(c->blk[(c->pos - 1) >> 12]) + ((c->pos - n) & 4095), c->buf, n); + fs_mount(); + i = find_file(c->name); + if (i < 0) { + for (i = 0; i < MAXFILES && dir.e[i].name[0]; i++); + if (i == MAXFILES) error(E_DIRFULL); + } + if (!dir.e[i].name[0] || !e_date(i)) { /* keep the creation date */ + u32 t = now(); + dir.e[i].date[0] = (u16)t; + dir.e[i].date[1] = t >> 16; + } + memcpy(dir.e[i].name, c->name, 8); + dir.e[i].len = c->pos; + memcpy(dir.e[i].blk, c->blk, sizeof c->blk); + fs_commit(); +} + +static void close_all(void) +{ + u8 i; + for (i = 1; i < NCHAN; i++) chan_close(&ch[i]); +} + +/* [#]n of an open channel in the given mode */ +static struct chan *chan_arg(u8 mode) +{ + i16 n; + accept('#'); + n = to_int(expr()); + if (n < 1 || n >= NCHAN) error(E_FUNC); + if (ch[n].mode != mode) error(E_NOTOPEN); + return &ch[n]; +} + +/* OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n */ +static void st_open(void) +{ + char nm[8]; + u8 m; + i16 n; + get_name(nm); + expect(T_FOR); + m = peekc(); + if (m != T_INPUT && m != T_OUTPUT && m != T_APPEND) error(E_SYNTAX); + tp++; + if (peekc() != 'A' || tp[1] != 'S') error(E_SYNTAX); + tp += 2; + accept('#'); + n = to_int(expr()); + if (n < 1 || n >= NCHAN) error(E_FUNC); + if (ch[n].mode) error(E_OPEN); + if (m == T_INPUT) chan_open_in(&ch[n], nm); + else chan_open_out(&ch[n], nm, m == T_APPEND); +} + +/* CLOSE [#n [, #n ...]], or every file */ +static void st_close(void) +{ + i16 n; + if (at_end()) { close_all(); return; } + do { + accept('#'); + n = to_int(expr()); + if (n < 1 || n >= NCHAN) error(E_FUNC); + chan_close(&ch[n]); + } while (accept(',')); +} + +/* BSAVE "NAME", start, length / BLOAD "NAME" [, address]: memory files, + the load address (4 bytes, low first) and then the bytes, as the monitor + writes them */ +static void st_bfile(u8 t) +{ + char nm[8]; + u32 a, n; + int b; + u8 i; + struct chan *c = &ch[0]; + c->mode = 0; + get_name(nm); + if (t == T_BSAVE) { + expect(','); a = (u32)(i32)expr(); + expect(','); n = (u32)(i32)expr(); + chan_open_out(c, nm, 0); + for (i = 0; i < 32; i += 8) chan_putc(c, a >> i); + while (n--) chan_putc(c, peek(a++)); + chan_close(c); + } else { + chan_open_in(c, nm); + for (a = 0, i = 0; i < 32; i += 8) a |= (u32)chan_getc(c) << i; + if (accept(',')) a = (u32)(i32)expr(); + while ((b = chan_getc(c)) >= 0) poke(a++, b); + c->mode = 0; + } +} + +static void st_save(void) +{ + char nm[8]; + u8 *p; + struct chan *c = &ch[0]; + c->mode = 0; + get_name(nm); + chan_open_out(c, nm, 0); + for (p = arena; *p; p += *p) { + list_to(p, save_putc); + save_putc('\n'); + } + chan_close(c); +} + +/* Store a typed or loaded line " "; ignores lines without a number. */ +static void enter_line(char *s) +{ + u16 n = 0; + while (*s == ' ') s++; + if (!is_digit(*s)) return; + while (is_digit(*s)) n = n * 10 + (*s++ - '0'); + while (*s == ' ') s++; + tokenize(s, tokbuf); + store_line(n, tokbuf); +} + +static void fs_load(void) +{ + char nm[8]; + struct chan *c = &ch[0]; + c->mode = 0; + get_name(nm); + chan_open_in(c, nm); + new_prog(); + while (chan_line(c)) enter_line(linebuf); + c->mode = 0; +} + +static void st_dir(void) +{ + u8 i, n = 0; + u16 used = 2; + fs_mount(); + for (i = 0; i < MAXFILES; i++) { + if (!dir.e[i].name[0]) continue; + put_name(dir.e[i].name); + do putch(' '); while (col < 10); + put_u16(dir.e[i].len); + if (e_date(i)) { + char d[20]; + fmt_date(e_date(i), d, 0); + do putch(' '); while (col < 17); + puts_(d); + } + newline(); + used += nblk(dir.e[i].len); + n++; + check_break(); + } + put_u16(n); + puts_(n == 1 ? " FILE, " : " FILES, "); + put_u16((FS_BLOCKS - used) * 4); + puts_("K FREE"); + newline(); +} + +static void st_del(void) +{ + char nm[8]; + i16 i; + get_name(nm); + fs_mount(); + i = find_file(nm); + if (i < 0) error(E_NOFILE); + memset(&dir.e[i], 0, sizeof dir.e[i]); + fs_commit(); +} + +/* RENUM [start [, step]]: number the lines start, start+step, ... and change + the line numbers after GOTO, GOSUB, THEN, RUN and ON ... GOTO/GOSUB to + match. The new program is built in the free memory above the old one and + only copied down at the end, so an error leaves the program as it was. */ +static u16 rn_start, rn_step; +static u8 *rn_o; + +static void rn_put(u8 c) +{ + if (rn_o >= arr_low) error(E_MEMORY); + *rn_o++ = c; +} + +static u16 rn_new(u16 v) +{ + u8 *r = arena; + u16 n = rn_start; + for (; *r; r += *r, n += rn_step) + if (line_no(r) == v) return n; + return v; +} + +static void st_renum(void) +{ + u8 *p, *q, *h, t, want, i; + u16 n, v; + char b[6]; + rn_start = rn_step = 10; + if (!at_end()) { + rn_start = get_lineno(); + if (accept(',')) rn_step = get_lineno(); + } + if (!rn_step) error(E_FUNC); + clear_vars(); + rn_o = prog_end + 1; + for (p = arena, n = rn_start; *p; p += *p, n += rn_step) { + if (n < rn_start) error(E_FUNC); /* past 65535 */ + h = rn_o; + rn_put(0); rn_put(n); rn_put(n >> 8); + for (q = p + 3; (t = *q++) != 0; ) { + rn_put(t); + if ((t < T_THEN || t > T_GOSUB) && t != T_RUN) continue; /* THEN GOTO GOSUB */ + for (want = 1;;) { + while (*q == ' ') rn_put(*q++); + if (want && is_digit(*q)) { + v = 0; + while (is_digit(*q)) v = v * 10 + (*q++ - '0'); + fmt_ul(rn_new(v), b); + for (i = 0; b[i]; i++) rn_put(b[i]); + want = 0; + } else if (!want && *q == ',') { + rn_put(*q++); + want = 1; + } else break; + } + } + rn_put(0); + if (rn_o - h > 255) error(E_STRING); + *h = rn_o - h; + } + rn_put(0); + n = rn_o - (prog_end + 1); + memmove(arena, prog_end + 1, n); + prog_end = arena + n - 1; +} + +/* Stop running and go back to READY after this statement. */ +static void to_ready(void) +{ + running = 0; + curln = 0; + tp = (u8 *)""; +} + +static void statement(void); + +static void st_if(void) +{ + float c = expr(); + if (!accept(T_THEN) && peekc() != T_GOTO) error(E_SYNTAX); + if (!c) { skip_line(); return; } + if (is_digit(peekc())) goto_line(get_lineno()); + else statement(); +} + +static void statement(void) +{ + u8 t = peekc(), n; + u16 ln; + if (t == 0 || t == ':') return; + tp++; + switch (t) { + case T_LET: st_let(); break; + case T_PRINT: st_print(); break; + case T_INPUT: st_input(); break; + case T_IF: st_if(); break; + case T_GOTO: goto_line(get_lineno()); break; + case T_GOSUB: ln = get_lineno(); do_gosub(ln); break; + case T_RETURN: + if (!nsub) error(E_RETURN); + nsub--; + tp = subs[nsub].tp; + curln = subs[nsub].ln; + jumped = 1; + break; + case T_FOR: st_for(); break; + case T_NEXT: st_next(); break; + case T_DIM: st_dim(); break; + case T_DEF: st_def(); break; + case T_END: close_all(); running = 0; break; + case T_STOP: error(E_STOP); break; + case T_REM: skip_line(); break; + case T_DATA: skip_line(); break; + case T_READ: st_read(); break; + case T_RESTORE: datap = 0; break; + case T_ON: + n = to_int(expr()); + t = peekc(); + if (t != T_GOTO && t != T_GOSUB) error(E_SYNTAX); + tp++; + for (;;) { + ln = get_lineno(); + if (--n == 0) { + if (t == T_GOSUB) { skip_statement(); do_gosub(ln); } + else goto_line(ln); + return; + } + if (!accept(',')) break; + } + skip_statement(); + break; + case T_RANDOMIZE: seed ^= (u32)millis() * 2654435761UL; break; + case T_POKE: { + u32 a = (u32)(i32)expr(); + expect(','); + poke(a, (u8)to_int(expr())); + break; + } + case T_OUT: { + u8 p = (u8)to_int(expr()); + expect(','); + io_out(p, (u8)to_int(expr())); + break; + } + case T_LOAD: + close_all(); + fs_load(); + to_ready(); + break; + case T_SAVE: st_save(); break; + case T_DIR: st_dir(); break; + case T_DEL: st_del(); break; + case T_OPEN: st_open(); break; + case T_CLOSE: st_close(); break; + case T_BSAVE: case T_BLOAD: st_bfile(t); break; +#ifdef __riscv + case T_MONITOR: io_out(0x61, 0); break; /* NMI into the monitor */ + case T_CALL: ((void (*)(void))(u32)(i32)expr())(); break; +#endif + case T_DATE: { + char d[STRMAX]; + if (is_str_start()) { sexpr(d); set_date(d); break; } + fmt_date(now(), d, 1); + puts_(*d ? d : "DATE NOT SET"); + newline(); + break; + } + case T_RUN: + close_all(); + if (is_str_start()) fs_load(); + run_prog(); + running = 1; + if (is_digit(peekc())) goto_line(get_lineno()); + break; + case T_LIST: st_list(); break; + case T_NEW: + case T_SCRATCH: close_all(); new_prog(); to_ready(); break; + case T_RENUM: st_renum(); to_ready(); break; + case T_BYE: bye(); break; + case T_LINE: + if (accept(T_INPUT)) { st_line_input(); break; } + graphics(t); + break; + case T_CLS: case T_COLOR: case T_PLOT: case T_RECT: + case T_FILL: case T_CIRCLE: case T_LOCATE: case T_INK: + graphics(t); + break; + default: + tp--; + st_let(); + } +} + +/* Run statements from tp until the program ends or stops. */ +static void execute(void) +{ + running = 1; + while (running) { + check_break(); + jumped = 0; + statement(); + if (!running) break; + if (jumped) continue; + if (accept(':')) continue; + if (peekc()) error(E_SYNTAX); + if (!curln) break; /* end of a direct statement */ + curln += *curln; + if (!*curln) { close_all(); break; } /* end of program */ + tp = curln + 3; + } + running = 0; +} + +int main(void) +{ + u16 n; + u8 *p; +#ifdef __riscv + clk_sec = 0; +#endif + new_prog(); + g_clear(0); + newline(); + puts_("DARTMOUTH-STYLE BASIC RISC-V ON A BASYS 3"); + newline(); + if (setjmp(errjmp)) { + running = 0; + nfor = nsub = 0; + curln = 0; + } + for (;;) { + if (!running) { newline(); puts_("READY"); newline(); } + for (;;) { + if (!read_line()) continue; + p = (u8 *)linebuf; + while (*p == ' ') p++; + if (!*p) continue; + if (is_digit(*p)) { + n = 0; + while (is_digit(*p)) n = n * 10 + (*p++ - '0'); + while (*p == ' ') p++; + tokenize((char *)p, tokbuf); + store_line(n, tokbuf); + continue; + } + break; + } + tokenize((char *)p, tokbuf); + curln = 0; + tp = tokbuf; + execute(); + curln = 0; + } +} + diff --git a/basic/basic.ld b/basic/basic.ld new file mode 100644 index 0000000..916fb62 --- /dev/null +++ b/basic/basic.ld @@ -0,0 +1,40 @@ +/* BASIC: code and constants below A000h (ROM_TOP: the hardware ignores writes + there), the program area at A000h, then data. 12000h-12FFFh is left free for + machine code; the stack comes down from 13FF0h; 13FF8h-13FFFh hold the clock + (include/basys3.h). */ +OUTPUT_ARCH("riscv") +ENTRY(_start) +MEMORY +{ + ROM (rx) : ORIGIN = 0x00000, LENGTH = 0xA000 + RAM (rw) : ORIGIN = 0x0A000, LENGTH = 0x8000 +} +SECTIONS +{ + .text : { + KEEP(*(.text.start)) + *(.text .text.*) + *(.rodata .rodata.* .srodata .srodata.*) + . = ALIGN(4); + } > ROM + .arena (NOLOAD) : { KEEP(*(.arena)) } > RAM + .data : ALIGN(4) { + __data_start = .; + *(.data .data.*) + __global_pointer$ = . + 0x800; + *(.sdata .sdata.*) + . = ALIGN(4); + __data_end = .; + } > RAM AT > ROM + __data_load = LOADADDR(.data); + .bss (NOLOAD) : ALIGN(4) { + __bss_start = .; + *(.sbss .sbss.* .bss .bss.* COMMON) + . = ALIGN(4); + __bss_end = .; + } > RAM + ASSERT(__bss_end <= 0x12000, "BASIC's data runs into the machine-code area") + __stack_top = 0x13FF0; + __rom_end = __data_load + SIZEOF(.data); + /DISCARD/ : { *(.comment) *(.riscv.attributes) } +} diff --git a/basic/basic.mem b/basic/basic.mem new file mode 100644 index 0000000..fe8cd24 --- /dev/null +++ b/basic/basic.mem @@ -0,0 +1,16384 @@ +00010197 +8b818193 +00014117 +fe810113 +000202b7 +00428293 +30529073 +0000f517 +09c50513 +00009597 +e1058593 +80c18613 +00c57c63 +0005a283 +00552023 +00450513 +00458593 +fedff06f +81018513 +00011617 +28460613 +00c57863 +00052023 +00450513 +ff5ff06f +4c1050ef +0000006f +f0004783 +0027f793 +fe078ce3 +f0a000a3 +00008067 +f4a000a3 +f4004783 +0017f793 +fe079ce3 +f4104503 +00008067 +ff010113 +00812423 +00050413 +01055513 +0ff57513 +00112623 +fd1ff0ef +00845513 +0ff57513 +fc5ff0ef +0ff47513 +00812403 +00c12083 +01010113 +fb1ff06f +00357713 +00050793 +02071263 +06400713 +02e57733 +00100513 +00071c63 +19000713 +02e7f7b3 +0017b513 +00008067 +00000513 +00008067 +000097b7 +9c878793 +ff010113 +00b787b3 +00812423 +00112623 +fff7c403 +00200793 +02f59263 +fa9ff0ef +00a03533 +00c12083 +00a40533 +00812403 +0ff57513 +01010113 +00008067 +00000513 +fe5ff06f +0000a7b7 +00050713 +00078513 +00054683 +00068c63 +00254783 +00154603 +00879793 +00c7e7b3 +00e7e463 +00008067 +00d50533 +fddff06f +02000693 +3341a783 +0007c503 +00d50463 +00008067 +00178793 +32f1aa23 +fe9ff06f +ff010113 +00112623 +fd9ff0ef +00050793 +00100513 +00078663 +fc678793 +0017b513 +00c12083 +01010113 +00008067 +ff010113 +00112623 +fadff0ef +fbf50713 +0ff77713 +01900693 +00050793 +0ff00513 +04e6e663 +3341a703 +02400813 +00174683 +03068e63 +fd068593 +0ff5f593 +00900513 +02b56c63 +00274583 +0ff00513 +03058063 +00270713 +32e1aa23 +00b00713 +02e787b3 +00668693 +00d787b3 +0ff7f513 +00c12083 +01010113 +00008067 +00170713 +32e1aa23 +00b00713 +02e787b3 +03578793 +fddff06f +ff010113 +00112623 +f1dff0ef +00050793 +02200713 +00100513 +02e78e63 +03778713 +0ff77713 +00500693 +02e6f663 +fbf78793 +0ff7f793 +01900713 +00000513 +00f76a63 +3341a783 +0017c503 +fdc50513 +00153513 +0ff57513 +00c12083 +01010113 +00008067 +0000f7b7 +0bc7a503 +00054a63 +fff00713 +0ae7ae23 +0ff57513 +00008067 +f0004783 +0017f793 +fe078ce3 +f0104503 +fe9ff06f +ff010113 +00912223 +fe41a783 +00112623 +00812423 +08079a63 +fe91c683 +fe81c783 +08d7e463 +00000793 +0f418613 +02000513 +0ff7f713 +06d77863 +00178593 +00c58833 +fff84803 +04a80c63 +0f418613 +00c787b3 +00000413 +00900513 +00a00813 +06d76063 +00040513 +dfdff0ef +00054783 +02078e63 +00254783 +00154703 +00879793 +00e7e7b3 +02879463 +000087b7 +00350513 +30c78793 +fea1a223 +fef1a023 +0100006f +00058793 +f91ff06f +fae692e3 +00c12083 +00812403 +00412483 +01010113 +00008067 +0007c583 +00178793 +fd058613 +0ff67613 +fcc56ee3 +03040433 +00170713 +0ff77713 +fd040413 +00b40433 +01041413 +01045413 +f71ff06f +fe41a783 +00000513 +04078e63 +fe01a703 +00074503 +00050863 +00170713 +fee1a023 +00008067 +0007c503 +02050e63 +00178793 +fef1a223 +08054793 +05400613 +f8050713 +02f66263 +000097b7 +00271713 +a3878793 +00e787b3 +0007a783 +0007c503 +00178713 +fee1a023 +00008067 +00000693 +03a00593 +02200513 +3341a783 +0007c703 +00070663 +00069663 +00b71463 +00008067 +00a71463 +0016c693 +00178793 +32f1aa23 +fd9ff06f +3341a783 +0007c683 +00069463 +00008067 +00178793 +32f1aa23 +fe9ff06f +00a5c863 +00058793 +00050593 +00078513 +01061793 +0107d793 +0ef00713 +06f76063 +04054e63 +13f00793 +04b7ca63 +00058793 +0005d463 +00000793 +01079793 +13f00593 +4107d793 +00050713 +00a5d463 +13f00713 +0ff7f593 +f2b00823 +01079593 +0105d593 +0085d593 +01071713 +0ff67613 +f2b008a3 +41075713 +f2c00923 +00f75463 +00008067 +00178793 +01079793 +f2d009a3 +4107d793 +fe9ff06f +ff010113 +00812423 +00112623 +06300793 +00050413 +02a7f863 +06400513 +02a45533 +03050513 +0ff57513 +b11ff0ef +00a00793 +02f45533 +02f57533 +03050513 +afdff0ef +00c0006f +00900793 +fea7e2e3 +00a00793 +02f47533 +00812403 +00c12083 +01010113 +03050513 +ad5ff06f +fff50793 +01079793 +00006537 +0000f6b7 +00010637 +0107d793 +aa550513 +10c68693 +fff60613 +0006c583 +00151713 +00f55513 +00a76733 +fff78793 +00b70733 +01079793 +01071513 +0107d793 +00168693 +01055513 +fcc79ae3 +00008067 +00011537 +ff010113 +47800613 +00000593 +8c850513 +00112623 +15d050ef +00001637 +00010537 +82060613 +00000593 +0a850513 +145050ef +1a000613 +00000593 +65018513 +135050ef +0d000613 +00000593 +58018513 +125050ef +0000f7b7 +0b878793 +00011737 +d4f72023 +00c12083 +32018c23 +42018e23 +3201a623 +01010113 +00008067 +fe010113 +00912a23 +0000f4b7 +00812c23 +01212823 +01312623 +00112e23 +00050913 +11448493 +00000413 +04000993 +00800613 +00090593 +00048513 +0dd050ef +02051463 +01041513 +41055513 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00140413 +0ff47413 +01e48493 +fb341ee3 +fff00513 +fd1ff06f +00014737 +ff872503 +ff870713 +02050e63 +000146b7 +e0002783 +ffc6a603 +3e800593 +40c787b3 +02b7d7b3 +00072603 +00c78633 +02b787b3 +00c72023 +ffc6a603 +00c787b3 +fef6ae23 +00072503 +00008067 +fd010113 +01512a23 +02112623 +02812423 +02912223 +03212023 +01312e23 +01412c23 +01612823 +00058a93 +02051863 +00058023 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +03010113 +00008067 +000157b7 +18078793 +02f579b3 +00050913 +00060a13 +7d000493 +02f55433 +03c00793 +02f9d9b3 +01041413 +01045413 +01099993 +0109d993 +00048513 +90dff0ef +16c50793 +0c87c263 +00100b13 +000b0593 +00048513 +929ff0ef +0ca47863 +03c00793 +02f9d733 +03048493 +00140413 +004a0a13 +00009637 +00910423 +016104a3 +00810523 +002a8593 +0ffa7a13 +98860613 +00000693 +00a00513 +02f9f9b3 +00e105a3 +02f97933 +03200793 +00fa8023 +03000793 +01310623 +00fa80a3 +012106a3 +00058793 +00068863 +fff64703 +00158793 +00e58023 +00810713 +00d70733 +00074703 +00168693 +00160613 +02a755b3 +02a77733 +03058593 +00b78023 +00278593 +03070713 +00e780a3 +fada5ee3 +00078123 +ed9ff06f +16d50513 +00148493 +40a40433 +01049493 +01041413 +0104d493 +01045413 +f15ff06f +40a40433 +001b0b13 +01041413 +0ffb7b13 +01045413 +f11ff06f +ff010113 +00812423 +00112623 +00050413 +8adff0ef +02851263 +3341a783 +00100513 +00178793 +32f1aa23 +00c12083 +00812403 +01010113 +00008067 +00000513 +fedff06f +ff010113 +00112623 +875ff0ef +03d00713 +02e51263 +3341a783 +00178793 +32f1aa23 +00200713 +00c12083 +00070513 +01010113 +00008067 +0d300713 +00e51c63 +3341a783 +00178793 +32f1aa23 +00500713 +fd9ff06f +0d100713 +00e51c63 +3341a783 +00178793 +32f1aa23 +00300713 +fbdff06f +0d200713 +00e51c63 +3341a783 +00178793 +32f1aa23 +00600713 +fa1ff06f +03c00713 +02e51863 +3341a783 +03e00513 +00178793 +32f1aa23 +f21ff0ef +fa0512e3 +03d00513 +f15ff0ef +00100713 +f60508e3 +fadff06f +03e00693 +00000713 +f6d510e3 +3341a783 +03d00513 +00178793 +32f1aa23 +ee9ff0ef +00400713 +f40502e3 +f9dff06f +ff010113 +00812623 +00912423 +00000693 +00000713 +ff418613 +02200293 +000093b7 +00100413 +01900e93 +0d500493 +00054783 +00079c63 +00060023 +00c12403 +00812483 +01010113 +00008067 +00160613 +00068863 +00150513 +fef60fa3 +fd5ff06f +06579863 +06871863 +a3838313 +00000893 +00000713 +08000593 +00032f83 +000fc683 +02f69063 +00100693 +00df8833 +00084f03 +060f1463 +00d77663 +00068713 +00058893 +00158593 +0ff5f593 +00430313 +fc9596e3 +06070a63 +0fd8f693 +f7068693 +00e50533 +00088793 +00000713 +0016b693 +f8dff06f +00070863 +00150513 +00100713 +f7dff06f +f9f78713 +0ff77713 +f8eee0e3 +fe078793 +0ff7f793 +f75ff06f +00d50833 +00084803 +f9f80e13 +0ffe7e13 +01cee663 +fe080813 +0ff87813 +f90f16e3 +00168693 +0ff6f693 +f69ff06f +00150513 +00000693 +f2dff06f +ff010113 +00410793 +00078693 +00a00613 +00900813 +02c57733 +00178793 +03070713 +fee78fa3 +00050713 +02c55533 +fee864e3 +00078713 +00058613 +02e6e063 +00000713 +00d7e463 +40d78733 +00e585b3 +00058023 +01010113 +00008067 +fff74503 +fff70713 +00160613 +fea60fa3 +fd1ff06f +fd010113 +02812423 +02912223 +03212023 +02112623 +01312e23 +01412c23 +00254783 +00154703 +00058413 +00879793 +00350913 +00810593 +00e7e533 +f5dff0ef +00810493 +0004c503 +04051063 +02000513 +000094b7 +000400e7 +05400a13 +a3848493 +00094503 +02051863 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +03010113 +00008067 +00148493 +000400e7 +fb5ff06f +08054713 +f8050793 +02ea6663 +00279793 +00f487b3 +0007a983 +0009c503 +00051663 +00190913 +fa9ff06f +000400e7 +00198993 +fe9ff06f +000400e7 +fe9ff06f +fc010113 +02812c23 +00058413 +00000593 +02912a23 +02112e23 +03212823 +03312623 +03412423 +03512223 +03612023 +01712e23 +01812c23 +00050493 +181060ef +00055c63 +02d00793 +00f40023 +800007b7 +0097c4b3 +00140413 +000097b7 +b8c7a583 +00048513 +159060ef +2e055863 +00048513 +31c070ef +00050913 +388070ef +00048593 +001060ef +02051e63 +00040593 +03812403 +03c12083 +03412483 +02c12983 +02812a03 +02412a83 +02012b03 +01c12b83 +01812c03 +00090513 +03012903 +04010113 +e11ff06f +000097b7 +b907a583 +00048513 +00000913 +025060ef +06054263 +00009a37 +000099b7 +9b0a0a13 +99898993 +00500a93 +00000913 +00100b93 +fff00b13 +014a2503 +00048593 +0bd060ef +02a04263 +0149a583 +00048513 +17d060ef +015b97b3 +012787b3 +01879913 +00050493 +41895913 +fffa8a93 +ffca0a13 +ffc98993 +fd6a92e3 +000097b7 +b947a583 +00048513 +079060ef +04055e63 +000097b7 +b907ab83 +000099b7 +9b098993 +00500a13 +00100c13 +fff00b13 +0149a583 +00048513 +11d060ef +000b8593 +00050a93 +041060ef +00055c63 +014c17b3 +40f907b3 +01879913 +41895913 +000a8493 +fffa0a13 +ffc98993 +fd6a14e3 +000097b7 +b987a583 +00048513 +0dd060ef +000097b7 +b9c7a583 +5e9050ef +1cc070ef +000f47b7 +23f78793 +00a7dc63 +00a00793 +02f54533 +00190913 +01891913 +41895913 +000187b7 +6a078793 +00f55463 +00078513 +00810593 +cd5ff0ef +00500793 +03000713 +00810693 +00f686b3 +0006c683 +0ee68863 +01879713 +41875713 +0ff97613 +00360593 +0ff5f593 +00800793 +00100693 +02b7ee63 +00160693 +01869693 +4186d693 +02d04663 +02e00793 +00140813 +00f40023 +fff64413 +0ff47413 +00080513 +00040793 +03000893 +0a079663 +00880433 +00000793 +02e00513 +0af75863 +0ad7ce63 +00800793 +04b7f663 +04500793 +00f40023 +02b00793 +00095463 +02d00793 +00f400a3 +00095863 +40c00633 +01861913 +41895913 +00a00793 +02f94733 +00440413 +02f967b3 +03070713 +fee40f23 +03078793 +fef40fa3 +00040023 +03c12083 +03812403 +03412483 +03012903 +02c12983 +02812a03 +02412a83 +02012b03 +01c12b83 +01812c03 +04010113 +00008067 +fff78793 +f00790e3 +00000713 +f11ff06f +fff78793 +01150023 +0ff7f793 +00150513 +f45ff06f +00f69863 +00068663 +00a40023 +00140413 +01078813 +00280833 +ff884803 +00178793 +01879793 +01040023 +4187d793 +00140413 +f21ff06f +000097b7 +b907a583 +00048513 +00000913 +58c060ef +d60556e3 +e35ff06f +fe010113 +00812c23 +fed1c403 +05000793 +01312623 +00850433 +02f459b3 +01512223 +01412423 +00112e23 +00912a23 +01212823 +00050a13 +02f47433 +feb1c783 +0ff9f993 +00a79663 +fea1c783 +06078a63 +00d00513 +854ff0ef +fec1c783 +02f9f663 +413787b3 +01b00513 +0ff7f493 +83cff0ef +05b00513 +834ff0ef +00048513 +cf4ff0ef +04100513 +824ff0ef +fec1c483 +0534ec63 +02040263 +01b00513 +810ff0ef +05b00513 +808ff0ef +00040513 +cc8ff0ef +04300513 +ff9fe0ef +ff318623 +ff4185a3 +fe018523 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +02010113 +00008067 +00a00513 +00148493 +fbdfe0ef +fe918623 +f95ff06f +fe010113 +00912a23 +01212823 +00050913 +00812c23 +01312623 +01412423 +00112e23 +00058993 +00090413 +ee5ff0ef +0f418493 +fe91c783 +06f46263 +00098493 +06049a63 +01340433 +0ff47413 +02897663 +fed1c783 +05000693 +008787b3 +fff78713 +02d74733 +02d7e7b3 +fee18623 +fe8185a3 +0017b793 +fef18523 +01812403 +01c12083 +01412483 +01012903 +00c12983 +00812a03 +fe81c503 +02010113 +e79ff06f +008487b3 +0007c503 +00140413 +0ff47413 +f09fe0ef +f85ff06f +02000513 +fff48493 +ef9fe0ef +0ff4f493 +f7dff06f +fe010113 +01212823 +01312623 +00812c23 +01412423 +01512223 +fe91ca03 +00112e23 +00912a23 +00050413 +0f900a93 +948ff0ef +0f418993 +fe91c483 +029ae463 +a28ff0ef +02050063 +00148793 +fff40413 +009984b3 +fef184a3 +00a48023 +0ff47413 +fc041ce3 +fe91c703 +01812403 +01c12083 +01412483 +01012903 +00c12983 +00412a83 +000a0513 +00812a03 +fee18423 +00000593 +02010113 +eadff06f +ff010113 +01212023 +00812423 +00912223 +fe81c403 +fe91c483 +00140593 +40848633 +0f418513 +00b505b3 +fff60613 +00850533 +00112623 +4cd040ef +fff48493 +00040513 +00812403 +fe9184a3 +00c12083 +00412483 +00012903 +00100593 +01010113 +e4dff06f +fe010113 +00112e23 +00812c23 +00912a23 +01212823 +01312623 +01412423 +00100a13 +00050993 +f5400023 +00600513 +00058913 +00060413 +00068493 +dd5fe0ef +f4000023 +f5400023 +00098513 +dc5fe0ef +009404b3 +00090513 +01049493 +dcdfe0ef +0104d493 +01041793 +0107d793 +02f49c63 +f4004503 +f4000023 +01c12083 +01812403 +00155513 +00154513 +01412483 +01012903 +00c12983 +00812a03 +00157513 +02010113 +00008067 +00044503 +00140413 +d65fe0ef +fb5ff06f +ff010113 +00112623 +00812423 +00912223 +01212023 +00100793 +00058413 +00060493 +00050913 +f4f00023 +00300513 +d31fe0ef +009404b3 +00090513 +01049493 +d39fe0ef +0104d493 +01041793 +0107d793 +02f49063 +f4000023 +00c12083 +00812403 +00412483 +00012903 +01010113 +00008067 +00000513 +00140413 +ce9fe0ef +fea40fa3 +fc9ff06f +00c55783 +00a55703 +08e7f463 +00e55683 +ff010113 +00812423 +00112623 +0087d713 +00050413 +04e68263 +00e51723 +00c7d713 +00870713 +00171713 +00e50733 +00075503 +00001737 +f0070713 +00e7f7b3 +00240737 +00c51513 +00e787b3 +10000613 +02140593 +00f50533 +f1dff0ef +00c45783 +00c12083 +00178713 +0ff7f793 +00e41623 +00f40433 +02144503 +00812403 +01010113 +00008067 +fff00513 +00008067 +fe010113 +00912a23 +00112e23 +00812c23 +01212823 +01312623 +01412423 +00050493 +f49ff0ef +06054863 +00a00793 +00000413 +02f50a63 +0f900a13 +0f418913 +00a00993 +008a6a63 +00140793 +00890433 +00a40023 +0ff7f413 +00048513 +f11ff0ef +00054463 +ff3510e3 +0f418793 +008787b3 +00078023 +00100513 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +02010113 +00008067 +00000513 +fddff06f +fb010113 +04912223 +05212023 +03312e23 +00050913 +00058993 +00060493 +00060693 +00058613 +00050593 +00200513 +04112623 +04812423 +03412c23 +03512a23 +03612823 +03712623 +d59ff0ef +00051663 +01200513 +350000ef +00010ab7 +3d8000ef +00000413 +02000b93 +fffa8a93 +02946863 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +05010113 +00008067 +40848a33 +014bd463 +02000a13 +010a1b13 +010b5b13 +000b0613 +00010593 +01240533 +d95ff0ef +015a7633 +008985b3 +00010513 +1e5040ef +00050663 +01200513 +2cc000ef +01640433 +01041413 +01045413 +f85ff06f +fe010113 +00812c23 +00c55403 +01212823 +01312623 +00112e23 +00912a23 +01441793 +00050913 +00058993 +0a079263 +00c45413 +00700793 +0087f663 +01300513 +27c000ef +0000f737 +10c70793 +0067d783 +0000f537 +1c000493 +10c70613 +1bf00313 +0d050513 +00200693 +00f36463 +00078693 +0036d713 +01071713 +01075713 +00e50733 +00074583 +0076f893 +00168793 +4115d833 +01079793 +00187813 +0107d793 +0a081a63 +00100513 +01151533 +00a5e5b3 +00b70023 +00f61323 +00068493 +00840413 +00141413 +00890433 +00941023 +00048513 +2f0000ef +00c95783 +0ff7f713 +00178793 +00e90733 +01079793 +033700a3 +0107d793 +00f91623 +0ff7f713 +06071c63 +fff78713 +40c75713 +00870713 +00171713 +00e90733 +00075503 +f0078793 +01812403 +01479793 +01c12083 +01412483 +00c12983 +0147d793 +00240737 +02190593 +01012903 +00c51513 +00e787b3 +10000613 +00f50533 +02010113 +dd1ff06f +fff48493 +01049493 +0104d493 +f00494e3 +00f00513 +158000ef +f51ff06f +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00050593 +00011537 +e4850513 +e71ff06f +1e018a23 +fef1c503 +02050063 +12200793 +02f50533 +000117b7 +e4878793 +00a00593 +00a78533 +e49ff06f +ff010113 +00d00513 +00112623 +8e5fe0ef +00c12083 +00a00513 +01010113 +8d5fe06f +00a00793 +00f51463 +fb1ff06f +00800793 +02f51c63 +1f41c783 +00078663 +fff78793 +1ef18a23 +fef1c783 +02078a63 +12200713 +02e787b3 +00050593 +00011537 +e4850513 +00f50533 +de1ff06f +01f00793 +fca7fce3 +1f41c783 +00178793 +fc9ff06f +875fe06f +ff010113 +00812423 +00112623 +00050413 +00044503 +00051a63 +00c12083 +00812403 +01010113 +00008067 +00140413 +f75ff0ef +fe1ff06f +fe010113 +00050793 +00112e23 +000106a3 +00d10513 +00a00693 +00900613 +02d7f733 +fff50513 +03070713 +00e50023 +00078713 +02d7d7b3 +fee664e3 +f95ff0ef +01c12083 +02010113 +00008067 +fef1c683 +ff010113 +00812423 +00112623 +00050413 +00068863 +fe0187a3 +fee1c703 +1ee18a23 +1f41c783 +00078463 +eb1ff0ef +01600793 +0087e663 +03f00513 +ee9ff0ef +000097b7 +00241413 +9d478793 +008787b3 +0007a503 +f31ff0ef +3301a403 +02040263 +00008537 +31050513 +f1dff0ef +00244783 +00144503 +00879793 +00a7e533 +f3dff0ef +e5dff0ef +00100593 +1f818513 +2b0050ef +ff010113 +01212023 +e0002903 +00812423 +00001437 +00912223 +00112623 +00100493 +bb840413 +f4900023 +00500513 +f4cfe0ef +00000513 +f44fe0ef +00157513 +f4000023 +00051e63 +00c12083 +00812403 +00412483 +00012903 +01010113 +00008067 +e0002783 +412787b3 +fcf450e3 +01200513 +f05ff0ef +00c51513 +002405b7 +ff010113 +00b505b3 +00000693 +00000613 +02000513 +00112623 +8ddff0ef +00051663 +01200513 +ed5ff0ef +00c12083 +01010113 +f59ff06f +0000f737 +0bc72783 +0207da63 +f0004783 +0017f793 +02078463 +f0104783 +00300613 +0ff7f693 +00c79a63 +ff010113 +01700513 +00112623 +e91ff0ef +0ad72e23 +00008067 +00c5e7b3 +ff010113 +01079793 +00112623 +00812423 +00912223 +01212023 +4107d793 +0207ce63 +00160713 +00158793 +02e787b3 +01900713 +00050413 +00058493 +00060913 +01079793 +0107d793 +06a77063 +0ff00713 +00f74663 +05000713 +0600006f +00500513 +e25ff0ef +00078513 +00000593 +d4f6a023 +504040ef +00050793 +00341413 +65018513 +00850533 +00c12083 +00812403 +00951223 +01251323 +00f52023 +00412483 +00012903 +01010113 +00008067 +00001737 +77070713 +faf746e3 +00400713 +02f70733 +000116b7 +d406a783 +01071613 +00011737 +d4472703 +01065613 +40c787b3 +00170713 +f8f764e3 +00700513 +f7dff06f +fe010113 +00052783 +00812c23 +00050593 +00112e23 +00912a23 +01212823 +01312623 +00000613 +00000713 +00000693 +00000413 +00000513 +02e00313 +00900e13 +00800e93 +00a00f13 +0007c803 +00681863 +18061863 +00100613 +0380006f +fd080893 +0ff8ff93 +05fe6263 +02dee863 +03e50533 +00a88533 +00050663 +00168693 +0ff6f693 +40c40433 +01041413 +41045413 +00100713 +00178793 +fb5ff06f +00060713 +fe061ae3 +00140413 +fe1ff06f +12070e63 +04500713 +02e81863 +0017c703 +fd570693 +0fd6f693 +08068e63 +00178693 +00000713 +0006c603 +00900813 +fd060613 +0ff67613 +0ec87463 +00f5a023 +498060ef +00040793 +00045863 +408007b3 +01079793 +4107d793 +03f00713 +00078913 +00f75463 +03f00913 +000094b7 +01091913 +9b048493 +41095913 +01848993 +00197793 +00078863 +0004a583 +0a045663 +4c8050ef +00448493 +40195913 +ff3492e3 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +fd370713 +00173713 +00278693 +f65ff06f +011e4c63 +03d787b3 +00f60633 +fd060613 +01061893 +4108d893 +00168693 +0006c603 +01089793 +0107d793 +fd060813 +0ff87813 +fd0378e3 +00070863 +40f007b3 +01079793 +0107d793 +008787b3 +01079413 +41045413 +00068793 +f21ff06f +00000893 +00900313 +06300e13 +00a00e93 +fb5ff06f +231050ef +f59ff06f +f00710e3 +00000513 +bb9ff0ef +ff010113 +00112623 +c01fe0ef +00051463 +ba5ff0ef +00c12083 +01010113 +00008067 +000097b7 +ba07a583 +ff010113 +00812423 +00112623 +00050413 +04d050ef +00a04c63 +000097b7 +ba47a583 +00040513 +101050ef +00055663 +00a00513 +b5dff0ef +00040513 +2bc060ef +00c12083 +00812403 +01051513 +41055513 +01010113 +00008067 +ff010113 +00112623 +c40fe0ef +fd050793 +0ff7f793 +00900713 +00000513 +02f76663 +00900613 +00a00593 +3341a703 +00074783 +fd078793 +0ff7f793 +00f67a63 +00c12083 +01010113 +00008067 +af1ff0ef +02b50533 +00170793 +32f1aa23 +00074783 +fd078793 +00f50533 +01051513 +01055513 +fbdff06f +ff010113 +00812423 +00112623 +00050413 +b94fe0ef +00054783 +00078c63 +00254783 +00154703 +00879793 +00e7e7b3 +00878663 +00100513 +a95ff0ef +32a1a823 +00c12083 +00812403 +00350513 +32a1aa23 +00100713 +fee18823 +01010113 +00008067 +3381c703 +01f00793 +00e7fa63 +ff010113 +00d00513 +00112623 +a55ff0ef +00371613 +33c18793 +00c787b3 +3341a603 +00170713 +32e18c23 +00c7a023 +3301a603 +00c7a223 +f65ff06f +000116b7 +8101a783 +d406a683 +00d7ea63 +ff010113 +00700513 +00112623 +a0dff0ef +00178693 +80d1a823 +00a78023 +00008067 +02b67a63 +00161613 +00c50533 +00051503 +00f00793 +01051713 +01075713 +0ff57513 +00e7fe63 +ff010113 +00a00513 +00112623 +9c9ff0ef +0000f7b7 +0b87c503 +00008067 +fe010113 +00112e23 +00812c23 +00912a23 +01312623 +01512223 +01212823 +01412423 +01612023 +00050993 +a6cfe0ef +00050413 +ff418513 +0c0040ef +01051493 +ff418793 +0104d493 +00f507b3 +ff418593 +02000713 +00048863 +fff7c683 +fff78793 +08e68463 +ed4fe0ef +00044a03 +020a0e63 +00244783 +00144703 +00879793 +00e7e7b3 +02f99463 +00011b37 +d44b2903 +014405b3 +00040513 +00190613 +40b60633 +41490933 +7b9030ef +d52b2223 +08048e63 +00448913 +01091913 +01095913 +0ff00793 +00900513 +0327e263 +00011b37 +d44b2a03 +00011737 +d4072703 +00190793 +00fa07b3 +02e7e263 +00700513 +8d9ff0ef +fff48493 +01049493 +0104d493 +009586b3 +00068023 +f59ff06f +001a0613 +40860633 +00040593 +01240533 +749030ef +00148613 +013400a3 +01061613 +0089d993 +01240023 +01340123 +01065613 +ff418593 +00340513 +012a0a33 +6f9030ef +d54b2223 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +00012b03 +02010113 +00008067 +1f41c783 +05000713 +fb010113 +02e7f7b3 +04912223 +05212023 +03312e23 +03412c23 +00008a37 +03512a23 +03612823 +03712623 +03812423 +04112623 +04812423 +03912223 +03a12023 +01b12e23 +fe018423 +fe0184a3 +fe01a223 +01500b13 +07e00a93 +01f00b93 +01400c13 +748a0a13 +fef186a3 +fe018523 +fe0185a3 +fe018623 +a24fe0ef +00050413 +02ab6263 +fe050ae3 +fff50413 +0ff47413 +fe8c64e3 +00241413 +01440433 +00042783 +00078067 +08aae063 +14abec63 +01b00793 +fcf514e3 +9e8fe0ef +05b00713 +00050793 +00e50663 +04f00713 +22e51063 +00000413 +00900c93 +03e00d13 +9c4fe0ef +fd050713 +0ff77713 +00050793 +0eecfa63 +fc050713 +0ff77713 +feed62e3 +07e00713 +1ee51863 +03100793 +1af40463 +03400793 +1af40463 +03300793 +1af40a63 +fe81c503 +e85fe0ef +f59ff06f +07f00793 +f4f518e3 +fe81c783 +f40784e3 +fff78793 +fef18423 +8b0ff0ef +f39ff06f +fe91c403 +00040513 +fe818423 +e51fe0ef +dd8ff0ef +0f418793 +008787b3 +00078023 +00040a63 +00011537 +0f418593 +d4850513 +65d030ef +00100513 +0240006f +fe91c503 +fea18423 +e19fe0ef +00008537 +31850513 +e40ff0ef +d94ff0ef +00000513 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +02412c83 +02012d03 +01c12d83 +05010113 +00008067 +00050413 +ef9ff06f +fe91c583 +fe018423 +fe0184a3 +fe01a223 +00000513 +e9dfe0ef +e7dff06f +fe91cc83 +0f900793 +e797e8e3 +fe81cd03 +0f418513 +001d0793 +00ad0db3 +41ac8633 +000d8593 +00f50533 +00f12623 +4c1030ef +00c12783 +001c8c93 +008d8023 +fef18423 +ff9184a3 +00000593 +000d0513 +fadff06f +fbd78793 +0ff7f793 +00d00713 +eaf76ee3 +00008737 +00279793 +79c70713 +00e787b3 +0007a783 +00078067 +fe81c783 +fe91c703 +00e7f863 +00178793 +fef18423 +e8dff06f +00100513 +ec5fe0ef +e81ff06f +fe81c783 +e6078ce3 +fff78793 +fe1ff06f +fe018423 +e69ff06f +fe91c783 +fe81c703 +fcf766e3 +0fa00513 +fd1ff06f +fe81c703 +fe91c783 +00f77663 +f19fe0ef +e41ff06f +ff1fd0ef +8dcfe0ef +e35ff06f +e35508e3 +04100713 +f6e790e3 +000115b7 +d4858593 +0f418513 +fe91c403 +4cd030ef +0f418513 +481030ef +0ff57513 +fea18423 +fea184a3 +fe01a223 +00000593 +00857663 +40a40433 +0ff47593 +00000513 +d61fe0ef +de1ff06f +fe010113 +00912a23 +0000f4b7 +00812c23 +10c48413 +00445783 +01412423 +01212823 +8501c903 +00178793 +00112e23 +01312623 +01512223 +01612023 +78800513 +00f41223 +00194913 +9f4fe0ef +78a41423 +00090513 +dc4ff0ef +002407b7 +00c91993 +78a78793 +10c48493 +78a00413 +10000b13 +00f989b3 +f8a00a93 +00040613 +008b7463 +10000613 +01061613 +00048593 +40898533 +01065613 +f0040413 +8e0ff0ef +10048493 +fd541ce3 +01c12083 +01812403 +85218823 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +00012b03 +02010113 +00008067 +ff010113 +00812423 +002407b7 +0000f437 +00c51513 +78a00613 +10c40593 +00f50533 +00112623 +00912223 +01212023 +ec9fe0ef +000085b7 +00400613 +31c58593 +10c40513 +315030ef +02051c63 +10c40413 +78845403 +78800513 +918fe0ef +40a407b3 +0017b793 +00c12083 +00812403 +00412483 +00012903 +00078513 +01010113 +00008067 +000085b7 +00400613 +32458593 +10c40513 +2c9030ef +00000793 +fc0516e3 +10c40793 +6887d483 +68800513 +8c8fe0ef +10c40413 +00000793 +faa498e3 +fbe18793 +ec218493 +fea40913 +00048593 +00078513 +01a00613 +219030ef +00051e23 +00051d23 +fe250793 +fe648493 +ff2790e3 +325347b7 +64278793 +00f42023 +00100793 +f6dff06f +fe010113 +00112e23 +00100793 +00812c23 +00912a23 +01212823 +01312623 +f4f00023 +09f00513 +b35fd0ef +00000513 +b2dfd0ef +00050493 +00000513 +b21fd0ef +00050413 +00000513 +b15fd0ef +0c200713 +f4000023 +04e49263 +02000713 +02e41e63 +01600713 +02e51a63 +00000513 +ea1ff0ef +0000f9b7 +00050913 +10c98493 +00100513 +0044d403 +e89ff0ef +00091c63 +04050c63 +00100793 +0300006f +01200513 +ab8ff0ef +00050c63 +0044d783 +40f40433 +01041413 +41045413 +fc805ee3 +00000513 +e51ff0ef +00000793 +01c12083 +01812403 +84f18823 +01412483 +01012903 +00c12983 +02010113 +00008067 +78a00613 +00000593 +10c98513 +155030ef +325347b7 +64278793 +00f4a023 +00200793 +00f49323 +f89ff06f +fb010113 +04112623 +04812423 +04912223 +05212023 +03312e23 +03412c23 +03512a23 +0000fa37 +00050493 +00058913 +00060993 +ec9ff0ef +03800613 +00000593 +0d0a0513 +0f9030ef +0d0a0413 +00300793 +00f40023 +0000f437 +10c40a93 +00001837 +10c40693 +780a8313 +0d0a0613 +10c40413 +fff80813 +00100e13 +0086c783 +0e079e63 +01e68693 +fe669ae3 +000117b7 +e4878793 +00001837 +48878313 +04f00e13 +fff80813 +00100e93 +0007c703 +10071e63 +12278793 +fe679ae3 +00090513 +f8dfd0ef +00050a13 +00055a63 +00000793 +04000693 +008ac703 +14071663 +00800613 +00090593 +00148513 +7e4030ef +04f00793 +00049623 +02048023 +00f48023 +06098063 +040a4e63 +01e00793 +02fa0a33 +01e00613 +01010513 +000019b7 +00240ab7 +fff98993 +014405b3 +00858593 +7a4030ef +01815a03 +01a10593 +01048513 +00ca5413 +00141913 +00090613 +788030ef +00c41413 +03090793 +00849623 +00278933 +0f446463 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +05010113 +00008067 +0106d703 +00068893 +00000593 +01070733 +40c75713 +0ff77713 +00288893 +eeb706e3 +0108d783 +00158593 +0ff5f593 +0037d513 +00a60533 +00054e83 +0077f793 +00fe17b3 +01d7e7b3 +00f50023 +fd1ff06f +05c71863 +00c7d703 +01070733 +40c75713 +0ff77713 +00078893 +00000593 +00288893 +ecb704e3 +00e8d683 +00158593 +0ff5f593 +0036d513 +00a60533 +00054f03 +0076f693 +00de96b3 +01e6e6b3 +00d50023 +fd1ff06f +00a7d703 +fb5ff06f +00178793 +01079793 +0107d793 +01ea8a93 +ead790e3 +01000513 +818ff0ef +fea95783 +01347533 +00100613 +00c79793 +015787b3 +00a78533 +00f10593 +aa5fe0ef +00f14583 +00140413 +00048513 +01041413 +d2dfe0ef +01045413 +ee1ff06f +00054703 +04f00793 +00050023 +16f71463 +00c55783 +fe010113 +00912a23 +00112e23 +00812c23 +01212823 +01312623 +0ff7f613 +00050493 +04060063 +fff78713 +40c75713 +00870713 +00171713 +00e50733 +00075503 +40c787b3 +01479793 +0147d793 +00240737 +00c51513 +00e787b3 +02148593 +00f50533 +bc9fe0ef +c15ff0ef +00148913 +00090513 +d51fd0ef +0000f7b7 +00050413 +10c78993 +00055c63 +10c78793 +00000413 +04000693 +0087c703 +0a071663 +01e00713 +02e407b3 +00f987b3 +0087c783 +02078263 +0ff47793 +02e787b3 +00f987b3 +0247d703 +0227d783 +01071713 +00f767b3 +02079063 +d71fd0ef +01e00793 +02f407b3 +00f987b3 +02a79123 +01055513 +02a79223 +01e00793 +02f40433 +00090593 +00800613 +00840513 +00a98533 +540030ef +00c4d703 +008987b3 +01240413 +00898533 +01048593 +01000613 +00e79823 +520030ef +01812403 +01c12083 +01412483 +01012903 +00c12983 +02010113 +979ff06f +00140413 +01041713 +01075713 +01041413 +41045413 +01e78793 +f2d71ce3 +01000513 +e69fe0ef +00008067 +00011537 +ff010113 +f6a50513 +00112623 +e79ff0ef +00011537 +08c50513 +e6dff0ef +00c12083 +00011537 +1ae50513 +01010113 +e59ff06f +ff010113 +00912223 +01212023 +00112623 +00812423 +00050493 +00058913 +ac1ff0ef +00090513 +c01fd0ef +00055663 +00e00513 +dfdfe0ef +00090593 +00050413 +00800613 +00148513 +460030ef +01e00793 +02f40433 +0000f5b7 +10c58593 +01048513 +01000613 +008587b3 +0107d783 +01240413 +008585b3 +00f49523 +430030ef +fff00793 +00f49723 +04900793 +00f48023 +00c12083 +00812403 +00049623 +00012903 +00412483 +01010113 +00008067 +f8010113 +06112e23 +06812c23 +06912a23 +07212823 +07312623 +07412423 +07512223 +02d00513 +db9fd0ef +02050c63 +fd5ff0ef +80000437 +00a44433 +07c12083 +00040513 +07812403 +07412483 +07012903 +06c12983 +06812a03 +06412a83 +08010113 +00008067 +02b00513 +d79fd0ef +fa051ce3 +e2cfd0ef +fd050793 +0ff7f793 +00900713 +00050413 +00f77663 +02e00793 +0af51863 +33418513 +f5dfe0ef +00050413 +000097b7 +bb47aa83 +05e00513 +d39fd0ef +f80508e3 +f55ff0ef +00050993 +43c050ef +01051913 +41095913 +00090513 +4a0050ef +00050593 +00098513 +115040ef +4c051a63 +000a8593 +00098513 +179040ef +4c054263 +000097b7 +bb87a583 +00098513 +22d040ef +4aa04863 +00090993 +00095863 +412009b3 +01099993 +4109d993 +00009a37 +b94a2483 +46099063 +00095a63 +b94a2503 +00048593 +4b8040ef +00050493 +00048413 +f6dff06f +02800793 +02f51263 +3341a783 +00178793 +32f1aa23 +6dc000ef +00050413 +02900513 +87cff0ef +f3dff06f +e14fd0ef +00050663 +00800513 +c1dfe0ef +0c100793 +0af41863 +3341a783 +00178793 +32f1aa23 +d14fd0ef +fbf50513 +0ff57713 +01900793 +00e7f663 +00000513 +fd1ff06f +3341a783 +00351513 +58018493 +00178793 +00a484b3 +32f1aa23 +0004a783 +00b00513 +fa0786e3 +02800513 +80cff0ef +65c000ef +00050413 +02900513 +ffdfe0ef +0044c783 +000119b7 +8c898993 +00279793 +00f987b3 +0007aa03 +0087a023 +0004a783 +3341aa83 +32f1aa23 +624000ef +0044c783 +00050413 +3351aa23 +00279793 +00f989b3 +0149a023 +e79ff06f +04a40493 +0ff4f713 +01a00793 +32e7e663 +0c200793 +f6f400e3 +3341a783 +00178793 +32f1aa23 +0bf00793 +04f41a63 +02800513 +b89fd0ef +00050863 +5cc000ef +02900513 +f71fe0ef +8081a503 +41c657b7 +e6d78793 +02f50533 +000037b7 +03978793 +00f50533 +80a1a423 +00855513 +3f0050ef +000097b7 +bac7a583 +159040ef +df9ff06f +0cf00793 +00f41e63 +e0002503 +2b8050ef +000097b7 +bb07a583 +328040ef +dd9ff06f +02800513 +f11fe0ef +0d000793 +06f41863 +558000ef +f21fe0ef +00050493 +02c00513 +ef5fe0ef +544000ef +f0dfe0ef +00050413 +02900513 +ee1fe0ef +01049793 +0107d793 +13f00713 +22f76063 +01041713 +01075713 +0ef00693 +20e6e863 +0ff4f493 +f2900823 +0087d793 +f2f008a3 +0ff47413 +f2800923 +f3304503 +348050ef +d5dff06f +0c800793 +02f41863 +04900513 +53c000ef +00050413 +02900513 +e81fe0ef +00c45703 +00a45783 +1cf76263 +000097b7 +ba87a403 +d2dff06f +03b40793 +0ff7f793 +00200713 +0af76863 +01010493 +00048513 +00912623 +48d000ef +02900513 +e41fe0ef +0c500793 +00f41863 +00048513 +120030ef +f8dff06f +0c700793 +01014503 +f8f400e3 +00000693 +02000613 +00048793 +0007c703 +00148493 +02c70863 +00068463 +00f12623 +02d00693 +02d71463 +00178793 +00c10513 +00f12623 +80000437 +bfdfe0ef +00a44433 +ca1ff06f +00100693 +fc1ff06f +02b00693 +00d71663 +00178793 +00f12623 +00c12783 +00000413 +00c10513 +0007c783 +c6078ae3 +c69ff06f +3fc000ef +00050413 +02900513 +d9dfe0ef +0ff4f493 +00e00793 +d497eae3 +000087b7 +7d478793 +00249493 +00f484b3 +0004a783 +00078067 +00040513 +258030ef +c2dff06f +00040513 +338030ef +c21ff06f +00040513 +424030ef +c15ff06f +00040513 +558030ef +c09ff06f +00040513 +235030ef +bfdff06f +00000593 +00040513 +67c040ef +00a04663 +00a00513 +cbdff06f +00040513 +68c030ef +bd9ff06f +00000593 +00040513 +658040ef +bc0556e3 +800007b7 +0087c433 +bc1ff06f +00000593 +00040513 +63c040ef +fc0542e3 +00040513 +095030ef +ba1ff06f +00040513 +16d030ef +b95ff06f +00000593 +00040513 +54c040ef +04a04063 +00000593 +00040513 +604040ef +e40542e3 +00000413 +b71ff06f +00040513 +7c1040ef +00054503 +dfdff06f +00040513 +cb5fe0ef +0ff57513 +f0054503 +de9ff06f +000097b7 +b947a403 +b41ff06f +fbf40413 +0ff47413 +01900793 +c287e8e3 +50c000ef +00052403 +b25ff06f +0019f793 +00078a63 +00048513 +00040593 +668040ef +00050493 +00040593 +00040513 +658040ef +4019d993 +00050413 +b75ff06f +00000593 +00040513 +570040ef +ee054ce3 +00000593 +00040513 +424040ef +00000493 +b60504e3 +00040513 +574030ef +00050593 +00098513 +614040ef +0e9030ef +b49ff06f +ff010113 +00112623 +00812423 +00912223 +a09ff0ef +00050413 +02a00513 +fd8fd0ef +00050c63 +9f5ff0ef +00050593 +00040513 +5d8040ef +fe1ff06f +02f00513 +fb8fd0ef +02050863 +9d5ff0ef +00000593 +00050493 +3ac040ef +00051663 +00600513 +f44fe0ef +00048593 +00040513 +791030ef +fa9ff06f +00c12083 +00040513 +00812403 +00412483 +01010113 +00008067 +ff010113 +00112623 +00812423 +f6dff0ef +00050413 +02b00513 +f54fd0ef +00050c63 +f59ff0ef +00050593 +00040513 +26d030ef +fe1ff06f +02d00513 +f34fd0ef +00050c63 +f39ff0ef +00050593 +00040513 +115040ef +fc1ff06f +00c12083 +00040513 +00812403 +01010113 +00008067 +f4010113 +0b500513 +0a112e23 +0a812c23 +0a912a23 +ef0fd0ef +02050863 +fe5ff0ef +afdfe0ef +fff54513 +665040ef +00050493 +0bc12083 +0b812403 +00048513 +0b412483 +0c010113 +00008067 +854fd0ef +04050c63 +01010513 +0ed000ef +eecfd0ef +00050413 +00051663 +00800513 +e48fe0ef +06010513 +0d1000ef +06010593 +01010513 +58d020ef +01051513 +41055513 +06055063 +00147413 +00000493 +f8040ee3 +000097b7 +ba87a483 +f91ff06f +ef5ff0ef +00050493 +e98fd0ef +00050413 +f6050ee3 +ee1ff0ef +00050593 +00a12623 +00048513 +380040ef +fc0540e3 +00c12583 +00048513 +2a8040ef +00a05863 +00447413 +fadff06f +fe051ce3 +00247413 +fa1ff06f +ff010113 +00112623 +00812423 +f01ff0ef +00050413 +0b300513 +df8fd0ef +00051c63 +00c12083 +00040513 +00812403 +01010113 +00008067 +00040513 +9f1fe0ef +00050413 +ecdff0ef +9e5fe0ef +00a47533 +01051513 +41055513 +545040ef +fb9ff06f +ff010113 +00112623 +00812423 +f99ff0ef +00050413 +0b400513 +d9cfd0ef +00051c63 +00c12083 +00040513 +00812403 +01010113 +00008067 +00040513 +995fe0ef +00050413 +f65ff0ef +989fe0ef +00a46533 +01051513 +41055513 +4e9040ef +fb9ff06f +ff010113 +00812423 +00050413 +02300513 +00112623 +d44fd0ef +f8dff0ef +955fe0ef +fff50793 +01079793 +0107d793 +00200713 +00f77663 +00a00513 +cccfe0ef +12200713 +02e50733 +000117b7 +e4878793 +00e78533 +00054783 +00878663 +01500513 +fddff06f +00c12083 +00812403 +01010113 +00008067 +fe010113 +01212823 +00050913 +02800513 +00112e23 +00912a23 +01312623 +01412423 +00812c23 +01512223 +8b9fe0ef +f09ff0ef +8d1fe0ef +00050993 +02c00513 +cacfd0ef +00050a13 +00000493 +00050863 +ee9ff0ef +8b1fe0ef +00050493 +02900513 +885fe0ef +65018793 +00391a93 +015787b3 +0007a783 +65018413 +00079e63 +00000613 +000a0463 +00a00613 +00a00593 +00090513 +d84fe0ef +0209c263 +01540733 +00471783 +0137cc63 +0004ca63 +00675783 +01079693 +4106d693 +0096d663 +00500513 +bdcfe0ef +00178793 +033787b3 +01900693 +00072503 +05000713 +009787b3 +0126e463 +00400713 +02e787b3 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +02010113 +00f50533 +00008067 +ff010113 +00112623 +00812423 +00912223 +c8dfc0ef +3341a783 +00050413 +fbf50493 +00278793 +32f1aa23 +c75fc0ef +02800793 +02f51063 +fd940513 +00812403 +00c12083 +00412483 +0ff57513 +01010113 +eadff06f +0ff4f493 +05000793 +02f484b3 +00c12083 +00812403 +00010537 +0a850513 +00950533 +00412483 +01010113 +00008067 +ff010113 +00112623 +c19fc0ef +fbf50513 +0ff57513 +01900793 +02a7ea63 +3341a783 +02800693 +0017c603 +02d61263 +0007c503 +00c12083 +00178793 +fbf50513 +32f1aa23 +0ff57513 +01010113 +e35ff06f +c21fc0ef +0ff00793 +00f51663 +00000513 +ab4fe0ef +00c12083 +000117b7 +00251513 +8c878793 +00a78533 +01010113 +00008067 +fe010113 +00812c23 +00052403 +00912a23 +00112e23 +01212823 +00050493 +00812623 +b85fc0ef +00040793 +00000713 +02000693 +00078413 +00044603 +00178793 +08d60263 +00070463 +00812623 +fbf50513 +0ff57513 +01900793 +12a7e263 +3341a783 +0017c703 +02400793 +10f71a63 +ea1ff0ef +00044703 +02200793 +04f70a63 +00c12703 +00000693 +00000793 +02c00593 +04e00813 +00074603 +0c061263 +00068463 +00e12623 +00f50733 +02000693 +04078663 +fff74603 +fff70713 +04d61063 +fff78793 +0ff7f793 +fe9ff06f +00100713 +f6dff06f +00140413 +00812623 +00000693 +00000793 +02200613 +04e00593 +00044703 +04071663 +00068463 +00812623 +00f50533 +00050023 +00c12783 +02000693 +00078713 +0007c603 +00178793 +fed60ae3 +00e4a023 +00100513 +01c12083 +01812403 +01412483 +01012903 +02010113 +00008067 +00140413 +fac70ce3 +00f5ea63 +00178693 +00f507b3 +00e78023 +0ff6f793 +00100693 +f91ff06f +f4b600e3 +00f86a63 +00178693 +00f507b3 +00c78023 +0ff6f793 +00170713 +00100693 +f19ff06f +e0dff0ef +00044783 +02d00713 +00050913 +04e79863 +00140413 +00812623 +00100413 +00c12783 +00900693 +0007c703 +fd070793 +0ff7f793 +00f6f863 +02e00793 +00000513 +f6f710e3 +00c10513 +b38fe0ef +00040663 +800007b7 +00a7c533 +00a92023 +f25ff06f +02b00713 +00e79663 +00140413 +00812623 +00000413 +fadff06f +fe010113 +00812c23 +00912a23 +01212823 +01312623 +00112e23 +00058913 +00060993 +00050493 +00000413 +b1dff0ef +00140413 +ce0fe0ef +0ff47413 +00a49023 +01340a63 +02c00513 +8b4fd0ef +00248493 +fc051ee3 +01247663 +00000513 +84cfe0ef +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +f9010113 +06912223 +06112623 +06812423 +07212023 +05312e23 +00050493 +91dfc0ef +02200713 +08e51463 +3341a703 +02200513 +04f00813 +00170713 +32e1aa23 +00000713 +3341a683 +00e48633 +0006c583 +00058463 +02a59c63 +00060023 +3341a703 +00074683 +00068663 +00170713 +32e1aa23 +06c12083 +06812403 +06412483 +06012903 +05c12983 +07010113 +00008067 +01071663 +00900513 +f99fd0ef +00168593 +32b1aa23 +0006c683 +00170713 +00d60023 +f99ff06f +fbf50693 +0ff6f693 +01900613 +3341a703 +00050993 +02d66c63 +00174603 +02400693 +02d61663 +bcdff0ef +06812403 +06c12083 +06012903 +05c12983 +00050593 +00048513 +06412483 +07010113 +6b40206f +00170713 +32e1aa23 +0ce00793 +02f99663 +d95fc0ef +06812403 +06c12083 +06012903 +05c12983 +00048593 +06412483 +00100613 +07010113 +dbdfc06f +02800513 +b40fe0ef +0ca00793 +0af98863 +0137ea63 +0c900793 +06f98a63 +00000513 +f41ff06f +03598793 +0ff7f793 +00200713 +fef766e3 +00010513 +150000ef +02c00513 +b04fe0ef +955ff0ef +b1cfe0ef +00050413 +00010513 +5e0020ef +0cd00793 +00050913 +08f99663 +02c00513 +ee5fc0ef +0c050463 +929ff0ef +af0fe0ef +00050993 +00805463 +0a055e63 +00a00513 +ed9ff06f +90dff0ef +ad4fe0ef +00a48023 +000480a3 +06812403 +06c12083 +06412483 +06012903 +05c12983 +02900513 +07010113 +a8cfe06f +8ddff0ef +02000793 +00f48023 +00000593 +00050413 +3c1030ef +00054463 +00148493 +00048593 +00040513 +9f4fd0ef +fb5ff06f +f8044ce3 +00855663 +01051413 +41045413 +0cb00793 +02f99063 +00040613 +00010593 +00048513 +00848433 +45c020ef +00040023 +f81ff06f +408905b3 +00b105b3 +00048513 +54c020ef +f6dff06f +0ff00993 +f48056e3 +00895863 +00190413 +01041413 +41045413 +408907b3 +00178793 +0137da63 +00190513 +40850533 +01051993 +4109d993 +fff40593 +00098613 +00b105b3 +00048513 +013489b3 +3f4020ef +00098023 +f19ff06f +fa010113 +04812c23 +04112e23 +04912a23 +05212823 +00050413 +f44fc0ef +00051663 +00800513 +d4dfd0ef +00040513 +d1dff0ef +04f00913 +02b00513 +d8dfc0ef +00051e63 +05c12083 +05812403 +05412483 +05012903 +06010113 +00008067 +f04fc0ef +fc0502e3 +00010513 +ce5ff0ef +00040513 +440020ef +00050493 +00010513 +434020ef +00a484b3 +00997663 +00900513 +f9dff06f +00010593 +00040513 +478020ef +f9dff06f +fa010113 +04812c23 +00050413 +00010513 +04112e23 +f51ff0ef +00800613 +00000593 +00040513 +3a0020ef +00000793 +01900613 +00800593 +00900513 +00f10733 +00074703 +00071e63 +0ff7f793 +02078263 +05c12083 +05812403 +06010113 +00008067 +f9f70693 +0ff6f693 +00d66863 +02b79c63 +01100513 +c65fd0ef +feb78ce3 +fbf70693 +0ff6f693 +00d67863 +fd070693 +0ff6f693 +fed560e3 +00f406b3 +00e68023 +00178793 +f9dff06f +fe070713 +0ff77713 +fe9ff06f +fd010113 +02912223 +00810513 +000114b7 +02112623 +03212023 +01312e23 +01412c23 +01512a23 +01612823 +02812423 +e4048423 +f25ff0ef +00810593 +e4848513 +dc1fe0ef +0000a7b7 +00078793 +00011737 +00078023 +d4f72223 +e4848a13 +94dfc0ef +02000913 +00900993 +00a00b13 +e4848513 +f80fd0ef +06051a63 +000a0023 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +03010113 +00008067 +00150513 +00054783 +ff278ce3 +fd078793 +0ff7f793 +00000413 +faf9e8e3 +00054703 +fd070793 +0ff7f793 +02f9f263 +00054783 +03278c63 +cd1fc0ef +00040513 +994fe0ef +f89ff06f +0f418513 +fbdff06f +03640433 +00150513 +fd040413 +00e40433 +01041413 +01045413 +fb9ff06f +00150513 +fc1ff06f +f8010113 +06812c23 +07212823 +07312623 +06112e23 +06912a23 +07412423 +00000413 +00f00993 +c24fc0ef +02050463 +0e041863 +07812403 +07c12083 +07412483 +07012903 +06c12983 +06812a03 +08010113 +9a9fd06f +02c00513 +b19fc0ef +02050063 +02000513 +9ddfd0ef +1f41c783 +0337f7b3 +fe0798e3 +00100413 +fb1ff06f +03b00513 +af1fc0ef +00050413 +fe0516e3 +0c200513 +ae1fc0ef +02050a63 +02800513 +ecdfd0ef +d1cff0ef +ee5fd0ef +00050493 +02900513 +eb9fd0ef +1f41c783 +f697d8e3 +02000513 +981fd0ef +ff1ff06f +c40fc0ef +00050c63 +00c10513 +cd9ff0ef +00c10513 +9c5fd0ef +f49ff06f +cd8ff0ef +00000593 +00050493 +6fc030ef +00054663 +02000513 +945fd0ef +00c10593 +00048513 +df5fc0ef +00c10513 +991fd0ef +02000513 +929fd0ef +f0dff06f +07c12083 +07812403 +07412483 +07012903 +06c12983 +06812a03 +08010113 +00008067 +ff010113 +00112623 +00812423 +ae0fc0ef +fbf50513 +0ff57513 +01900793 +02a7ec63 +3341a783 +0017c703 +02400793 +02f71463 +e20ff0ef +00050413 +03d00513 +dedfd0ef +00040513 +00812403 +00c12083 +01010113 +c1dff06f +e78ff0ef +00050413 +03d00513 +dc9fd0ef +c18ff0ef +00c12083 +00a42023 +00812403 +01010113 +00008067 +01051793 +0107d793 +13f00713 +02f76863 +01059713 +01075713 +0ef00693 +02e6e063 +0ff57513 +f2a00823 +0087d793 +f2f008a3 +0ff5f593 +f2b00923 +f2c009a3 +00008067 +fc010113 +02812c23 +03212823 +03412423 +03512223 +01051913 +01061793 +02112e23 +02912a23 +03312623 +03612023 +01712e23 +01812c23 +01912a23 +00068a13 +00058413 +00060a93 +00070693 +01095913 +0107d793 +08c55a63 +412787b3 +01079913 +41095913 +00100c93 +010a1993 +01041793 +0109d993 +0107d793 +09445263 +413787b3 +01079993 +4109d993 +00100b13 +01091b93 +01099c13 +010bdb93 +010c5c13 +018b84b3 +01049493 +4104d493 +068a1463 +03812403 +03c12083 +03412483 +03012903 +02c12983 +02012b03 +01c12b83 +01812c03 +01412c83 +000a0613 +000a8593 +02812a03 +02412a83 +04010113 +c68fc06f +40f90933 +01091913 +41095913 +fff00c93 +f71ff06f +40f989b3 +01099993 +4109d993 +fff00b13 +f81ff06f +00068613 +00040593 +00d12623 +00a12423 +ea5ff0ef +00812503 +00c12683 +01551463 +05440a63 +01049713 +01075713 +00171793 +01079793 +4107d793 +0137ce63 +00ec0733 +01950533 +01071493 +01051513 +4104d493 +41055513 +faf946e3 +009b84b3 +01640433 +01049493 +01041413 +4104d493 +41045413 +f91ff06f +03c12083 +03812403 +03412483 +03012903 +02c12983 +02812a03 +02412a83 +02012b03 +01c12b83 +01812c03 +01412c83 +04010113 +00008067 +06350513 +0ff57513 +00800793 +5ea7e463 +000097b7 +81078793 +00251513 +00f50533 +00052783 +fb010113 +04112623 +04812423 +04912223 +05212023 +03312e23 +03412c23 +03512a23 +03612823 +03712623 +03812423 +00078067 +01b00513 +f09fb0ef +05b00513 +f01fb0ef +03200513 +ef9fb0ef +04a00513 +ef1fb0ef +01b00513 +ee9fb0ef +05b00513 +ee1fb0ef +04800513 +ed9fb0ef +1e018a23 +f2000a23 +f3404783 +0017f793 +fe079ce3 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +05010113 +00008067 +00100613 +00100593 +01410513 +decff0ef +01411783 +00f00713 +01079693 +0106d693 +00d77663 +00a00513 +e74fd0ef +0000f737 +0af70c23 +f9dff06f +00300613 +00200593 +01410513 +db4ff0ef +01411403 +01611483 +00050593 +00200613 +01410513 +c49fd0ef +00050613 +00040513 +04812403 +04c12083 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +00048593 +04412483 +05010113 +ca5ff06f +00500613 +00400593 +01410513 +d50ff0ef +01a11683 +00050593 +00400613 +01410513 +00d12623 +01411403 +be1fd0ef +01611483 +01811903 +00c12683 +00050713 +00090613 +00048593 +00040513 +04812403 +04c12083 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +05010113 +c6dff06f +00500613 +00400593 +01410513 +cd8ff0ef +00050593 +00400613 +01410513 +b75fd0ef +01411a03 +01811903 +01611483 +00050413 +00050693 +00048613 +00090593 +000a0513 +970fc0ef +01a11983 +00040693 +00090593 +00098613 +000a0513 +958fc0ef +00040713 +00098693 +000a0613 +00048593 +000a0513 +bf9ff0ef +00040713 +00098693 +00090613 +00048593 +00090513 +f49ff06f +00500613 +00400593 +01410513 +c4cff0ef +00050593 +00400613 +01410513 +ae9fd0ef +01a11603 +01611703 +00050913 +00060413 +00c75463 +00070413 +01041793 +0007d463 +00000413 +01041413 +41045413 +00060793 +00e65463 +00070793 +01079713 +41075713 +0ef00693 +00e6d463 +0ef00793 +01079493 +4104d493 +da84cee3 +01811583 +01411503 +00040613 +00140413 +00090693 +01041413 +894fc0ef +41045413 +fddff06f +00400613 +00300593 +01410513 +bb0ff0ef +01811b03 +00050593 +00300613 +01410513 +a49fd0ef +01411a03 +01611a83 +00050493 +da0b4ce3 +00100913 +41690933 +01091913 +010a1a13 +010a9a93 +41095913 +00000413 +010a5a13 +010ada93 +010b1993 +0109d993 +01041413 +01045413 +013a0c33 +008a85b3 +010c1c13 +410c5c13 +01059593 +4105d593 +000c0513 +00048613 +00b12623 +413a0bb3 +a71ff0ef +00c12583 +010b9b93 +410bdb93 +000b8513 +00048613 +a59ff0ef +408a85b3 +01059593 +4105d593 +000c0513 +00048613 +00b12623 +a3dff0ef +00c12583 +000b8513 +00048613 +a2dff0ef +008a0c33 +010c1c13 +015985b3 +410c5c13 +01059593 +4105d593 +00048613 +000c0513 +00b12623 +408a0bb3 +a01ff0ef +00c12583 +010b9b93 +410bdb93 +00048613 +000b8513 +9e9ff0ef +413a85b3 +01059593 +4105d593 +00048613 +000c0513 +00b12623 +9cdff0ef +00c12583 +00048613 +000b8513 +9bdff0ef +00140413 +00190793 +01041713 +01079793 +01041413 +01075713 +41045413 +0107d793 +00095e63 +00171713 +00e787b3 +01079913 +41095913 +ec8b5ee3 +c15ff06f +fff98993 +01099b13 +410b5b13 +41640733 +fd9ff06f +00200613 +00200593 +01410513 +a18ff0ef +01411483 +03f00713 +fff48793 +01079793 +0107d793 +c2f766e3 +01611403 +08300713 +fff40793 +01079793 +0107d793 +c0f76ae3 +01b00513 +a79fb0ef +05b00513 +a71fb0ef +0ff4f513 +f31fb0ef +03b00513 +a61fb0ef +0ff47413 +00040513 +f1dfb0ef +04800513 +a4dfb0ef +fff40413 +1e818a23 +b81ff06f +00200613 +00100593 +01410513 +998ff0ef +01411483 +00f00793 +00050413 +01049713 +01075713 +bae7e6e3 +00100713 +00a77663 +01615703 +b8e7eee3 +01b00513 +a01fb0ef +05b00513 +9f9fb0ef +00700713 +0ff4f793 +06974863 +01e78793 +0ff7f513 +ea9fb0ef +00100793 +0287f463 +03b00513 +9d1fb0ef +01611783 +00700713 +0ff7f513 +04f74663 +02850513 +0ff57513 +e7dfb0ef +04812403 +04c12083 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +06d00513 +05010113 +981fb06f +05278793 +f95ff06f +05c50513 +fb9ff06f +00008067 +f4010113 +0a112e23 +0a812c23 +0a912a23 +0b212823 +0b312623 +0b412423 +0b512223 +0b612023 +09712e23 +09812c23 +09912a23 +09a12823 +09b12623 +a4dfb0ef +20050263 +03a00793 +00050493 +1ef50c63 +3341a683 +05400713 +00168793 +32f1aa23 +f8050793 +0ff7f793 +00f77463 +5780106f +00009737 +00279793 +83470713 +00e787b3 +0007a783 +00078067 +02000913 +02200993 +0000aa37 +32c1a783 +000a0713 +02078463 +32c1a783 +0007c703 +7d270863 +02c00693 +00178793 +02d700e3 +3281a703 +00074783 +00f70733 +32e1a423 +00000693 +09200813 +7cc0006f +01900993 +02400a13 +9adfb0ef +fbf50493 +0ff4f493 +2e99ee63 +3341a783 +00178713 +32e1aa23 +0017c703 +01471a63 +00278793 +fd950513 +32f1aa23 +0ff57493 +02800513 +cb0fd0ef +b01fe0ef +cc8fd0ef +01051913 +02c00513 +8a4fc0ef +01095913 +00000613 +00050a63 +ae1fe0ef +ca8fd0ef +01051613 +01065613 +02900513 +00c12623 +c74fd0ef +00c12603 +00048513 +00090593 +994fd0ef +02c00513 +864fc0ef +f60518e3 +0d40006f +00011ab7 +0ff00b13 +44018993 +8c8a8a93 +951fb0ef +43c1c783 +00050a13 +54079263 +00300513 +11c0006f +02300513 +82cfc0ef +04051063 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +c80ff06f +04f00513 +a8dfe0ef +00050413 +8b9fb0ef +00051663 +02c00513 +bc8fd0ef +1f41c903 +0fe3c737 +ff218723 +02044783 +07170713 +1ef18a23 +000117b7 +e4878793 +40f407b3 +4017d793 +02e787b3 +fef187a3 +c30ff0ef +1f41c783 +fe0187a3 +1f218a23 +02f40023 +0bc12083 +0b812403 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +00008067 +02300513 +f49fb0ef +0f418493 +06050a63 +04900513 +9e1fe0ef +00050413 +02c00513 +b24fd0ef +00040513 +a95fc0ef +00051663 +01600513 +ec5fc0ef +02912823 +03010513 +c25fe0ef +00051663 +00800513 +fe9ff06f +02c00513 +ef9fb0ef +f60506e3 +03012783 +02c00693 +0007c703 +00d71863 +00178793 +02f12823 +fc9ff06f +fc0712e3 +fa9ff06f +f88fb0ef +02200793 +02f51463 +03010513 +e41fe0ef +03010513 +de5fc0ef +03b00513 +eadfb0ef +00051663 +02c00513 +a98fd0ef +00008937 +35090513 +dc5fc0ef +decfd0ef +00051663 +01700513 +f6dff06f +02912823 +03010513 +3341a983 +b8dfe0ef +02051863 +00008537 +35450513 +d95fc0ef +ce9fc0ef +35090513 +d89fc0ef +db0fd0ef +fc0504e3 +02912823 +3331aa23 +fc9ff06f +02c00513 +e3dfb0ef +ea0508e3 +03012783 +02c00693 +0007c703 +00d71863 +00178793 +02f12823 +fa1ff06f +f8071ee3 +00008537 +35c50513 +f79ff06f +855fe0ef +00050413 +08400513 +dfdfb0ef +00051c63 +eb0fb0ef +08500793 +00f50663 +00000513 +ecdff06f +00000593 +00040513 +1e1020ef +04051063 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +951fb06f +e50fb0ef +fd050513 +0ff57513 +00900793 +bea7eae3 +9f4fd0ef +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +a28fd06f +9b4fd0ef +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +a44fd06f +3381c783 +00200513 +de0780e3 +fff78793 +0ff7f793 +32f18c23 +33c18713 +00379793 +00f707b3 +0007a703 +32e1aa23 +0047a703 +32e1a823 +00100713 +fee18823 +d3dff06f +dc8fb0ef +0ff00793 +00050b93 +ecf506e3 +03d00513 +8a4fd0ef +ef4fe0ef +000114b7 +8c848793 +002b9b13 +016787b3 +43c1c603 +00a7a023 +44018693 +00000713 +8c848493 +44018993 +00c70a63 +0006c783 +01468693 +01779e63 +42e18e23 +43c1ca83 +00f00793 +0157fc63 +00c00513 +d41ff06f +00170713 +0ff77713 +fd1ff06f +01400913 +032a8933 +08900513 +01298933 +01790023 +82cfd0ef +e7cfe0ef +00050b93 +00a92223 +08a00513 +c21fb0ef +0a050863 +e64fe0ef +00050913 +01400793 +02fa87b3 +3341a703 +00000593 +00090513 +00f987b3 +00e7a623 +3301a703 +0127a423 +00e7a823 +001a8793 +42f18e23 +05d020ef +06054e63 +016484b3 +0004a583 +000b8513 +111020ef +c40550e3 +43518e23 +00000493 +08800913 +08b00a13 +f34fb0ef +3341a783 +0007c703 +06071863 +3301a783 +f40782e3 +0007c703 +00e787b3 +0007c703 +f2070ae3 +32f1a823 +00378793 +32f1aa23 +c3cfb0ef +05251663 +00148493 +0ff4f493 +fbdff06f +000097b7 +b947a903 +f55ff06f +00000593 +00090513 +09d020ef +bc0556e3 +016484b3 +0004a583 +000b8513 +7c0020ef +baa05ce3 +f79ff06f +00178793 +fb1ff06f +f7451ee3 +02049663 +3341a783 +00178793 +32f1aa23 +bf8fb0ef +b80518e3 +c1cfb0ef +02c00513 +b0dfb0ef +fe0516e3 +b7dff06f +fff48493 +f89ff06f +03650463 +01400713 +02e78733 +00000693 +00e98733 +fec74603 +fec70713 +09461063 +00068463 +42f18e23 +43c1cc03 +01400493 +fffc0c13 +029c04b3 +009984b3 +0004cb83 +0084ac83 +002b9b93 +017a8bb3 +000ba583 +000c8513 +5d1010ef +00050d13 +00aba023 +00000593 +000c8513 +70c020ef +04054463 +0044a583 +000d0513 +7c4020ef +04a04c63 +01400793 +02fc07b3 +00f987b3 +00c7a703 +32e1aa23 +0107a703 +d91ff06f +fff78793 +0ff7f793 +00100693 +f60796e3 +42018e23 +a11ff06f +00000593 +000c8513 +780020ef +00055a63 +0044a583 +000d0513 +6a8020ef +fa0558e3 +43818e23 +a96a0ce3 +02c00513 +a19fb0ef +9c0516e3 +a89ff06f +0c100513 +e01fc0ef +ac0fb0ef +fbf50493 +0ff4f713 +01900793 +c0e7e6e3 +3341a783 +02800513 +00178793 +32f1aa23 +dd9fc0ef +ae4fb0ef +0ff00793 +00050913 +bef504e3 +02900513 +dc1fc0ef +03d00513 +db9fc0ef +3341a703 +00349493 +58018793 +009787b3 +01278223 +00e7a023 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +cecfb06f +ab5fd0ef +fe0188a3 +9d9ff06f +01800513 +a41ff06f +00178793 +32f1a623 +821ff06f +00370793 +00000593 +0007c603 +02061263 +00a70733 +00100693 +00074503 +fe0512e3 +00068463 +32e1a423 +00400513 +a05ff06f +00178793 +01361663 +0015c593 +fcdff06f +fc0594e3 +fd0612e3 +00068463 +32e1a423 +32c18513 +32f1a623 +e08fe0ef +b00502e3 +32c1a783 +0007c783 +00078663 +02c00713 +aee798e3 +02c00513 +8d1fb0ef +f8051a63 +941ff06f +3201a623 +939ff06f +b08fe0ef +cd1fc0ef +00050493 +96cfb0ef +07b50793 +0ff7f793 +00100713 +00050913 +aaf76ae3 +3341a783 +0ff4f493 +00178793 +32f1aa23 +fff48493 +cf9fc0ef +0ff4f493 +00050413 +00049c63 +08600793 +aef91ae3 +becfb0ef +00040513 +b29ff06f +02c00513 +85dfb0ef +fc0518e3 +eb1ff06f +e0002703 +9e3787b7 +9b178793 +02f70733 +8081a783 +00e7c7b3 +80f1a423 +8adff06f +a7cfe0ef +00050493 +02c00513 +c1dfc0ef +a6cfe0ef +c35fc0ef +0ff57413 +00048513 +725020ef +00850023 +881ff06f +a50fe0ef +c19fc0ef +00050413 +02c00513 +bedfc0ef +a3cfe0ef +c05fc0ef +0ff57513 +0ff47413 +f0a40023 +855ff06f +925fd0ef +b59fe0ef +fe0188a3 +3201a823 +000087b7 +33c78793 +32f1aa23 +835ff06f +000114b7 +03010513 +e4048423 +a85fe0ef +00000613 +03010593 +e4848513 +0000a437 +cfcfd0ef +00040413 +00001937 +00044783 +00079863 +e4848513 +f54fd0ef +ff4ff06f +00040513 +74490593 +a31fb0ef +00a00513 +de0fc0ef +00044783 +00f40433 +fd1ff06f +0000f437 +00001a37 +bacfd0ef +11440413 +fdc18993 +00000493 +00200913 +00800b13 +00900b93 +fffa0a13 +00044783 +0a078063 +00000c13 +018407b3 +0007c503 +00051463 +02000513 +001c0c13 +de0fc0ef +ff6c14e3 +02000513 +dd4fc0ef +1f41c783 +fefbfae3 +00845503 +e58fc0ef +01c45503 +01a45783 +01051513 +00f56533 +02050663 +00000613 +03010593 +d40fb0ef +01000c13 +02000513 +d98fc0ef +1f41c783 +fefc7ae3 +03010513 +de8fc0ef +d3cfc0ef +00845783 +00148493 +0ff4f493 +014787b3 +40c7d793 +00f907b3 +01079913 +01095913 +f78fc0ef +01e40413 +f4899ce3 +00048513 +de4fc0ef +00100793 +06f49863 +00008537 +32c50513 +d9cfc0ef +1c000513 +41250533 +00251513 +01051513 +01055513 +db8fc0ef +00008537 +36050513 +d78fc0ef +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +c94fc06f +00008537 +33450513 +f95ff06f +03010513 +8d1fe0ef +a50fd0ef +03010513 +b90fb0ef +00055663 +00e00513 +ec8ff06f +01e00793 +02f50533 +0000f7b7 +10c78793 +01e00613 +00000593 +00850513 +00a78533 +459000ef +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +818fd06f +02810513 +851fe0ef +08800513 +969fc0ef +e29fa0ef +08200793 +00050493 +00f50a63 +04f50793 +0ff7f793 +00100713 +f6f76463 +3341a783 +00178793 +32f1aa23 +dfdfa0ef +04100793 +f4f51863 +3341a783 +05300713 +0017c683 +f4e69063 +00278793 +02300513 +32f1aa23 +d18fb0ef +f61fd0ef +929fc0ef +fff50793 +01079793 +0107d793 +00200713 +00f77663 +00a00513 +ddcff06f +12200713 +02e50733 +000117b7 +e4878513 +00e50533 +00054783 +00078663 +01400513 +db8ff06f +08200793 +00f49863 +02810593 +e40fd0ef +d34ff06f +f4e48613 +00163613 +02810593 +a10fd0ef +d20ff06f +d81fa0ef +04051863 +00011437 +00200913 +12200493 +e4840413 +02300513 +c88fb0ef +ed1fd0ef +899fc0ef +fff50793 +01079793 +0107d793 +f6f96ce3 +02950533 +00a40533 +c38fd0ef +02c00513 +c5cfb0ef +fc0516e3 +cccff06f +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +d64fd06f +00011937 +03010513 +e4090423 +ee0fe0ef +0af00793 +e4890993 +08f49063 +02c00513 +fecfc0ef +e3dfd0ef +301020ef +00050413 +02c00513 +fd8fc0ef +e29fd0ef +2ed020ef +00050493 +00000613 +03010593 +e4890513 +928fd0ef +00000993 +02000a13 +013455b3 +0ff5f593 +e4890513 +00898993 +89cfc0ef +ff4996e3 +009404b3 +00849663 +e4890513 +c15ff06f +00044583 +e4890513 +00140413 +878fc0ef +fe5ff06f +03010593 +e4890513 +cf4fd0ef +00000493 +00000413 +02000a13 +e4890513 +e39fb0ef +00951533 +00848493 +00a46433 +ff4496e3 +02c00513 +b48fb0ef +00050863 +d8dfd0ef +251020ef +00050413 +e4890513 +e09fb0ef +00055663 +00098023 +b9cff06f +0ff57513 +00a40023 +00140413 +fe1ff06f +f60000a3 +b84ff06f +d55fd0ef +219020ef +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +00050067 +c5dfa0ef +1c050c63 +03010513 +cf4fe0ef +03014703 +00012c23 +00011e23 +03200793 +daf716e3 +03114703 +03000793 +daf710e3 +000099b7 +98898993 +00000493 +03210413 +0ff4f913 +14048463 +00044703 +ffd90793 +0fd7f793 +00e7e7b3 +08078e63 +fff9c783 +d6e796e3 +00200793 +00140413 +12f49063 +01814503 +01914583 +7d050513 +a85fa0ef +00044783 +00900613 +00040693 +fd078793 +0ff7f713 +d2e66ce3 +00144703 +fd070713 +0ff77593 +d2b664e3 +00a00613 +02c787b3 +fff90913 +00293913 +00e787b3 +01079793 +0107d793 +d127e4e3 +d0f562e3 +01810713 +00970733 +00f70023 +00148493 +00600793 +00240413 +00198993 +f4f49ce3 +0026c783 +cc079ee3 +01a14403 +01814903 +7d000493 +fff40413 +03048793 +0ff7f793 +0927ea63 +01914983 +00100493 +7d090913 +0b34e263 +e0002703 +000147b7 +fee7ae23 +01b14783 +03c00713 +02e787b3 +01c14703 +00e787b3 +01079793 +03c00713 +0107d793 +02e787b3 +01d14703 +00e787b3 +00015737 +18070713 +02e40433 +00014737 +ff870713 +008787b3 +00f72023 +00072783 +00078463 +9c0ff06f +00100793 +00f72023 +9b4ff06f +000097b7 +99078793 +00f487b3 +0007c503 +ee5ff06f +00048513 +929fa0ef +00148493 +16d50513 +01049493 +00a40433 +0104d493 +f49ff06f +00048593 +00090513 +939fa0ef +00148493 +00a40433 +0ff4f493 +f45ff06f +f09fa0ef +00100613 +03010593 +f49fa0ef +03014783 +03010513 +a80794e3 +00008537 +34050513 +a7dff06f +a0cfd0ef +a55fa0ef +00050463 +c38fe0ef +dd9fa0ef +0000a7b7 +00078793 +0000a737 +00370713 +32f1a823 +0007c783 +32e1aa23 +00100613 +fec18823 +00079a63 +000087b7 +33c78793 +3201a823 +32f1aa23 +00100713 +fee188a3 +929fa0ef +fd050513 +0ff57513 +00900793 +00a7f463 +8d0ff06f +ad4ff06f +90dfa0ef +fd050513 +0ff57513 +00900793 +08a7e663 +cb0fc0ef +00050413 +00050493 +02d00513 +82cfb0ef +02050063 +8e1fa0ef +fd050513 +0ff57513 +00900793 +06a7e863 +c84fc0ef +00050413 +00048513 +88dfa0ef +00050493 +00001937 +0004c783 +00079463 +868ff06f +0024c783 +0014c703 +00879793 +00e7e7b3 +00f47463 +850ff06f +00048513 +79c90593 +a8cfb0ef +e51fb0ef +8acfc0ef +0004c783 +00f484b3 +fc1ff06f +00010437 +fff40413 +00000493 +f79ff06f +00010437 +fff40413 +f95ff06f +8e4fd0ef +0000a7b7 +00078793 +00011737 +00078023 +d4f72223 +ca9fa0ef +facff06f +00a00793 +80f19a23 +80f19b23 +849fa0ef +02051063 +bd8fc0ef +80a19b23 +02c00513 +f59fa0ef +00050663 +bc4fc0ef +80a19a23 +8141db83 +a40b86e3 +00011cb7 +c65fa0ef +d44ca903 +8161dc03 +00190913 +0000ab37 +8121a823 +000c0493 +000b0993 +00900d13 +0009c783 +04079263 +00000513 +c90fc0ef +8101a483 +00090593 +000b0513 +412484b3 +01049493 +0104d493 +00048613 +534000ef +0000a7b7 +fff48493 +00078793 +009787b3 +d4fca223 +f04ff06f +9d84ece3 +00000513 +8101ad83 +c48fc0ef +0ff4f513 +c40fc0ef +0084d513 +c38fc0ef +00398793 +0007ca03 +00178693 +020a1263 +00000513 +c20fc0ef +8101a783 +0ff00713 +41b787b3 +14f75463 +00900513 +f6dfe06f +000a0513 +00d12623 +bfcfc0ef +07ca0793 +0ff7f793 +00200713 +00c12683 +02f76a63 +00100713 +0006c783 +02000613 +00168a13 +02c78863 +0e070863 +fd078793 +0ff7f793 +00fd6c63 +00068a13 +00000793 +0480006f +09800793 +fcfa06e3 +00068793 +f79ff06f +02000513 +00e12623 +b9cfc0ef +00c12703 +000a0693 +fb1ff06f +00a00713 +02e787b3 +00060a13 +fd078793 +00d787b3 +01079793 +0107d793 +000a4683 +001a0613 +fd068713 +0ff77713 +fced7ae3 +0000a737 +000c0513 +00070713 +00074603 +04061263 +00078513 +02010593 +810fb0ef +00000793 +07078713 +01010693 +00d70733 +fa074703 +f8070ae3 +00070513 +00f12623 +b1cfc0ef +00c12783 +00178793 +0ff7f793 +fd5ff06f +00274683 +00174583 +00869693 +00b6e6b3 +faf68ae3 +00ab8533 +01051513 +00c70733 +01055513 +f95ff06f +02c00713 +f2e798e3 +02c00513 +ad4fc0ef +00100713 +f39ff06f +00fd8023 +0009c783 +009b84b3 +01049493 +00f989b3 +0104d493 +e15ff06f +08200513 +d25fa0ef +0e050c63 +02300513 +d19fa0ef +0a050863 +04900513 +fb4fd0ef +00050493 +02c00513 +8f8fc0ef +00048513 +869fb0ef +00051463 +dd5fe06f +da8fa0ef +fbf50513 +0ff57513 +01900793 +00a7f463 +dd5fe06f +3341a783 +0017c703 +02400793 +00f70463 +dc1fe06f +0f418513 +3a4000ef +04f00793 +00a7f663 +0f418793 +040787a3 +8c9fd0ef +0f418593 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +3940006f +d20fa0ef +02200793 +02f51463 +03010513 +bd9fd0ef +03010513 +b7dfb0ef +03b00513 +c45fa0ef +00051663 +02c00513 +830fc0ef +b90fc0ef +f40512e3 +da5fe06f +0a000513 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +c2cfe06f +32d1aa23 +0b812403 +0bc12083 +0b412483 +0b012903 +0ac12983 +0a812a03 +0a412a83 +0a012b03 +09c12b83 +09812c03 +09412c83 +09012d03 +08c12d83 +0c010113 +97cfe06f +fd010113 +02112623 +02812423 +02912223 +03212023 +01312e23 +01412c23 +01512a23 +01612823 +01712623 +01812423 +000147b7 +fe07ac23 +0000a7b7 +00078793 +00011737 +00078023 +d4f72223 +889fa0ef +f2000a23 +f3404783 +0017f793 +fe079ce3 +9d5fb0ef +00008537 +36850513 +a71fb0ef +9c5fb0ef +1f818513 +5dd000ef +00050a63 +fe0188a3 +32018c23 +42018e23 +3201a823 +02000493 +00a00a13 +00000a93 +ff11c783 +06078663 +00900b13 +a60fc0ef +fe050ee3 +0f418513 +00054783 +06978663 +fe0786e3 +fd078793 +0ff7f793 +0afb7263 +c09fa0ef +ff418793 +32f1aa23 +00100793 +3201a823 +fef188a3 +ff11c783 +00078c63 +ba9fb0ef +fe018823 +8f1fe0ef +ff11c783 +08079063 +fe0188a3 +3201a823 +f95ff06f +929fb0ef +00008537 +39450513 +9c5fb0ef +919fb0ef +f85ff06f +00150513 +f8dff06f +03440433 +00150513 +fd040413 +00e40433 +01041413 +01045413 +00054703 +fd070793 +0ff7f793 +fcfb7ee3 +00054783 +00978e63 +b79fa0ef +00040513 +83cfc0ef +f41ff06f +000a8413 +fd5ff06f +00150513 +fddff06f +ff01c783 +f60792e3 +03a00513 +a25fa0ef +f4051ce3 +ad8fa0ef +00050663 +00000513 +9bdfb0ef +3301a783 +f4078ee3 +0007c703 +00e787b3 +0007c703 +32f1a823 +00071663 +b3dfc0ef +f41ff06f +00378793 +32f1aa23 +f19ff06f +00000793 +00f61463 +00008067 +00f58733 +00074683 +00f50733 +00178793 +00d70023 +fe5ff06f +02b56a63 +fff64693 +00000793 +fff78793 +02d79663 +00008067 +00f58733 +00074683 +00f50733 +00178793 +00d70023 +fef616e3 +00008067 +00000793 +ff5ff06f +00f60733 +00e58833 +00084803 +00e50733 +01070023 +fbdff06f +00c50633 +00050793 +00c79463 +00008067 +00178793 +feb78fa3 +ff1ff06f +00000713 +00e61663 +00000513 +00008067 +00e507b3 +00170713 +00e586b3 +0007c783 +fff6c683 +fed780e3 +40d78533 +00008067 +00050793 +0007c703 +00071663 +40a78533 +00008067 +00178793 +fedff06f +00054783 +00078663 +0005c703 +00f70863 +0005c503 +40a78533 +00008067 +00150513 +00158593 +fddff06f +00050793 +0005c703 +00158593 +00178793 +fee78fa3 +fe0718e3 +00008067 +fe010113 +00112e23 +00812c23 +00b12623 +00050413 +f8dff0ef +00c12583 +00a40533 +fc5ff0ef +01c12083 +00040513 +01812403 +02010113 +00008067 +fe010113 +000097b7 +01312623 +00058993 +bbc7a583 +00112e23 +00812c23 +01212823 +00912a23 +00050913 +66c010ef +769010ef +00157793 +00050413 +00078463 +00150413 +00040513 +7c5010ef +000097b7 +bc07a583 +00747413 +0089a023 +00050493 +638010ef +00050593 +00090513 +20d010ef +000097b7 +bc47a583 +00050413 +00048513 +618010ef +00050593 +00040513 +1ed010ef +000097b7 +bc87a583 +00050413 +00048513 +5f8010ef +00050593 +00040513 +1cd010ef +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +ff010113 +00050593 +00112623 +00812423 +00912223 +5b8010ef +000097b7 +bcc7a583 +00050413 +5a8010ef +000097b7 +bd07a583 +17d010ef +00040593 +594010ef +000097b7 +bd47a583 +2a1000ef +00040593 +580010ef +00040593 +578010ef +000097b7 +b9c7a583 +00050493 +00040513 +564010ef +00050593 +00048513 +139010ef +000097b7 +b947a583 +265000ef +00c12083 +00812403 +00412483 +01010113 +00008067 +fe010113 +00000593 +00812c23 +00912a23 +00112e23 +01212823 +00050413 +448010ef +01f55493 +00055663 +800007b7 +0087c433 +00040513 +00c10593 +e69ff0ef +00c12783 +00300713 +00050413 +00f75863 +ffc78793 +0014c493 +00f12623 +00c12783 +00100713 +fff78793 +02f76863 +00040513 +efdff0ef +00048663 +800007b7 +00a7c533 +01c12083 +01812403 +01412483 +01012903 +02010113 +00008067 +00040593 +00040513 +498010ef +000097b7 +bd87a583 +00050913 +488010ef +000097b7 +bdc7a583 +195000ef +00090593 +474010ef +000097b7 +be07a583 +049010ef +00090593 +460010ef +00040593 +458010ef +00040593 +169000ef +f89ff06f +fe010113 +00000593 +00812c23 +00112e23 +00912a23 +01212823 +00050413 +35c010ef +00055663 +800007b7 +0087c433 +00040513 +00c10593 +d81ff0ef +00c12783 +00300713 +00050413 +00000493 +00f75863 +ffc78793 +00f12623 +00100493 +00c12783 +00100713 +00f75463 +0014c493 +fff78793 +00100713 +06f76e63 +00040593 +00040513 +3cc010ef +000097b7 +bd87a583 +00050913 +3bc010ef +000097b7 +bdc7a583 +0c9000ef +00090593 +3a8010ef +000097b7 +be07a583 +77c010ef +00090593 +394010ef +00040593 +38c010ef +00040593 +09d000ef +00048663 +800007b7 +00a7c533 +01c12083 +01812403 +01412483 +01012903 +02010113 +00008067 +00040513 +d8dff0ef +fd5ff06f +fe010113 +00000593 +00912a23 +01212823 +00112e23 +00050913 +00812c23 +264010ef +00090493 +00055663 +800004b7 +0124c4b3 +00c10593 +00048513 +c85ff0ef +000097b7 +be47a583 +00050413 +00048513 +16c010ef +08a05e63 +00040593 +00040513 +2f4010ef +000097b7 +be87a583 +00050493 +2e4010ef +000097b7 +bec7a583 +7f0000ef +00048593 +2d0010ef +000097b7 +bf07a583 +7dc000ef +00048593 +2bc010ef +000097b7 +bf47a583 +7c8000ef +00048593 +2a8010ef +000097b7 +bf87a583 +7b4000ef +00048593 +294010ef +000097b7 +bfc7a583 +7a0000ef +00048593 +280010ef +00040593 +278010ef +00050593 +00040513 +784000ef +00050413 +00c12783 +0027f793 +00078c63 +000097b7 +ba87a503 +00040593 +43d000ef +00050413 +00000593 +00090513 +16c010ef +00055663 +800007b7 +0087c433 +01c12083 +00040513 +01812403 +01412483 +01012903 +02010113 +00008067 +fe010113 +00000593 +00812c23 +00912a23 +00112e23 +00050493 +01212823 +01312623 +120010ef +00048413 +00055663 +80000437 +00944433 +000097b7 +c087a583 +00040513 +038010ef +0ca05663 +000097b7 +ba87a503 +00040593 +3ad000ef +000097b7 +c007a983 +00050413 +00040593 +00040513 +1a4010ef +000097b7 +c107a583 +00050913 +194010ef +000097b7 +c147a583 +568010ef +00090593 +180010ef +000097b7 +c187a583 +68c000ef +00090593 +16c010ef +000097b7 +c1c7a583 +540010ef +00090593 +158010ef +00040593 +150010ef +00040593 +660000ef +00098593 +658000ef +00050413 +00000593 +00048513 +060010ef +00055663 +800007b7 +0087c433 +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +000097b7 +c0c7a583 +00040513 +00000993 +759000ef +f4a050e3 +000099b7 +b949a583 +00040513 +4bc010ef +b949a583 +00050913 +00040513 +5e4000ef +00050593 +00090513 +2b1000ef +000097b7 +c047a983 +00050413 +f05ff06f +fe010113 +00000593 +00812c23 +00112e23 +00912a23 +01212823 +01312623 +00050413 +7bd000ef +04a04663 +00000593 +00040513 +671000ef +20050063 +00040593 +00040513 +44c010ef +00050593 +255000ef +00050413 +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +7f800737 +00040793 +fce47ce3 +008006b7 +00000713 +00d47e63 +000097b7 +c247a583 +00040513 +018010ef +00050793 +fe800713 +00979413 +0177d493 +00945413 +3f0007b7 +00f46433 +000097b7 +c287a583 +f8248493 +00040513 +00e484b3 +715000ef +00009937 +14055c63 +00040593 +00040513 +4e8000ef +b9492583 +fff48493 +3a4010ef +00050593 +00050413 +7b9000ef +000097b7 +c2c7a583 +00050993 +00040513 +7a5000ef +000097b7 +c307a583 +378010ef +00040593 +791000ef +000097b7 +c347a583 +49c000ef +00040593 +77d000ef +000097b7 +c387a583 +350010ef +00040593 +769000ef +000097b7 +c3c7a583 +474000ef +00040593 +755000ef +000097b7 +c407a583 +328010ef +00040593 +741000ef +000097b7 +c447a583 +44c000ef +00040593 +72d000ef +000097b7 +c487a583 +300010ef +00040593 +719000ef +000097b7 +c4c7a583 +424000ef +00040593 +705000ef +00098593 +6fd000ef +00050913 +00048513 +065010ef +000097b7 +c507a583 +00050493 +6e1000ef +00090593 +3f0000ef +000097b7 +c547a583 +00050913 +00098513 +6c5000ef +00090593 +3d4000ef +000097b7 +c587a583 +00050913 +00048513 +6a9000ef +00050493 +00090593 +00040513 +3b0000ef +00050593 +00048513 +3a4000ef +e29ff06f +b9492583 +00040513 +eb9ff06f +000097b7 +c207a403 +e15ff06f +00050593 +02a04663 +00151793 +0c078863 +ff010113 +00112623 +234010ef +00050593 +03d000ef +00c12083 +01010113 +00008067 +7f8007b7 +00050713 +0af55263 +41755793 +00079e63 +00171713 +00871613 +00078693 +00178793 +fe0658e3 +40d007b3 +008006b7 +fff68613 +f8178793 +00c77733 +00d76733 +0017f693 +00068463 +00171713 +4017d593 +00171713 +01900513 +01000637 +00000893 +00000793 +00c88833 +00070693 +01076863 +00c808b3 +410706b3 +00c787b3 +fff50513 +00169713 +00165613 +fc051ee3 +00068663 +00178793 +ffe7f793 +01759593 +3f000737 +00e585b3 +0017d793 +00f585b3 +00058513 +00008067 +01755693 +0ff6f693 +f8168693 +01600713 +00050793 +04d74463 +0206c663 +00800737 +fff70713 +40d75733 +00a776b3 +02068863 +00055463 +00e507b3 +fff74713 +00f77533 +00008067 +00000513 +0007da63 +00179793 +bf800537 +00079463 +80000537 +00008067 +000097b7 +c607a583 +fe010113 +00812c23 +00112e23 +00912a23 +01212823 +01312623 +00050413 +36d000ef +18a04463 +000097b7 +c647a583 +00040513 +421000ef +00050793 +00000513 +1207c863 +000097b7 +c687a583 +00040513 +000099b7 +4d1000ef +b9c9a583 +1e0000ef +f3dff0ef +000097b7 +c587a583 +00050913 +4b5000ef +00050593 +00040513 +088010ef +000097b7 +c6c7a583 +00050413 +00090513 +495000ef +00040593 +1a4000ef +00050493 +00090513 +580010ef +000097b7 +c707a583 +00050413 +00048513 +46d000ef +000097b7 +c747a583 +178000ef +00048593 +459000ef +000097b7 +c787a583 +164000ef +00048593 +445000ef +000097b7 +c7c7a583 +150000ef +00048593 +431000ef +000097b7 +c807a583 +13c000ef +00048593 +41d000ef +b9c9a583 +12c000ef +00050913 +00048593 +00048513 +405000ef +00050593 +00090513 +3f9000ef +00048593 +108000ef +000097b7 +b947a583 +07f00493 +0f8000ef +000097b7 +c847a903 +0284ce63 +000097b7 +c887a903 +f8200493 +02944e63 +07f40593 +01759593 +3b9000ef +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00090593 +395000ef +f8140413 +fb9ff06f +00090593 +385000ef +07e40413 +fb9ff06f +000097b7 +c5c7a503 +fbdff06f +00152023 +00252223 +00852423 +00952623 +01252823 +01352a23 +01452c23 +01552e23 +03652023 +03752223 +03852423 +03952623 +03a52823 +03b52a23 +00000513 +00008067 +00052083 +00452103 +00852403 +00c52483 +01052903 +01452983 +01852a03 +01c52a83 +02052b03 +02452b83 +02852c03 +02c52c83 +03052d03 +03452d83 +0015b513 +00b50533 +00008067 +008007b7 +ff010113 +01755693 +0175d713 +fff78793 +00a7f633 +0ff77813 +00812423 +01212023 +01f55413 +0ff6f913 +00b7f533 +00112623 +01f5d593 +00060693 +00040893 +00361713 +00351e13 +41090333 +04b40863 +02605263 +06081863 +1e0e0463 +fff30793 +3c078e63 +0ff00693 +1ed30463 +00078313 +0640006f +14030463 +41280333 +28091263 +1a070c63 +fff30793 +3e078263 +0ff00693 +3ad30063 +00078313 +2780006f +1e605063 +16080463 +0ff00793 +1af90463 +040007b7 +00fe6e33 +01b00793 +2a67da63 +00170713 +0900006f +0ff00793 +18f90463 +040007b7 +00fe6e33 +01b00693 +00100793 +0066ce63 +02000793 +406787b3 +00fe17b3 +006e56b3 +00f037b3 +00f6e7b3 +40f70733 +00571793 +1607d863 +00912223 +040004b7 +fff48493 +009774b3 +00048513 +574010ef +ffb50513 +00a494b3 +19254063 +41250533 +00150513 +02000713 +40a70733 +00e49733 +00e03733 +00a4d4b3 +00e4e733 +00412483 +00000913 +00777793 +00078a63 +00f77793 +00400613 +00c78463 +00470713 +00571793 +0c07dc63 +00190793 +0ff00693 +00040893 +0ed78463 +fc0006b7 +fff68693 +00d776b3 +0ff7f513 +00669693 +0096d693 +00c12083 +00812403 +01751513 +00d56533 +01f89793 +00012903 +00f56533 +01010113 +00008067 +00190613 +0fe67613 +18061063 +06091063 +2a070863 +00000513 +fc0e02e3 +41c706b3 +00569613 +2a065e63 +40ee06b3 +00569713 +2c075863 +fc0007b7 +fff78793 +00f6f6b3 +00058893 +00100513 +f8dff06f +020e0c63 +fff30793 +1e078a63 +0ff00693 +02d30c63 +00078313 +e95ff06f +20070863 +00000893 +0ff00513 +004006b7 +f65ff06f +00058413 +000e0713 +00030913 +0ff00793 +00375613 +1cf91863 +fc061ce3 +00040893 +0ff00513 +00000693 +f39ff06f +0ff00513 +00000693 +f2dff06f +00777793 +ee0792e3 +fcdff06f +04030063 +41280333 +12091c63 +fa070ae3 +fff30793 +16078a63 +0ff00693 +18d30e63 +00078313 +12c0006f +fc000737 +fff70713 +00e4f733 +40a90933 +00412483 +e99ff06f +00190613 +0fe67593 +10059e63 +f4091ee3 +1c070263 +00000513 +ec0e02e3 +01c70e33 +005e1713 +003e5693 +1c075063 +1f800737 +fff70713 +00e6f6b3 +00f6f6b3 +00100513 +e9dff06f +0ff00793 +12f80663 +040007b7 +00f76733 +01b00693 +00100793 +0066ce63 +02000793 +406787b3 +00f717b3 +00f037b3 +00675733 +00f767b3 +40fe0733 +00080913 +00058413 +dbdff06f +00912223 +41c704b3 +00549793 +0a07c463 +dc0490e3 +00412483 +00000893 +00000513 +00000693 +e31ff06f +02000793 +406787b3 +00fe17b3 +006e5333 +00f037b3 +00f36333 +00670733 +00571793 +ee07d2e3 +00190913 +0ff00513 +00000693 +dea90ee3 +7e0006b7 +00175793 +fff68693 +00177713 +00d7f7b3 +00e7e733 +d99ff06f +0ff00793 +06f80a63 +040007b7 +00f76733 +01b00793 +0667dc63 +001e0713 +00080913 +d75ff06f +0ff00793 +e8f600e3 +01c70e33 +001e5713 +00060913 +d5dff06f +40ee04b3 +00058413 +d15ff06f +01c70733 +00571793 +00200913 +f807c8e3 +00375613 +00100913 +00961613 +00965693 +0ff97513 +00040893 +d6dff06f +00058413 +00050613 +e19ff06f +41c70733 +00100913 +cb9ff06f +02000793 +406787b3 +00f717b3 +00675333 +00f037b3 +00f36333 +01c30733 +00080913 +f21ff06f +40ee0733 +00058413 +00100913 +c85ff06f +020e0863 +00050693 +00058893 +00000513 +d0dff06f +00050693 +00000513 +d01ff06f +02068863 +0036d693 +00f6f6b3 +cf1ff06f +00000893 +00000513 +00000693 +ce1ff06f +0036d693 +00f6f6b3 +00058893 +cd1ff06f +00000893 +00000693 +cc5ff06f +fd010113 +01755793 +01312e23 +01512a23 +02112623 +00951a93 +02812423 +02912223 +03212023 +01412c23 +01612823 +0ff7f793 +009ada93 +01f55993 +12078863 +0ff00713 +06e78c63 +003a9a93 +04000737 +00eaeab3 +f8178a13 +00000493 +00000b13 +0175d793 +00959413 +0ff7f793 +00945413 +01f5d913 +06078863 +0ff00713 +10e78263 +00341413 +04000737 +00e46433 +f8178793 +00000613 +00f00693 +0129c733 +40fa0a33 +2696ee63 +000097b7 +c8c78793 +00249493 +00f484b3 +0004a783 +00078067 +140a9863 +0175d793 +00959413 +0ff7f793 +00800493 +0ff00a13 +00200b13 +00945413 +01f5d913 +f8079ce3 +0c041663 +0014e493 +00d00793 +0129c733 +0097ee63 +000097b7 +ccc78793 +00249493 +00f484b3 +0004a783 +00078067 +0ff00793 +00000693 +02c12083 +02812403 +01779513 +00d56533 +01f71713 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +00e56533 +03010113 +00008067 +00300793 +00090513 +0ef61a63 +00000713 +0ff00793 +004006b7 +fb1ff06f +060a9a63 +00400493 +00000a13 +00100b13 +ee5ff06f +04041863 +0024e493 +ffd48493 +00b00793 +0129c733 +0897e463 +000097b7 +d0478793 +00249493 +00f484b3 +0004a783 +00078067 +00040513 +004010ef +ffb50793 +00f41433 +f8a00793 +40a787b3 +00000613 +ec9ff06f +0034e493 +0ff00793 +00300613 +eb9ff06f +000a8513 +00b12623 +7d1000ef +ffb50793 +00fa9ab3 +f8a00793 +00c12583 +40a78a33 +00000493 +00000b13 +e59ff06f +00c00493 +0ff00a13 +00300b13 +e49ff06f +00000793 +00000693 +ef5ff06f +f01a0a13 +00200793 +00098513 +06fb1663 +00050713 +0ff00793 +00000693 +ed5ff06f +000a8413 +00050713 +07fa0793 +06f05663 +00747693 +00068a63 +00f47693 +00400613 +00c68463 +00440413 +00441693 +0006da63 +f80007b7 +fff78793 +00f47433 +080a0793 +0fe00693 +e8f6c2e3 +00641693 +0096d693 +0ff7f793 +e7dff06f +00300793 +eafb0ce3 +00100793 +f8fb1ee3 +00050713 +00000793 +00000693 +e5dff06f +00100613 +00078c63 +40f60633 +01b00593 +00000793 +00000693 +e4c5c0e3 +09ea0793 +00f417b3 +00f037b3 +00c45433 +00f46433 +00747793 +00078a63 +00f47793 +00400693 +00d78463 +00440413 +00541793 +0e07d263 +00100793 +00000693 +e01ff06f +000106b7 +00541513 +fe068693 +01055613 +00d576b3 +088af863 +02cad433 +000a8793 +fffa0a13 +00000a93 +02d405b3 +02c7f7b3 +01079793 +0157e7b3 +00b7fa63 +00f507b3 +fff40813 +08a7f063 +00080413 +40b787b3 +02c7d5b3 +02c7f7b3 +02d586b3 +01079793 +02d7f663 +00a78633 +00f63833 +fff58893 +00060793 +00081a63 +00d67863 +ffe58593 +00a607b3 +0080006f +00088593 +01041413 +40d787b3 +00b46433 +00f037b3 +00f46433 +e95ff06f +001ad793 +02c7d433 +01fa9a93 +010ada93 +02d405b3 +f75ff06f +00090513 +ed5ff06f +f8b7f2e3 +ffe40413 +00a787b3 +f7dff06f +00641413 +00945693 +00000793 +d1dff06f +00090513 +e35ff06f +01755693 +00800737 +fff70713 +0175d613 +0ff6f693 +0ff00813 +00a778b3 +01f55793 +00b77733 +0ff67613 +01f5d593 +00100513 +03068863 +01060863 +00c69463 +00e88663 +00008067 +00008067 +00000513 +feb78ae3 +00100513 +fe0696e3 +01103533 +00008067 +fed610e3 +00e8e8b3 +fc089ce3 +00b7c533 +00008067 +01755613 +00800737 +fff70713 +0175d693 +0ff67613 +0ff00813 +00a778b3 +01f55793 +00b77733 +0ff6f513 +01f5d593 +05060063 +03050063 +04061863 +02051063 +06070a63 +08089063 +00100513 +06058063 +00008067 +06071463 +00061463 +fe0886e3 +04b78263 +04079463 +00100513 +00008067 +04089663 +fec518e3 +04071263 +feb794e3 +00000513 +00008067 +fc050ee3 +fcb79ce3 +fcc54ae3 +00a64863 +fd1766e3 +00000513 +fae8f8e3 +00100513 +fa0794e3 +fff00513 +00008067 +fa0898e3 +00008067 +ffe00513 +00008067 +fcb78ae3 +f9dff06f +01755613 +00800737 +fff70713 +0175d693 +0ff67613 +0ff00813 +00a778b3 +01f55793 +00b77733 +0ff6f513 +01f5d593 +05060263 +03050063 +04061c63 +02051263 +06070e63 +08089463 +00100513 +06058463 +00008067 +00200513 +fe071ce3 +00061463 +fe0884e3 +04b78463 +04079663 +00100513 +00008067 +04089863 +fec518e3 +00200513 +fc0718e3 +feb792e3 +00000513 +00008067 +fc050ce3 +fcb79ae3 +fcc548e3 +00a64863 +fd1764e3 +00000513 +fae8f4e3 +00100513 +fa0790e3 +fff00513 +00008067 +fa0896e3 +00008067 +00200513 +00008067 +fcb78ae3 +f99ff06f +fd010113 +01755793 +03212023 +01412c23 +02112623 +00951a13 +02812423 +02912223 +01312e23 +01512a23 +01612823 +0ff7f793 +009a5a13 +01f55913 +24078063 +0ff00713 +16e78663 +003a1a13 +04000737 +00ea6a33 +f8178993 +00000493 +00000b13 +0175d793 +00959a93 +0ff7f793 +009ada93 +01f5d413 +16078263 +0ff00713 +1ce78a63 +003a9a93 +f8178793 +04000737 +00eaeab3 +00f989b3 +00000593 +00a00793 +00198613 +1497c863 +00894533 +00200793 +00050693 +1e97d863 +00100713 +00971733 +53077793 +12079a63 +24077793 +26079863 +08877713 +24071c63 +000108b7 +fff88793 +010a5593 +010ad813 +00fa7a33 +00faf7b3 +03478533 +02f587b3 +01055713 +03480a33 +00fa0a33 +01470733 +030585b3 +00f77463 +011585b3 +00010837 +fff80813 +010777b3 +01079793 +01057533 +00a787b3 +01075713 +00679a13 +00b70733 +01a7d793 +00671713 +01403a33 +00fa6a33 +00471793 +01476a33 +0007da63 +001a5793 +001a7a13 +0147ea33 +00060993 +07f98793 +1ef05263 +007a7713 +00070a63 +00fa7713 +00400613 +00c70463 +004a0a13 +004a1713 +00075a63 +f80007b7 +fff78793 +00fa7a33 +08098793 +0fe00713 +22f74663 +006a1713 +00975713 +0ff7f793 +06c0006f +160a1463 +0175d793 +00959a93 +0ff7f793 +00800493 +0ff00993 +00200b13 +009ada93 +01f5d413 +ea0792e3 +100a9863 +0014e493 +00a00793 +00100593 +00198613 +ea97dce3 +00090513 +00200793 +08fb0c63 +00300793 +12fb0c63 +00100793 +00050693 +1afb1a63 +00000793 +00000713 +02c12083 +02812403 +01779513 +00e56533 +01f69793 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +00f56533 +03010113 +00008067 +0ff98713 +0a0a8a63 +0034e493 +00a00693 +10098613 +1496c063 +008946b3 +00068513 +00070993 +00300593 +e3dff06f +040a1063 +00400493 +00000993 +00100b13 +dd5ff06f +00050693 +0ff00793 +00000713 +f7dff06f +fff48493 +00100713 +e29766e3 +fef582e3 +000a8a13 +00058b13 +f4dff06f +000a0513 +00b12623 +0e5000ef +ffb50793 +00fa1a33 +f8a00793 +00c12583 +40a789b3 +00000493 +00000b13 +d7dff06f +000a8513 +0bd000ef +ffb50793 +40a98533 +00fa9ab3 +f8a50993 +00000593 +d95ff06f +0024e493 +00070993 +00200593 +d85ff06f +00c00493 +0ff00993 +00300b13 +d3dff06f +000a8a13 +00058b13 +00040513 +ec1ff06f +00000693 +0ff00793 +00400737 +ed5ff06f +00100613 +00078c63 +40f60633 +01b00593 +00000793 +00000713 +eac5cce3 +09e98713 +00ea1733 +00e03733 +00ca57b3 +00e7e7b3 +0077f713 +00070a63 +00f7f713 +00400613 +00c70463 +00478793 +00579713 +04075063 +00100793 +00000713 +e79ff06f +00f00593 +00000693 +00400737 +000a8a13 +00300b13 +e6b480e3 +f75ff06f +00060993 +d9dff06f +0ff00793 +00000713 +e49ff06f +00679793 +0097d713 +00000793 +e39ff06f +008007b7 +ff010113 +fff78793 +0175d693 +00a7f833 +00b7f733 +00812423 +00912223 +01755413 +01f55493 +00112623 +0ff6f693 +0ff00513 +00080613 +0ff47413 +00048313 +00381793 +01f5d593 +00371e13 +04a68a63 +0015c893 +40d405b3 +03148263 +48b05263 +06069663 +1c0e0c63 +fff58713 +3c070c63 +1ca58e63 +00070593 +0600006f +48b05263 +18068e63 +1ca40463 +04000737 +00ee6e33 +01b00713 +2cb75c63 +00178793 +0b80006f +f0140513 +100e1e63 +0015c893 +29148063 +1a050e63 +00088493 +10040c63 +0014f313 +0ff00513 +00000613 +0d40006f +18a40063 +04000737 +00ee6e33 +01b00693 +00100713 +00b6ce63 +02000713 +40b70733 +00ee1733 +00be56b3 +00e03733 +00e6e733 +40e787b3 +00579713 +14075e63 +01212023 +04000937 +fff90913 +0127f933 +00090513 +6a8000ef +ffb50513 +00a91933 +18854863 +40850533 +00150513 +02000793 +40a787b3 +00f917b3 +00f037b3 +00a95933 +00f967b3 +00012903 +00000413 +0077f713 +00070a63 +00f7f713 +00400693 +00d70463 +00478793 +00579713 +0c075863 +00140413 +0ff00713 +f4e400e3 +fc000637 +fff60613 +00c7f633 +0ff47513 +00661613 +00965613 +0014f313 +00c12083 +00812403 +01751513 +00c56533 +01f31793 +00412483 +00f56533 +01010113 +00008067 +00058893 +12b48a63 +0a050263 +20041263 +0ff00593 +06078063 +fff58613 +28060c63 +0ff00513 +00088493 +24a58a63 +01b00593 +00100713 +00c5ce63 +02000713 +40c70733 +00e79733 +00c7d633 +00e03733 +00e66733 +40ee07b3 +00068413 +ee9ff06f +020e0063 +fff58713 +1e070463 +02a58263 +00070593 +e61ff06f +00088493 +000e0793 +00058413 +0ff00713 +0037d813 +1ce41e63 +e60808e3 +00000313 +0ff00513 +00400637 +f41ff06f +0077f713 +ee071ce3 +fd9ff06f +00140693 +0fe6f693 +04069e63 +fc041ce3 +20078463 +00000513 +f00e0ce3 +41c78733 +00571693 +2206d263 +40fe0633 +00561793 +2207d463 +fc0007b7 +fff78793 +00f67633 +00088493 +00100513 +eddff06f +fc0007b7 +fff78793 +00f977b3 +40a40433 +00012903 +e89ff06f +01212023 +41c78933 +00591713 +12074263 +e2091ce3 +00012903 +00000313 +00000513 +00000613 +ea9ff06f +02050c63 +14041063 +0ff00593 +f2078ae3 +fff58613 +10060063 +0ff00513 +12a58463 +01b00713 +12c75a63 +001e0793 +00068413 +e2dff06f +08051c63 +00140693 +0fe6f593 +0a059863 +0e041e63 +14078c63 +00000513 +e40e0ae3 +01c78e33 +003e5793 +00979793 +005e1713 +0097d613 +e2075ee3 +00100513 +e35ff06f +02000713 +40b70733 +00ee1733 +00be55b3 +00e03733 +00e5e5b3 +00b787b3 +00579713 +ec075ae3 +00140413 +0ff00713 +00e41863 +0ff00513 +00000613 +df9ff06f +7e0006b7 +0017d713 +fff68693 +0017f793 +00d77733 +00f767b3 +d95ff06f +ce041ce3 +0ff00593 +f39ff06f +00058493 +00070813 +e75ff06f +00140693 +0fe6f593 +f4058ee3 +0ff00713 +fae688e3 +01c78e33 +001e5793 +00068413 +d59ff06f +40fe0933 +00088493 +d11ff06f +01c787b3 +00579713 +00200413 +f80748e3 +0037d813 +00100413 +00981813 +00985613 +0ff47513 +0014f313 +d69ff06f +e0079ce3 +00070813 +e0dff06f +41c787b3 +00100413 +cb5ff06f +02000713 +40c70733 +00e79733 +00c7d633 +00e037b3 +00f66633 +01c607b3 +00068413 +f19ff06f +40fe07b3 +00088493 +00100413 +c81ff06f +020e0063 +00088313 +00070613 +00000513 +d09ff06f +00070613 +00000513 +cfdff06f +00000313 +00000513 +00000613 +cedff06f +02070063 +00671713 +00975613 +cddff06f +00661613 +00088313 +00965613 +ccdff06f +00000313 +00000613 +cc1ff06f +d80586e3 +40868633 +00060593 +ce0404e3 +04000737 +00e7e7b3 +00088493 +cf1ff06f +ec058ee3 +40868633 +00041663 +00060593 +df5ff06f +04000737 +00e7e7b3 +dfdff06f +00800637 +01755713 +fff60793 +0ff77713 +07e00593 +00a7f6b3 +01f55793 +00e5de63 +09d00593 +00e5de63 +80000537 +fff50513 +00a78533 +00008067 +00000513 +00008067 +09500593 +00c6e6b3 +02e5c063 +09600613 +40e60733 +00e6d6b3 +40d00533 +fe0790e3 +00068513 +00008067 +f6a70713 +00e696b3 +fe9ff06f +ff010113 +00112623 +00812423 +00912223 +04050863 +41f55713 +00a74433 +40e40433 +00050793 +00040513 +01f7d493 +204000ef +09e00793 +40a787b3 +09600713 +04f74a63 +00800713 +0ce50263 +ff850513 +00a41433 +00941413 +00945413 +0ff7f793 +0100006f +00000493 +00000793 +00000413 +01779793 +00c12083 +0087e7b3 +00812403 +01f49513 +00a7e533 +00412483 +01010113 +00008067 +09900713 +04f74a63 +ffb50713 +00e41733 +fc0006b7 +fff68693 +00777613 +00d77433 +02060463 +00f77713 +00400613 +00c70e63 +00440413 +00541713 +00075863 +09f00793 +00d47433 +40a787b3 +00641413 +00945413 +0ff7f793 +f89ff06f +01b50713 +00500693 +00e41733 +40a686b3 +00d45433 +00e03733 +00e46733 +f9dff06f +00941413 +00945413 +09600793 +f59ff06f +ff010113 +00112623 +00812423 +04050863 +00050413 +104000ef +09e00793 +40a787b3 +09600713 +04f74c63 +00800713 +0ce50e63 +ff850513 +00a41433 +00941413 +0ff7f513 +00945413 +01751513 +00c12083 +00856533 +00812403 +01010113 +00008067 +00000513 +00000413 +01751513 +00c12083 +00856533 +00812403 +01010113 +00008067 +09900713 +06f74463 +ffb50713 +00e41733 +fc0006b7 +fff68693 +00777613 +00d77433 +02060463 +00f77713 +00400613 +00c70e63 +00440413 +00541713 +00075863 +09f00793 +00d47433 +40a787b3 +00641413 +0ff7f513 +00945413 +01751513 +00c12083 +00856533 +00812403 +01010113 +00008067 +01b50713 +00500693 +00e41733 +40a686b3 +00e03733 +00d45433 +00876733 +f89ff06f +00941413 +00945413 +09600513 +f51ff06f +000107b7 +02f57a63 +10053713 +00173713 +00371713 +000097b7 +00e55533 +d3478793 +00a787b3 +0007c503 +02000693 +40e686b3 +40a68533 +00008067 +010007b7 +02f57463 +01000713 +000097b7 +00e55533 +d3478793 +00a787b3 +0007c503 +01000693 +40a68533 +00008067 +01800713 +000097b7 +00e55533 +d3478793 +00a787b3 +0007c503 +00800693 +40a68533 +00008067 +00000020 +204e4920 +00000000 +0000435e +32534642 +00000000 +31534642 +00000000 +4c494620 +00202c45 +4c494620 +202c5345 +00000000 +45544144 +544f4e20 +54455320 +00000000 +0000203f +4445523f +0000004f +00203f3f +5246204b +00004545 +54524144 +54554f4d +54532d48 +20454c59 +49534142 +52202043 +2d435349 +4e4f2056 +42204120 +53595341 +00003320 +44414552 +00000059 +544e5953 +45205841 +524f5252 +00000000 +45444e55 +454e4946 +494c2044 +4e20454e +45424d55 +00000052 +55544552 +57204e52 +4f485449 +47205455 +4255534f +00000000 +5458454e +54495720 +54554f48 +524f4620 +00000000 +2054554f +4420464f +00415441 +53425553 +50495243 +554f2054 +464f2054 +4e415220 +00004547 +49564944 +4e4f4953 +20594220 +4f52455a +00000000 +2054554f +4d20464f +524f4d45 +00000059 +45505954 +53494d20 +4354414d +00000048 +49525453 +5420474e +4c204f4f +00474e4f +454c4c49 +204c4147 +434e5546 +4e4f4954 +4c414320 +0000004c +45444e55 +454e4946 +55462044 +4954434e +00004e4f +20524f46 +5453454e +54204445 +44204f4f +4c504545 +00000059 +55534f47 +454e2042 +44455453 +4f4f5420 +45454420 +00594c50 +454c4946 +544f4e20 +554f4620 +0000444e +4b534944 +4c554620 +0000004c +204f4f54 +594e414d +4c494620 +00005345 +20444142 +454c4946 +4d414e20 +00000045 +53414c46 +52452048 +00524f52 +454c4946 +4f4f5420 +47494220 +00000000 +454c4946 +524c4120 +59444145 +45504f20 +0000004e +454c4946 +544f4e20 +45504f20 +0000004e +55504e49 +41502054 +45205453 +0000444e +41455242 +0000004b +504f5453 +00000000 +0054454c +4e495250 +00000054 +55504e49 +00000054 +00004649 +4e454854 +00000000 +4f544f47 +00000000 +55534f47 +00000042 +55544552 +00004e52 +00524f46 +00004f54 +50455453 +00000000 +5458454e +00000000 +004d4944 +00464544 +00444e45 +004d4552 +44414552 +00000000 +41544144 +00000000 +54534552 +0045524f +444e4152 +5a494d4f +00000045 +454b4f50 +00000000 +0054554f +004e5552 +5453494c +00000000 +0057454e +41524353 +00484354 +00455942 +00534c43 +4f4c4f43 +00000052 +544f4c50 +00000000 +454e494c +00000000 +54434552 +00000000 +4c4c4946 +00000000 +43524943 +0000454c +41434f4c +00004554 +004b4e49 +45564153 +00000000 +44414f4c +00000000 +00524944 +004c4544 +45544144 +00000000 +4e45504f +00000000 +534f4c43 +00000045 +494e4f4d +00524f54 +4c4c4143 +00000000 +56415342 +00000045 +414f4c42 +00000044 +5054554f +00005455 +45505041 +0000444e +00444e41 +0000524f +00544f4e +004e4953 +00534f43 +004e4154 +004e5441 +00505845 +00474f4c +00534241 +00525153 +00544e49 +00444e52 +004e4753 +00004e46 +00424154 +4b454550 +00000000 +00504e49 +004e454c +004c4156 +00435341 +00464f45 +24524843 +00000000 +24525453 +00000000 +5446454c +00000024 +48474952 +00002454 +2444494d +00000000 +45544144 +00000024 +004d4954 +4e494f50 +00000054 +00003d3c +00003d3e +00003e3c +554e4552 +0000004d +000022d4 +000020a0 +000021a8 +000020a0 +000022dc +000020a0 +000020a0 +00002154 +000020a0 +0000216c +000020a0 +000020a0 +0000216c +000020a0 +000020a0 +000020a0 +000020a0 +000020a0 +000020a0 +000020a0 +0000220c +000022a0 +000022c4 +00002140 +000022dc +00002140 +000022d4 +00002140 +00002140 +00002140 +00002140 +00002140 +00002140 +00002140 +000022f0 +00002f50 +00002f5c +00002f68 +00002f74 +00002f80 +00002f8c +00002fb0 +00002fcc +00002fe8 +00002c88 +00002ff4 +00002c88 +00002c88 +0000301c +0000302c +00004160 +000041dc +00004214 +00004278 +000042f0 +0000437c +00004418 +000045b0 +00004630 +00005ce8 +0000489c +00004980 +00004ac4 +00005ce4 +00004b4c +00004b8c +00004bcc +00004c0c +00005ce4 +00005ce4 +00004874 +000047d4 +00004ec0 +00004f64 +00004f70 +00004afc +00004788 +00004afc +00005008 +00005010 +0000507c +0000509c +000050c8 +0000580c +0000587c +00005934 +00005934 +00004944 +00005ca8 +00005ca8 +00005ca8 +00005ba4 +00005ca8 +00005ca8 +00005ca8 +00005ca8 +00005ca8 +00005114 +000050f4 +00005174 +000052d0 +00005608 +00005350 +00005428 +000055bc +000055c4 +000054b8 +000054b8 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005ce4 +00005954 +3a202d2d +0000003a +171f0c63 +00003b3b +3dcccccd +3c23d70a +38d1b717 +322bcc77 +24e69595 +0a4fb11f +41200000 +42c80000 +461c4000 +4cbebc20 +5a0e1bca +749dc5ae +1e1f1c1f +1f1f1e1f +1f1e1f1e +0000839c +000083ac +000083c4 +000083dc +000083f0 +000083fc +00008414 +00008428 +00008438 +00008448 +00008458 +00008470 +00008484 +0000849c +000084b4 +000084c4 +000084d0 +000084e0 +000084f0 +000084fc +0000850c +00008520 +00008530 +00008540 +00008548 +00008550 +00008554 +0000855c +00008564 +00008568 +00008570 +00008578 +00008580 +00008588 +0000858c +00008590 +00008598 +000085a0 +000085a4 +000085a8 +00008548 +000085ac +000085b0 +000085b8 +000085c0 +00008480 +000085c8 +000085d4 +000085dc +000085e0 +000085e4 +000085ec +000085f0 +000085f8 +000085fc +00008600 +00008608 +00008610 +00008618 +00008620 +00008628 +00008630 +00008638 +0000863c +00008644 +0000864c +00008650 +00008654 +0000865c +00008664 +0000866c +00008674 +0000867c +00008684 +0000868c +00008694 +0000869c +000086a0 +000086a4 +000086a8 +000086ac +000086b0 +000086b4 +000086b8 +000086bc +000086c0 +000086c4 +000086c8 +000086cc +000086d0 +000086d4 +000086d8 +000086dc +000086e4 +000086e8 +000086ec +000086f0 +000086f4 +000086f8 +00008700 +00008708 +00008710 +00008718 +00008720 +00008728 +0000872c +00008734 +00008738 +0000873c +00008740 +497423f8 +41200000 +3f800000 +47c35000 +3f000000 +46fffe00 +c7000000 +bf800000 +33800000 +447a0000 +c2800000 +42800000 +3fa2f983 +3f490000 +397da000 +33222169 +37ccf5ce +3ab6061a +3d2aaaa5 +b94ca1f9 +3c08839e +3e2aaaa3 +38d1b717 +3c19c53b +3b4c779c +3cc821b5 +3d5ac5c9 +3e0896dd +3eaaaa6f +3fc90fdb +3f490fdb +401a827a +3ed413cd +3da4f0d1 +3e0e1b85 +3e4c925f +3eaaaa2a +ff800000 +4b800000 +3f3504f3 +3d9021bb +3debd1b8 +3def251a +3dfe5d4f +3e11e9bf +3e2aae50 +3e4cceac +3e7ffffc +3eaaaaaa +b95e8083 +bf000000 +3f318000 +7f800000 +42b17218 +c2ce8ed0 +3fb8aa3b +395e8083 +39506967 +3ab743ce +3c088908 +3d2aa9c1 +3e2aaaaa +7f000000 +00800000 +000073e8 +000071dc +000072e8 +0000721c +000072e8 +00007228 +000072e8 +0000721c +000071dc +000071dc +00007228 +0000721c +000072f8 +000072f8 +000072f8 +00007228 +000071dc +000071dc +000072e8 +000074a4 +000072e8 +00007228 +000072e8 +000074a4 +000071dc +000071dc +00007228 +000074a4 +000072f8 +000072f8 +000074cc +000072e8 +00007228 +000072e8 +000074cc +000071dc +000071dc +00007228 +000074cc +000072f4 +000072f4 +000072f4 +02020100 +03030303 +04040404 +04040404 +05050505 +05050505 +05050505 +05050505 +06060606 +06060606 +06060606 +06060606 +06060606 +06060606 +06060606 +06060606 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +07070707 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +08080808 +0000000f +ffffffff +00003039 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 diff --git a/basic/build.sh b/basic/build.sh new file mode 100755 index 0000000..9479ac0 --- /dev/null +++ b/basic/build.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Compile BASIC for RV32IM and write basic.bin and the RAM images basic.mem +# (0000-FFFF) and basic-hi.mem (10000-13FFF). +set -e +cd "$(dirname "$0")" +source ../scripts/rv_env.sh +mkdir -p out +CFLAGS="$RV_ARCH -Os -ffunction-sections -fdata-sections -fno-common -Wall -I../include" +${RV_PREFIX}gcc $CFLAGS -c -o out/crt0.o crt0.S +${RV_PREFIX}gcc $CFLAGS -c -o out/basic.o basic.c +${RV_PREFIX}gcc $CFLAGS -c -o out/string.o ../lib/string.c +${RV_PREFIX}gcc $CFLAGS -c -o out/mathf.o ../lib/mathf.c +${RV_PREFIX}gcc $CFLAGS -c -o out/setjmp.o ../lib/setjmp.S +${RV_PREFIX}gcc $RV_ARCH -nostdlib -nostartfiles -T basic.ld -Wl,--gc-sections -Wl,-Map,out/basic.map \ + -Wl,--build-id=none -o out/basic.elf out/crt0.o out/basic.o out/string.o out/mathf.o out/setjmp.o -lgcc +${RV_PREFIX}objcopy -O binary -j .text -j .data out/basic.elf basic.bin +${RV_PREFIX}nm -n out/basic.elf > out/basic.sym +python3 ../tools/bin2mem.py basic.bin out/basic-all.mem 20480 +head -n 16384 out/basic-all.mem > basic.mem +tail -n 4096 out/basic-all.mem > basic-hi.mem +${RV_PREFIX}size out/basic.elf diff --git a/basic/crt0.S b/basic/crt0.S new file mode 100644 index 0000000..8d44fbb --- /dev/null +++ b/basic/crt0.S @@ -0,0 +1,31 @@ +# Start-up for BASIC on the Basys 3 RISC-V computer: at the reset address 0. +# Copy the initialised data from ROM, clear the rest, point traps at the +# monitor and run main. +#include "basys3.h" + .section .text.start, "ax" + .globl _start +_start: + .option push + .option norelax + la gp, __global_pointer$ + .option pop + la sp, __stack_top + li t0, MON_TRAP # illegal instructions etc. stop in the monitor + csrw mtvec, t0 + la a0, __data_start # copy initialised data + la a1, __data_load + la a2, __data_end +1: bgeu a0, a2, 2f + lw t0, 0(a1) + sw t0, 0(a0) + addi a0, a0, 4 + addi a1, a1, 4 + j 1b +2: la a0, __bss_start # clear uninitialised data + la a2, __bss_end +3: bgeu a0, a2, 4f + sw zero, 0(a0) + addi a0, a0, 4 + j 3b +4: call main +5: j 5b diff --git a/basic/examples/graphics-demo.bas b/basic/examples/graphics-demo.bas new file mode 100644 index 0000000..351abfc --- /dev/null +++ b/basic/examples/graphics-demo.bas @@ -0,0 +1,69 @@ +10 REM GRAPHICS DEMO FOR THE BASYS 3 Z-80 +20 REM COLOUR BARS, CIRCLES, LINES, CURVES, SHAPES, ANIMATION, MANDELBROT +30 S=TIM +100 CLS +110 INK 15: LOCATE 3,30: PRINT "BASYS 3 Z-80 GRAPHICS" +120 INK 7: LOCATE 5,26: PRINT "320 X 240 PIXELS IN 16 COLOURS" +130 FOR C=1 TO 15 +140 FILL C*20-10,100,C*20+7,180,C +150 INK C: LOCATE 25,C*5-1: PRINT C; +160 NEXT C +170 GOSUB 9000 +200 CLS: INK 15: PRINT "CIRCLE" +210 C=0 +220 FOR R=3 TO 117 STEP 3 +230 GOSUB 8000: CIRCLE 160,120,R,C +240 NEXT R +250 GOSUB 9000 +300 CLS: INK 15: PRINT "LINE" +310 C=0 +320 FOR X=0 TO 319 STEP 8: GOSUB 8000: LINE 160,120,X,0,C: NEXT X +330 FOR Y=0 TO 239 STEP 8: GOSUB 8000: LINE 160,120,319,Y,C: NEXT Y +340 FOR X=319 TO 0 STEP -8: GOSUB 8000: LINE 160,120,X,239,C: NEXT X +350 FOR Y=239 TO 0 STEP -8: GOSUB 8000: LINE 160,120,0,Y,C: NEXT Y +360 GOSUB 9000 +400 CLS: INK 10: PRINT "Y = SIN(X)": INK 12: PRINT "Y = COS(X)" +410 LINE 0,120,319,120,8: LINE 160,0,160,239,8 +420 FOR X=0 TO 319 +430 PLOT X,120-90*SIN((X-160)/25),10 +440 PLOT X,120-90*COS((X-160)/25),12 +450 NEXT X +460 GOSUB 9000 +500 CLS: INK 15: PRINT "FILL AND RECT": RANDOMIZE +510 FOR I=1 TO 120 +520 X=INT(RND*290): Y=16+INT(RND*200): C=1+INT(RND*15) +530 IF RND<.5 THEN FILL X,Y,X+5+INT(RND*30),Y+5+INT(RND*20),C: GOTO 550 +540 RECT X,Y,X+5+INT(RND*30),Y+5+INT(RND*20),C +550 NEXT I +560 GOSUB 9000 +600 CLS: INK 15: PRINT "ANIMATION" +610 RECT 0,16,319,239,7 +620 X=40: Y=60: U=3: V=2 +630 FOR I=1 TO 500 +640 CIRCLE X,Y,6,0 +650 X=X+U: Y=Y+V +660 IF X<8 OR X>311 THEN U=-U +670 IF Y<24 OR Y>231 THEN V=-V +680 CIRCLE X,Y,6,11: PLOT X,Y,14 +690 T=TIM +700 IF TIM-T<.01 THEN 700 +710 NEXT I +720 GOSUB 9000 +800 CLS: INK 15: PRINT "MANDELBROT SET": M=TIM +810 FOR J=0 TO 59: FOR I=0 TO 79 +820 A=I*.04-2.2: B=J*.04-1.2: X=0: Y=0 +830 FOR K=1 TO 15 +840 Z=X*X-Y*Y+A: Y=2*X*Y+B: X=Z +850 IF X*X+Y*Y>4 THEN 870 +860 NEXT K +870 IF K>15 THEN K=0 +880 FILL I*4,J*4,I*4+3,J*4+3,K +890 NEXT I: NEXT J +900 INK 7: LOCATE 30,1: PRINT "MANDELBROT TOOK";INT(TIM-M);"SECONDS."; +910 PRINT " WHOLE DEMO";INT(TIM-S);"SECONDS." +920 END +8000 C=C+1: IF C>15 THEN C=1 +8010 RETURN +9000 T=TIM +9010 IF TIM-T<3 THEN 9010 +9020 RETURN diff --git a/basic/examples/sound.bas b/basic/examples/sound.bas new file mode 100644 index 0000000..f0ee41b --- /dev/null +++ b/basic/examples/sound.bas @@ -0,0 +1,26 @@ +10 REM SOUND DEMO - NEEDS A PMODAMP2 ON THE TOP ROW OF PMOD JA +20 REM PITCH = 125000 / FREQUENCY. PORTS: 144-149 PITCHES, 150 NOISE, +30 REM 151 MIXER, 152-154 VOLUMES, 155-157 ENVELOPES (ATTACK*16+DECAY) +40 PRINT "A SCALE" +50 OUT 151, 1: OUT 155, 3 +60 FOR I = 1 TO 8 +70 READ P: GOSUB 500 +80 OUT 152, 15 +90 IF INP(152) > 0 THEN 90 +100 NEXT I +110 PRINT "A LASER" +120 OUT 151, 4: OUT 149, 0: OUT 157, 0: OUT 154, 13 +130 FOR P = 30 TO 250 STEP 6: OUT 148, P: NEXT P +140 OUT 154, 0 +150 PRINT "AN EXPLOSION" +160 OUT 151, 16: OUT 150, 24: OUT 156, 8: OUT 153, 15 +170 IF INP(153) > 0 THEN 170 +180 PRINT "A CHORD" +190 OUT 151, 7 +200 OUT 144, 221: OUT 145, 1: OUT 146, 123: OUT 147, 1: OUT 148, 63: OUT 149, 1 +210 OUT 155, 69: OUT 156, 69: OUT 157, 69 +220 OUT 152, 12: OUT 153, 12: OUT 154, 12 +230 IF INP(152) > 0 THEN 230 +240 END +500 OUT 144, P - INT(P / 256) * 256: OUT 145, INT(P / 256): RETURN +900 DATA 477, 425, 379, 358, 319, 284, 253, 239 diff --git a/basic/examples/sprites.bas b/basic/examples/sprites.bas new file mode 100644 index 0000000..6efc485 --- /dev/null +++ b/basic/examples/sprites.bas @@ -0,0 +1,54 @@ +10 REM SPRITE DEMO FOR THE BASYS 3 Z-80 +20 REM W A S D MOVE THE ROBOT, Q QUITS. SIX BALLS BOUNCE AROUND; +30 REM THE BORDER CHANGES COLOUR WHILE THE ROBOT TOUCHES ONE. +40 DEF FNH(A)=A-48-7*INT(A/65) +50 RANDOMIZE +100 CLS: INK 15: PRINT "SPRITES W A S D MOVE Q QUITS" +110 RECT 0,16,319,239,8 +120 FOR S=0 TO 1: GOSUB 8000: NEXT S +200 N=6: DIM X(6),Y(6),U(6),V(6) +210 FOR I=1 TO N +220 X(I)=20+INT(RND(1)*270): Y(I)=30+INT(RND(1)*180) +230 U(I)=2+INT(RND(1)*3): V(I)=1+INT(RND(1)*3) +240 OUT 112,I: OUT 116,1: OUT 117,1 +250 NEXT I +260 P=152: Q=120: OUT 112,0: OUT 116,0: OUT 117,1 +300 F=INP(120) +310 IF INP(0) AND 1 THEN GOSUB 7000 +320 FOR I=1 TO N +330 X(I)=X(I)+U(I): IF X(I)<2 OR X(I)>301 THEN U(I)=-U(I): X(I)=X(I)+2*U(I) +340 Y(I)=Y(I)+V(I): IF Y(I)<18 OR Y(I)>221 THEN V(I)=-V(I): Y(I)=Y(I)+2*V(I) +350 OUT 112,I: OUT 113,X(I) AND 255: OUT 114,INT(X(I)/256): OUT 115,Y(I) +360 NEXT I +370 OUT 112,0: OUT 113,P AND 255: OUT 114,INT(P/256): OUT 115,Q +380 IF INP(128) AND 1 THEN H=H+1: RECT 0,16,319,239,1+(H AND 7) +390 IF INP(120)=F THEN 390 +400 GOTO 300 +7000 K=INP(1): IF K>96 THEN K=K-32 +7010 IF K=87 AND Q>18 THEN Q=Q-4 +7020 IF K=83 AND Q<220 THEN Q=Q+4 +7030 IF K=65 AND P>2 THEN P=P-4: OUT 112,0: OUT 117,3 +7040 IF K=68 AND P<300 THEN P=P+4: OUT 112,0: OUT 117,1 +7050 IF K=81 THEN CLS: END +7060 RETURN +8000 REM LOAD SHAPE S FROM 16 ROWS OF 16 HEX DIGITS (0 = SEE-THROUGH) +8010 OUT 118,S +8020 FOR R=1 TO 16: READ A$ +8030 FOR C=1 TO 15 STEP 2 +8040 OUT 119,16*FNH(ASC(MID$(A$,C,1)))+FNH(ASC(MID$(A$,C+1,1))) +8050 NEXT C: NEXT R +8060 RETURN +9000 REM SHAPE 0: THE ROBOT +9010 DATA "00000BBBBBB00000","0000BBBBBBBB0000","000BB99BB99BB000" +9020 DATA "000BB99BB99BB000","000BBBBBBBBBB000","000BBB0000BBB000" +9030 DATA "0000BBBBBBBB0000","0000007777000000","0077777777777700" +9040 DATA "0770777777770770","0770777777770770","0770777777770770" +9050 DATA "0000777777770000","0000770000770000","0000770000770000" +9060 DATA "000FFF0000FFF000" +9100 REM SHAPE 1: A BALL +9110 DATA "00000EEEEEE00000","000EEEEEEEEEE000","00EEFFEEEEEEEE00" +9120 DATA "0EEFFFEEEEEEEEE0","0EEFFEEEEEEEEEE0","EEEEEEEEEEEEEEEE" +9130 DATA "EEEEEEEEEEEEEEEE","EEEEEEEEEEEEEEEE","EEEEEEEEEEEEEEEE" +9140 DATA "EEEEEEEEEEEEEEEE","0EEEEEEEEEEEEE60","0EEEEEEEEEEEE660" +9150 DATA "00EEEEEEEEEE6600","000EEEEEEE666000","0000066666600000" +9160 DATA "0000000000000000" diff --git a/basic/test-edit.py b/basic/test-edit.py new file mode 100644 index 0000000..d512057 --- /dev/null +++ b/basic/test-edit.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +"""Try BASIC's line editor in tools/rv32emu.py, with the screen kept by pyte. + + python3 test-edit.py + +Types lines the way the keyboard sends them (cursor keys as ESC [ C and so +on), checks what the screen shows while a line is edited, and checks the +program LIST prints afterwards. Needs pyte. +""" +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "tools")) +from boardemu import Board # noqa: E402 + +RIGHT, LEFT, UP = b"\x1b[C", b"\x1b[D", b"\x1b[A" +HOME, END, DEL = b"\x1b[1~", b"\x1b[4~", b"\x1b[3~" +BS, CTRL_U, CR = b"\x7f", b"\x15", b"\r" + + +class Basic(Board): + def __init__(self): + mem = open(os.path.join(HERE, "basic.bin"), "rb").read() + super().__init__(mem, start=0, rom_top=0xA000) + self.idle = 0 + + def io_in(self, port): + if port & 0xFF == 0 and not self.keys_in: + self.idle += 1 + return super().io_in(port) + + def io_out(self, port, v): + self.idle = 0 # printing reads the status port too + super().io_out(port, v) + + def type(self, keys): + """Send keys one at a time and run until BASIC waits for the next.""" + for k in [keys[i:i + 1] for i in range(len(keys))]: + self.keys_in += k + self.idle = 0 + while self.idle < 50: + self.step() + + +def main(): + b = Basic() + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def screen(): + return b.screen_text() + + def lines(): + return "\n".join(l.rstrip() for l in screen().display) + + def row(r): + return screen().display[r].rstrip() + + def cur(): + s = screen() + return s.cursor.y, s.cursor.x + + b.type(b"") + b.type(b'10 PRINT "HELLO"' + CR + b"20 GOTO 10" + CR) + b.type(b"PRINT PEEK(40961)" + CR) # line 10's number, low byte + check("the program still starts at A000h", lines().rstrip().endswith(" 10\n\nREADY")) + y = cur()[0] + b.type(b"10" + RIGHT) + check("right after 10 copies one character of line 10", row(y) == "10" and cur() == (y, 3)) + b.type(RIGHT * 2) + check("each right copies one more", row(y) == "10 PR" and cur() == (y, 5)) + b.type(END) + check("End copies the rest", row(y) == '10 PRINT "HELLO"' and cur() == (y, 16)) + b.type(LEFT * 6) # cursor onto the H + check("left moves the cursor back", cur() == (y, 10)) + b.type(b"BIG ") + check("typing inserts in the middle", row(y) == '10 PRINT "BIG HELLO"' and cur() == (y, 14)) + b.type(HOME + RIGHT * 3 + DEL * 6) + check("Home and Delete", row(y) == '10 "BIG HELLO"' and cur() == (y, 3)) + b.type(b"PRINT " + END + BS + b'!"') + check("End and Backspace", row(y) == '10 PRINT "BIG HELLO!"') + b.type(CR + b"LIST" + CR) + lst = lines() + check("the edited line is stored", '10 PRINT "BIG HELLO!"\n20 GOTO 10' in lst) + + b.type(UP) + y = cur()[0] + check("up brings back the last line, cursor at the end", row(y) == "LIST" and cur() == (y, 4)) + b.type(CTRL_U) + check("Ctrl-U clears the line", row(y) == "" and cur() == (y, 0)) + b.type(b"99" + RIGHT) + check("right after a missing line number does nothing", row(y) == "99" and cur() == (y, 2)) + b.type(CTRL_U + b"20" + RIGHT * 6 + DEL * 2 + b"30" + CR) + b.type(b"LIST" + CR) + lst = lines().split("LIST")[-1] + check("Delete skips old characters while copying", "20 GOTO 30" in lst and "20 GOTO 10" not in lst) + b.type(b"20" + END + HOME + DEL * 2 + b"40" + CR + b"LIST" + CR) + check("a copied line can be stored under a new number", "20 GOTO 30\n40 GOTO 30" in lines()) + + # a line that wraps onto three screen rows + text = "REM " + "".join(chr(65 + i % 26) for i in range(170)) + b.type(b"40 " + text.encode() + CR) + b.type(b"40" + END) + y, x = cur() + full = "40 " + text + y0 = y - (len(full) // 80) + shown = "".join(screen().display[y0 + i] for i in range(3)) + check("a long line comes in over three rows", shown.rstrip() == full and (y, x) == (y0 + len(full) // 80, len(full) % 80)) + b.type(HOME + RIGHT * 79) + check("right walks across a row end", cur() == (y0, 79)) + b.type(RIGHT) + check("and onto the next row", cur() == (y0 + 1, 0)) + b.type(b"*" + LEFT * 2 + DEL) + full = full[:79] + "*" + full[80:] + shown = "".join(screen().display[y0 + i] for i in range(3)) + check("inserting and deleting across rows redraws them", shown.rstrip() == full and cur() == (y0, 79)) + b.type(CR + b"LIST 40" + CR) + check("the long line is stored", full in "".join(screen().display)) + b.type(UP + UP) + check("up again gives the same last line", lines().rstrip().endswith("LIST 40")) + b.type(CTRL_U) + + b.type(b"NEW" + CR + b'INPUT A$: PRINT "GOT ";A$' + CR) + b.type(b"ABD" + LEFT + b"C" + CR) + check("INPUT uses the editor too", "GOT ABCD" in lines()) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/basic/test-renum.py b/basic/test-renum.py new file mode 100644 index 0000000..7bc0520 --- /dev/null +++ b/basic/test-renum.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +"""Try BASIC's RENUM in tools/rv32emu.py, with the screen kept by pyte. + + python3 test-renum.py + +Also checks number printing and reading, which were rewritten to make room. +""" +import importlib.util +import os +import sys +import functools +print = functools.partial(print, flush=True) + +HERE = os.path.dirname(os.path.abspath(__file__)) +spec = importlib.util.spec_from_file_location("te", os.path.join(HERE, "test-edit.py")) +te = importlib.util.module_from_spec(spec) +spec.loader.exec_module(te) +CR = te.CR + + +def main(): + b = te.Basic() + errors = 0 + + def check(what, ok, got=None): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + if not ok and got is not None: + print(" got: " + repr(got)) + errors += not ok + + def screen(): + return "\n".join(l.rstrip() for l in b.screen_text().display) + + def cmd(text): + """Type a command and return what it printed.""" + b.type(b"CLS" + CR) + b.type(text.encode() + CR) + out = screen().split(text, 1)[-1] + return out.replace("\nREADY", "").strip() + + def load(prog): + b.type(b"NEW" + CR) + for line in prog.strip().splitlines(): + b.type(line.strip().encode() + CR) + + def listing(): + return [l for l in cmd("LIST").splitlines() if l] + + b.type(b"") + load(''' + 5 REM GOTO 5 STAYS AS TYPED + 7 GOSUB 200 + 12 IF X < 3 THEN 7 + 13 IF X = 3 GOTO 40 + 40 ON X - 2 GOTO 41, 13, 999 + 41 PRINT "GOTO 12"; X: END + 200 X = X + 1: RETURN + 300 END + ''') + before = cmd("RUN") + cmd("RENUM") + check("RENUM numbers from 10 in steps of 10, fixing GOTO, GOSUB, THEN and ON", + listing() == ['10 REM GOTO 5 STAYS AS TYPED', + '20 GOSUB 70', + '30 IF X < 3 THEN 20', + '40 IF X = 3 GOTO 50', + '50 ON X - 2 GOTO 60, 40, 999', + '60 PRINT "GOTO 12"; X: END', + '70 X = X + 1: RETURN', + '80 END'], listing()) + check("a reference to a missing line is left alone", "GOTO 60, 40, 999" in "\n".join(listing())) + check("the program runs the same afterwards", cmd("RUN") == before and before == "GOTO 12 3", before) + + cmd("RENUM 1000, 5") + l = listing() + check("RENUM start, step", l[0].startswith("1000 ") and l[-1] == "1035 END" and + "1010 IF X < 3 THEN 1005" in l and "1020 ON X - 2 GOTO 1025, 1015, 999" in l, l) + cmd("RENUM 1, 1") + l = listing() + check("line numbers can get shorter", "3 IF X < 3 THEN 2" in l and "5 ON X - 2 GOTO 6, 4, 999" in l, l) + check("still runs", cmd("RUN") == "GOTO 12 3") + + load(''' + 1 GOTO 2 + 2 RUN 3 + 3 GOSUB 1 + ''') + cmd("RENUM 10000, 10000") + check("RUN n is renumbered too", listing() == ["10000 GOTO 20000", "20000 RUN 30000", "30000 GOSUB 10000"], listing()) + out = cmd("RENUM 60000, 3000") + check("numbers past 65535 are refused", "ERROR" in out.upper() or "ILLEGAL" in out.upper(), out) + check("and the program is unchanged", listing() == ["10000 GOTO 20000", "20000 RUN 30000", "30000 GOSUB 10000"], listing()) + out = cmd("RENUM 10, 0") + check("step 0 is refused", listing()[0].startswith("10000"), out) + + load("10 PRINT 1\n20 GOTO 10") + load("") + check("RENUM on an empty program is fine", cmd("RENUM") == "" and listing() == []) + + # a line that would grow past 255 bytes + refs = ",".join(["1"] * 115) # typed lines stop at 250 characters + load("1 ON X GOTO " + refs) + out = cmd("RENUM 10000") + check("a line that would grow too long is refused", "LONG" in out.upper(), out) + check("and is left as it was", ("1 ON X GOTO " + refs) in cmd("LIST").replace("\n", "")) + + # number printing and reading (rewritten to make room); the screen wraps + # at 80 columns, so compare the words only + def nums(text): + b.type(b"CLS" + CR) + b.type(text.encode() + CR) + return " ".join("".join(b.screen_text().display).split()).split(text, 1)[-1].replace("READY", "").strip() + + out = nums('PRINT 0; 1; -1; .5; 1/3; .001; .0001; 123.456; 999999; 1000000; 1E30; -2.5E-12; 65535; 12345678') + check("numbers print as before", + out == "0 1 -1 .5 .333333 .001 1E-04 123.456 999999 1E+06 1E+30 -2.5E-12 65535 1.23457E+07", out) + out = nums("PRINT 1.5E3; 12.5E-1; 1234567890123; .000123; 3.; 00042.50") + check("numbers are read as before", out == "1500 1.25 1.23457E+12 1.23E-04 3 42.5", out) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/basic/test-strarr.py b/basic/test-strarr.py new file mode 100644 index 0000000..8bc23f0 --- /dev/null +++ b/basic/test-strarr.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +"""Try BASIC's string arrays in tools/rv32emu.py, with the screen kept by pyte. + + python3 test-strarr.py +""" +import importlib.util +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +spec = importlib.util.spec_from_file_location("te", os.path.join(HERE, "test-edit.py")) +te = importlib.util.module_from_spec(spec) +spec.loader.exec_module(te) +CR = te.CR + + +def main(): + b = te.Basic() + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def run(prog): + b.type(b"NEW" + CR) + for line in prog.strip().splitlines(): + b.type(line.encode() + CR) + b.type(b"RUN" + CR) + return "\n".join(l.rstrip() for l in b.screen_text().display).split("RUN")[-1] + + b.type(b"") + out = run(''' +10 DIM N$(4), A(3) +20 FOR I = 0 TO 4: READ N$(I): NEXT I +30 A(2) = 7: A$ = "PLAIN" +40 FOR I = 4 TO 0 STEP -1: PRINT N$(I);",";: NEXT I +50 PRINT: PRINT A$; A(2); LEN(N$(1)); " "; LEFT$(N$(3), 2) +60 DATA RED, GREEN, BLUE, "YEL, LOW", WHITE +''') + check("DIM, READ and PRINT a string array", "WHITE,YEL, LOW,BLUE,GREEN,RED," in out) + check("plain A$ and A() kept apart", "PLAIN 7 5 YE" in out) + + out = run(''' +10 DIM B$(2,3) +20 B$(1,2) = "MID": B$(2,3) = B$(1,2) + "DLE" +30 PRINT B$(2,3); "/"; B$(0,0); "/"; LEN(B$(0,1)) +40 C$(10) = "AUTO": PRINT C$(10) +50 IF B$(1,2) = "MID" THEN PRINT "EQUAL" +''') + check("two subscripts and joining", "MIDDLE// 0" in out) + check("undeclared string array gets 0..10", "AUTO" in out) + check("comparing an element", "EQUAL" in out) + + out = run(''' +10 INPUT "NAME"; N$(3) +20 PRINT "HI "; N$(3) +''') + b.type(b"ZED" + CR) + check("INPUT into an element", "HI ZED" in "\n".join(l.rstrip() for l in b.screen_text().display)) + + out = run('10 LINE INPUT L$(1): PRINT "<"; L$(1); ">"') + b.type(b"A, B" + CR) + check("LINE INPUT into an element", "" in "\n".join(l.rstrip() for l in b.screen_text().display)) + + out = run('10 DIM Q$(2): Q$(3) = "X"') + check("subscript out of range", "SUBSCRIPT" in out.upper()) + out = run('10 DIM Z$(300)') + check("too many elements is an error", "SUBSCRIPT" in out.upper()) + out = run('10 DIM Z$(200), Y$(200)') + check("running out of memory is an error", "MEMORY" in out.upper()) + out = run('10 DIM Z$(200): Z$(200) = "LAST": PRINT Z$(200)') + check("a 201-element string array fits", "LAST" in out) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/bench/bench.S b/bench/bench.S new file mode 100644 index 0000000..f050c73 --- /dev/null +++ b/bench/bench.S @@ -0,0 +1,16 @@ +# Bench program: the LEDs count up about 5 times a second at 90 MHz, using +# mul and div so they are exercised. + .text + .globl _start +_start: + li s0, 0x10000 # LED register + li s1, 0 # count +1: li t0, 3000000 # ~ 6 cycles per loop +2: addi t0, t0, -1 + bnez t0, 2b + addi s1, s1, 1 + li t1, 7 + mul t2, s1, t1 # count * 7 / 7 = count + divu t2, t2, t1 + sw t2, 0(s0) + j 1b diff --git a/bench/bench.mem b/bench/bench.mem new file mode 100644 index 0000000..693e6e3 --- /dev/null +++ b/bench/bench.mem @@ -0,0 +1,12 @@ +00010437 +00000493 +002dc2b7 +6c028293 +fff28293 +fe029ee3 +00148493 +00700313 +026483b3 +0263d3b3 +00742023 +fddff06f diff --git a/bench/bench.xdc b/bench/bench.xdc new file mode 100644 index 0000000..504173f --- /dev/null +++ b/bench/bench.xdc @@ -0,0 +1,34 @@ +set_property -dict { PACKAGE_PIN W5 IOSTANDARD LVCMOS33 } [get_ports clk] +create_clock -add -name sys_clk_pin -period 10.00 -waveform {0 5} [get_ports clk] +set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports {sw[0]}] +set_property -dict { PACKAGE_PIN V16 IOSTANDARD LVCMOS33 } [get_ports {sw[1]}] +set_property -dict { PACKAGE_PIN W16 IOSTANDARD LVCMOS33 } [get_ports {sw[2]}] +set_property -dict { PACKAGE_PIN W17 IOSTANDARD LVCMOS33 } [get_ports {sw[3]}] +set_property -dict { PACKAGE_PIN W15 IOSTANDARD LVCMOS33 } [get_ports {sw[4]}] +set_property -dict { PACKAGE_PIN V15 IOSTANDARD LVCMOS33 } [get_ports {sw[5]}] +set_property -dict { PACKAGE_PIN W14 IOSTANDARD LVCMOS33 } [get_ports {sw[6]}] +set_property -dict { PACKAGE_PIN W13 IOSTANDARD LVCMOS33 } [get_ports {sw[7]}] +set_property -dict { PACKAGE_PIN V2 IOSTANDARD LVCMOS33 } [get_ports {sw[8]}] +set_property -dict { PACKAGE_PIN T3 IOSTANDARD LVCMOS33 } [get_ports {sw[9]}] +set_property -dict { PACKAGE_PIN T2 IOSTANDARD LVCMOS33 } [get_ports {sw[10]}] +set_property -dict { PACKAGE_PIN R3 IOSTANDARD LVCMOS33 } [get_ports {sw[11]}] +set_property -dict { PACKAGE_PIN W2 IOSTANDARD LVCMOS33 } [get_ports {sw[12]}] +set_property -dict { PACKAGE_PIN U1 IOSTANDARD LVCMOS33 } [get_ports {sw[13]}] +set_property -dict { PACKAGE_PIN T1 IOSTANDARD LVCMOS33 } [get_ports {sw[14]}] +set_property -dict { PACKAGE_PIN R2 IOSTANDARD LVCMOS33 } [get_ports {sw[15]}] +set_property -dict { PACKAGE_PIN U16 IOSTANDARD LVCMOS33 } [get_ports {led[0]}] +set_property -dict { PACKAGE_PIN E19 IOSTANDARD LVCMOS33 } [get_ports {led[1]}] +set_property -dict { PACKAGE_PIN U19 IOSTANDARD LVCMOS33 } [get_ports {led[2]}] +set_property -dict { PACKAGE_PIN V19 IOSTANDARD LVCMOS33 } [get_ports {led[3]}] +set_property -dict { PACKAGE_PIN W18 IOSTANDARD LVCMOS33 } [get_ports {led[4]}] +set_property -dict { PACKAGE_PIN U15 IOSTANDARD LVCMOS33 } [get_ports {led[5]}] +set_property -dict { PACKAGE_PIN U14 IOSTANDARD LVCMOS33 } [get_ports {led[6]}] +set_property -dict { PACKAGE_PIN V14 IOSTANDARD LVCMOS33 } [get_ports {led[7]}] +set_property -dict { PACKAGE_PIN V13 IOSTANDARD LVCMOS33 } [get_ports {led[8]}] +set_property -dict { PACKAGE_PIN V3 IOSTANDARD LVCMOS33 } [get_ports {led[9]}] +set_property -dict { PACKAGE_PIN W3 IOSTANDARD LVCMOS33 } [get_ports {led[10]}] +set_property -dict { PACKAGE_PIN U3 IOSTANDARD LVCMOS33 } [get_ports {led[11]}] +set_property -dict { PACKAGE_PIN P3 IOSTANDARD LVCMOS33 } [get_ports {led[12]}] +set_property -dict { PACKAGE_PIN N3 IOSTANDARD LVCMOS33 } [get_ports {led[13]}] +set_property -dict { PACKAGE_PIN P1 IOSTANDARD LVCMOS33 } [get_ports {led[14]}] +set_property -dict { PACKAGE_PIN L1 IOSTANDARD LVCMOS33 } [get_ports {led[15]}] diff --git a/bench/build.tcl b/bench/build.tcl new file mode 100644 index 0000000..5efcbc8 --- /dev/null +++ b/bench/build.tcl @@ -0,0 +1,25 @@ +# Timing build of the core alone: vivado -mode batch -source bench/build.tcl +# MULT/DIV environment variables set the clock (default 9/10 = 90 MHz). +set root [file normalize [file dirname [info script]]/..] +set out $root/build/bench +file mkdir $out +set mult [expr {[info exists ::env(MULT)] ? $::env(MULT) : 9.0}] +set div [expr {[info exists ::env(DIV)] ? $::env(DIV) : 10.0}] +puts "CPU clock: [expr {100.0 * $mult / $div}] MHz" + +read_verilog $root/rtl/rv32_cpu.v $root/bench/cpu_bench.v +read_mem $root/bench/bench.mem +read_xdc $root/bench/bench.xdc +synth_design -top cpu_bench -part xc7a35tcpg236-1 -generic MULT=$mult -generic DIV=$div +opt_design -directive Explore +place_design -directive ExtraTimingOpt +phys_opt_design -directive AggressiveExplore +route_design -directive Explore +phys_opt_design -directive AggressiveExplore +report_utilization -file $out/utilization.rpt +report_utilization -hierarchical -file $out/util_hier.rpt +report_timing_summary -file $out/timing.rpt +report_timing -max_paths 20 -nworst 1 -unique_pins -file $out/paths.rpt +write_bitstream -force $out/cpu_bench.bit +set wns [get_property SLACK [get_timing_paths -max_paths 1 -setup]] +puts "Worst setup slack: $wns ns" diff --git a/bench/cpu_bench.v b/bench/cpu_bench.v new file mode 100644 index 0000000..c3a621d --- /dev/null +++ b/bench/cpu_bench.v @@ -0,0 +1,80 @@ +`timescale 1ns / 1ps + +// Timing bench for rv32_cpu: the core with 64 KB of block RAM (instruction +// fetch on one port, loads and stores on the other) at 100 MHz * MULT / DIV. +// The LEDs show a register at 0x10000; switches 3:0 drive the interrupts. +module cpu_bench #( + parameter real MULT = 9.0, + parameter real DIV = 10.0, + parameter MEM_FILE = "bench.mem" +) ( + input clk, + input [15:0] sw, + output reg [15:0] led +); + wire fb, cclk_m, cclk, locked; + MMCME2_BASE #( + .CLKIN1_PERIOD(10.0), .DIVCLK_DIVIDE(1), + .CLKFBOUT_MULT_F(MULT), .CLKOUT0_DIVIDE_F(DIV) + ) mmcm ( + .CLKIN1(clk), .CLKFBIN(fb), .CLKFBOUT(fb), .CLKFBOUTB(), + .CLKOUT0(cclk_m), .CLKOUT0B(), .CLKOUT1(), .CLKOUT1B(), .CLKOUT2(), + .CLKOUT2B(), .CLKOUT3(), .CLKOUT3B(), .CLKOUT4(), .CLKOUT5(), .CLKOUT6(), + .LOCKED(locked), .PWRDWN(1'b0), .RST(1'b0) + ); + BUFG bufg (.I(cclk_m), .O(cclk)); + + reg [3:0] rst_sr = 4'hF; + always @(posedge cclk) rst_sr <= {rst_sr[2:0], !locked}; + reg [3:0] sw_r; + always @(posedge cclk) sw_r <= sw[3:0]; + + wire i_en, d_req, d_we; + wire [31:0] i_addr, d_addr, d_wdata; + wire [3:0] d_wstrb; + reg [31:0] i_rdata, ram_q; + reg d_ack, io_sel; + + rv32_cpu cpu ( + .clk(cclk), .rst(rst_sr[3]), + .i_en(i_en), .i_addr(i_addr), .i_rdata(i_rdata), + .d_req(d_req), .d_we(d_we), .d_wstrb(d_wstrb), .d_addr(d_addr), + .d_wdata(d_wdata), .d_rdata(io_sel ? {16'd0, led} : ram_q), .d_ack(d_ack), + .irq_soft(sw_r[0]), .irq_timer(sw_r[1]), .irq_ext(sw_r[2]), + .irq_local({15'd0, sw_r[3]}), .nmi(1'b0), .nmi_step(1'b0), .nmi_taken(), + .dbg_pc(), .dbg_decode(), .retire() + ); + + // Reads use the core's address directly (a read with no request is + // harmless); stores are registered and written the next cycle, so the + // late d_req never reaches the block RAM's write enables. + reg [31:0] ram [0:16383]; + initial $readmemh(MEM_FILE, ram); + wire ram_sel = d_addr[31:16] == 16'd0; + reg w_go; + reg [13:0] w_a; + reg [31:0] w_d; + reg [3:0] w_s; + integer b; + always @(posedge cclk) begin + if (i_en) i_rdata <= ram[i_addr[15:2]]; + end + // one address for the data port: the pending store's, else the core's + wire [13:0] b_a = w_go ? w_a : d_addr[15:2]; + always @(posedge cclk) begin + if (w_go) begin + for (b = 0; b < 4; b = b + 1) + if (w_s[b]) ram[b_a][8*b +: 8] <= w_d[8*b +: 8]; + end + ram_q <= ram[b_a]; + end + always @(posedge cclk) begin + w_go <= d_req && d_we && ram_sel; + w_a <= d_addr[15:2]; + w_d <= d_wdata; + w_s <= d_wstrb; + d_ack <= d_req; // the store is written as the ack goes back + if (d_req) io_sel <= !ram_sel; + if (d_req && !ram_sel && d_we) led <= d_wdata[15:0]; + end +endmodule diff --git a/constraints/basys3.xdc b/constraints/basys3.xdc new file mode 100644 index 0000000..a17dd63 --- /dev/null +++ b/constraints/basys3.xdc @@ -0,0 +1,117 @@ +## Basys 3 (XC7A35T-1CPG236C) pins for basys3_terminal + +## 100 MHz clock +set_property -dict { PACKAGE_PIN W5 IOSTANDARD LVCMOS33 } [get_ports clk] +create_clock -add -name sys_clk_pin -period 10.00 -waveform {0 5} [get_ports clk] + +## Switches +set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports {sw[0]}] +set_property -dict { PACKAGE_PIN V16 IOSTANDARD LVCMOS33 } [get_ports {sw[1]}] +set_property -dict { PACKAGE_PIN W16 IOSTANDARD LVCMOS33 } [get_ports {sw[2]}] +set_property -dict { PACKAGE_PIN W17 IOSTANDARD LVCMOS33 } [get_ports {sw[3]}] +set_property -dict { PACKAGE_PIN W15 IOSTANDARD LVCMOS33 } [get_ports {sw[4]}] +set_property -dict { PACKAGE_PIN V15 IOSTANDARD LVCMOS33 } [get_ports {sw[5]}] +set_property -dict { PACKAGE_PIN W14 IOSTANDARD LVCMOS33 } [get_ports {sw[6]}] +set_property -dict { PACKAGE_PIN W13 IOSTANDARD LVCMOS33 } [get_ports {sw[7]}] +set_property -dict { PACKAGE_PIN V2 IOSTANDARD LVCMOS33 } [get_ports {sw[8]}] +set_property -dict { PACKAGE_PIN T3 IOSTANDARD LVCMOS33 } [get_ports {sw[9]}] +set_property -dict { PACKAGE_PIN T2 IOSTANDARD LVCMOS33 } [get_ports {sw[10]}] +set_property -dict { PACKAGE_PIN R3 IOSTANDARD LVCMOS33 } [get_ports {sw[11]}] +set_property -dict { PACKAGE_PIN W2 IOSTANDARD LVCMOS33 } [get_ports {sw[12]}] +set_property -dict { PACKAGE_PIN U1 IOSTANDARD LVCMOS33 } [get_ports {sw[13]}] +set_property -dict { PACKAGE_PIN T1 IOSTANDARD LVCMOS33 } [get_ports {sw[14]}] +set_property -dict { PACKAGE_PIN R2 IOSTANDARD LVCMOS33 } [get_ports {sw[15]}] + +## LEDs +set_property -dict { PACKAGE_PIN U16 IOSTANDARD LVCMOS33 } [get_ports {led[0]}] +set_property -dict { PACKAGE_PIN E19 IOSTANDARD LVCMOS33 } [get_ports {led[1]}] +set_property -dict { PACKAGE_PIN U19 IOSTANDARD LVCMOS33 } [get_ports {led[2]}] +set_property -dict { PACKAGE_PIN V19 IOSTANDARD LVCMOS33 } [get_ports {led[3]}] +set_property -dict { PACKAGE_PIN W18 IOSTANDARD LVCMOS33 } [get_ports {led[4]}] +set_property -dict { PACKAGE_PIN U15 IOSTANDARD LVCMOS33 } [get_ports {led[5]}] +set_property -dict { PACKAGE_PIN U14 IOSTANDARD LVCMOS33 } [get_ports {led[6]}] +set_property -dict { PACKAGE_PIN V14 IOSTANDARD LVCMOS33 } [get_ports {led[7]}] +set_property -dict { PACKAGE_PIN V13 IOSTANDARD LVCMOS33 } [get_ports {led[8]}] +set_property -dict { PACKAGE_PIN V3 IOSTANDARD LVCMOS33 } [get_ports {led[9]}] +set_property -dict { PACKAGE_PIN W3 IOSTANDARD LVCMOS33 } [get_ports {led[10]}] +set_property -dict { PACKAGE_PIN U3 IOSTANDARD LVCMOS33 } [get_ports {led[11]}] +set_property -dict { PACKAGE_PIN P3 IOSTANDARD LVCMOS33 } [get_ports {led[12]}] +set_property -dict { PACKAGE_PIN N3 IOSTANDARD LVCMOS33 } [get_ports {led[13]}] +set_property -dict { PACKAGE_PIN P1 IOSTANDARD LVCMOS33 } [get_ports {led[14]}] +set_property -dict { PACKAGE_PIN L1 IOSTANDARD LVCMOS33 } [get_ports {led[15]}] + +## 7-segment display +set_property -dict { PACKAGE_PIN W7 IOSTANDARD LVCMOS33 } [get_ports {seg[0]}] +set_property -dict { PACKAGE_PIN W6 IOSTANDARD LVCMOS33 } [get_ports {seg[1]}] +set_property -dict { PACKAGE_PIN U8 IOSTANDARD LVCMOS33 } [get_ports {seg[2]}] +set_property -dict { PACKAGE_PIN V8 IOSTANDARD LVCMOS33 } [get_ports {seg[3]}] +set_property -dict { PACKAGE_PIN U5 IOSTANDARD LVCMOS33 } [get_ports {seg[4]}] +set_property -dict { PACKAGE_PIN V5 IOSTANDARD LVCMOS33 } [get_ports {seg[5]}] +set_property -dict { PACKAGE_PIN U7 IOSTANDARD LVCMOS33 } [get_ports {seg[6]}] +set_property -dict { PACKAGE_PIN V7 IOSTANDARD LVCMOS33 } [get_ports dp] +set_property -dict { PACKAGE_PIN U2 IOSTANDARD LVCMOS33 } [get_ports {an[0]}] +set_property -dict { PACKAGE_PIN U4 IOSTANDARD LVCMOS33 } [get_ports {an[1]}] +set_property -dict { PACKAGE_PIN V4 IOSTANDARD LVCMOS33 } [get_ports {an[2]}] +set_property -dict { PACKAGE_PIN W4 IOSTANDARD LVCMOS33 } [get_ports {an[3]}] + +## Buttons +set_property -dict { PACKAGE_PIN U18 IOSTANDARD LVCMOS33 } [get_ports btnC] +set_property -dict { PACKAGE_PIN T18 IOSTANDARD LVCMOS33 } [get_ports btnU] +set_property -dict { PACKAGE_PIN U17 IOSTANDARD LVCMOS33 } [get_ports btnD] + +## VGA +set_property -dict { PACKAGE_PIN G19 IOSTANDARD LVCMOS33 } [get_ports {vgaRed[0]}] +set_property -dict { PACKAGE_PIN H19 IOSTANDARD LVCMOS33 } [get_ports {vgaRed[1]}] +set_property -dict { PACKAGE_PIN J19 IOSTANDARD LVCMOS33 } [get_ports {vgaRed[2]}] +set_property -dict { PACKAGE_PIN N19 IOSTANDARD LVCMOS33 } [get_ports {vgaRed[3]}] +set_property -dict { PACKAGE_PIN N18 IOSTANDARD LVCMOS33 } [get_ports {vgaBlue[0]}] +set_property -dict { PACKAGE_PIN L18 IOSTANDARD LVCMOS33 } [get_ports {vgaBlue[1]}] +set_property -dict { PACKAGE_PIN K18 IOSTANDARD LVCMOS33 } [get_ports {vgaBlue[2]}] +set_property -dict { PACKAGE_PIN J18 IOSTANDARD LVCMOS33 } [get_ports {vgaBlue[3]}] +set_property -dict { PACKAGE_PIN J17 IOSTANDARD LVCMOS33 } [get_ports {vgaGreen[0]}] +set_property -dict { PACKAGE_PIN H17 IOSTANDARD LVCMOS33 } [get_ports {vgaGreen[1]}] +set_property -dict { PACKAGE_PIN G17 IOSTANDARD LVCMOS33 } [get_ports {vgaGreen[2]}] +set_property -dict { PACKAGE_PIN D17 IOSTANDARD LVCMOS33 } [get_ports {vgaGreen[3]}] +set_property -dict { PACKAGE_PIN P19 IOSTANDARD LVCMOS33 } [get_ports Hsync] +set_property -dict { PACKAGE_PIN R19 IOSTANDARD LVCMOS33 } [get_ports Vsync] + +## USB-UART (FTDI), named from the FPGA's point of view +set_property -dict { PACKAGE_PIN B18 IOSTANDARD LVCMOS33 } [get_ports RsRx] +set_property -dict { PACKAGE_PIN A18 IOSTANDARD LVCMOS33 } [get_ports RsTx] + +## USB HID host (PIC24) - keyboard as PS/2 +set_property -dict { PACKAGE_PIN C17 IOSTANDARD LVCMOS33 PULLUP true } [get_ports PS2Clk] +set_property -dict { PACKAGE_PIN B17 IOSTANDARD LVCMOS33 PULLUP true } [get_ports PS2Data] + +## Asynchronous / human-speed I/O +set_false_path -from [get_ports {btnC btnU btnD sw[*] RsRx PS2Clk PS2Data}] + +# Configuration flash, used by the Z-80 for files (its clock goes through STARTUPE2) +set_property -dict { PACKAGE_PIN K19 IOSTANDARD LVCMOS33 } [get_ports QspiCSn] +set_property -dict { PACKAGE_PIN D18 IOSTANDARD LVCMOS33 } [get_ports {QspiDB[0]}] +set_property -dict { PACKAGE_PIN D19 IOSTANDARD LVCMOS33 } [get_ports {QspiDB[1]}] +set_property -dict { PACKAGE_PIN G18 IOSTANDARD LVCMOS33 } [get_ports {QspiDB[2]}] +set_property -dict { PACKAGE_PIN F18 IOSTANDARD LVCMOS33 } [get_ports {QspiDB[3]}] +# the SPI clock is slow (clk/4) and sampled mid-bit, so the pins need no timing +set_false_path -to [get_ports {QspiCSn QspiDB[*]}] +set_false_path -from [get_ports {QspiDB[*]}] + +# The Z-80 clock is only crossed through synchronisers and toggle handshakes. +set_clock_groups -asynchronous -group [get_clocks sys_clk_pin] \ + -group [get_clocks -of_objects [get_pins cpu_mmcm/CLKOUT0]] \ + -group [get_clocks -of_objects [get_pins pix_mmcm/CLKOUT0]] +set_false_path -to [get_ports {led[*] seg[*] dp an[*] RsTx}] + +## Pmod JA top row: a PmodAMP2 (AIN, GAIN, NC, SHUTDOWN) +set_property -dict { PACKAGE_PIN J1 IOSTANDARD LVCMOS33 } [get_ports {JA[0]}] +set_property -dict { PACKAGE_PIN L2 IOSTANDARD LVCMOS33 } [get_ports {JA[1]}] +set_property -dict { PACKAGE_PIN J2 IOSTANDARD LVCMOS33 } [get_ports {JA[2]}] +set_property -dict { PACKAGE_PIN G2 IOSTANDARD LVCMOS33 } [get_ports {JA[3]}] +set_false_path -to [get_ports {JA[*]}] + +## Configuration +set_property CONFIG_VOLTAGE 3.3 [current_design] +set_property CFGBVS VCCO [current_design] +set_property BITSTREAM.GENERAL.COMPRESS TRUE [current_design] +set_property BITSTREAM.CONFIG.SPI_BUSWIDTH 4 [current_design] +set_property CONFIG_MODE SPIx4 [current_design] diff --git a/docs/basic-manual.md b/docs/basic-manual.md new file mode 100644 index 0000000..3cea2ad --- /dev/null +++ b/docs/basic-manual.md @@ -0,0 +1,1398 @@ +# Basys 3 RISC-V BASIC + +*A Dartmouth-style BASIC with colour graphics, for the RISC-V computer inside +the Basys 3 VT220 terminal.* + +## 1. Getting started + +The computer shares the board with the terminal. Two switches decide who the screen +and keyboard belong to: + +| Switch | Down | Up | +|---|---|---| +| SW15 | Terminal for the PC's serial port | Console of the computer | +| SW14 | — | Link the PC's serial port to the computer as well: what the PC sends is typed in, and what BASIC prints is also sent to the PC | + +Flip **SW15 up**. The first time, BASIC greets you: + +``` +DARTMOUTH-STYLE BASIC RISC-V ON A BASYS 3 + +READY +``` + +The computer keeps running while SW15 is down. It just waits until it can print +again, so you can flip back and forth without losing your program. **BTND** +(or **Ctrl-Alt-Del** on the keyboard) restarts the computer; that wipes the program +but not the files in flash. **BTNC** restarts the whole board. + +### Talking to BASIC + +Anything typed without a line number runs at once: + +``` +PRINT 2+2 + 4 +``` + +A line that starts with a number is stored as part of the program instead: + +``` +10 PRINT "HELLO" +20 GOTO 10 +RUN +``` + +- **Ctrl-C** stops a running program. +- **Left** and **Right** move the cursor along the line; **Home** and **End** + (or Ctrl-A and Ctrl-E) jump to its start and end. What you type goes in at + the cursor. +- **Up** brings back the last line you entered, with the cursor at its end. +- **Backspace** rubs out the character before the cursor, **Delete** the one + under it. +- **Ctrl-U** erases the whole line. +- **Enter** takes the whole line, wherever the cursor is. + +Lines can be up to 250 characters. Lower case is accepted and turned into upper +case, except inside quotes. + +### Editing a program + +- To change a line, type its number and press **Right**: each press copies + one more character of the old line, as if you were retyping it. **End** + copies the rest of it at once. While copying, anything you type goes in + as new text, and **Delete** skips a character of the old line, so to + change a word, copy up to it, press Delete once for each old letter, and + type the new one. Enter takes the line as it now stands: whatever has not + been copied yet is left off, so press End first to keep it. If there is no + such line, Right and End do nothing. +- To copy a line to a new number, type the old number, press End, then Home, + Delete the old number and type the new one. +- To replace a line, you can also type it again with the same number. +- To delete a line, type its number alone. + +``` +10 PRINT "HELO" +10→→→→→→→→→→→ copies 10 PRINT "HEL +L End Enter now it is 10 PRINT "HELLO" +``` + +- Lines are kept in number order whatever order you type them in. Number in + tens (10, 20, 30…) to leave room for later additions. +- Changing the program clears all variables. + +| Command | Does | +|---|---| +| `RUN` | Clear variables and run from the first line | +| `RUN 100` | Clear variables and run from line 100 | +| `LIST` | List the whole program (Ctrl-C stops a long listing) | +| `LIST 100` | List line 100 | +| `LIST 100-200` | List lines 100 to 200 (`LIST -200` and `LIST 100-` work too) | +| `RENUM` | Renumber the program 10, 20, 30… (see below) | +| `RENUM 100, 5` | Renumber it 100, 105, 110… | +| `NEW` or `SCRATCH` | Erase the program and all variables | +| `SAVE "NAME"` | Keep the program in the board's flash (section 11) | +| `LOAD "NAME"` | Bring a saved program back | +| `RUN "NAME"` | Load a saved program and run it | +| `DIR` / `DEL "NAME"` | List the saved programs / delete one | +| `DATE "2026-11-28 09:30"` | Set the date and time, which `SAVE` records | + +`RENUM` gives the lines new numbers, starting at 10 (or the first number +given) and going up in tens (or the second). It also changes the line numbers +after `GOTO`, `GOSUB`, `THEN`, `RUN` and `ON … GOTO`/`GOSUB` so the program +runs as before. A number that isn't a line in the program is left alone. +Numbers inside quotes, `REM` and `DATA` are left as they are, and so is a +line number worked out at run time. If the new numbers would pass 65535, or +a line would grow too long or the program run out of memory, `RENUM` stops +with an error and changes nothing. Like any change to the program, it clears +the variables. + +## 2. Program lines + +A program line is a number from 0 to 65535 followed by one or more statements +separated by colons: + +``` +10 FOR I=1 TO 3: PRINT I: NEXT I +``` + +Spaces don't matter outside quotes, as at Dartmouth. `FORI=1TO3` is the same as +`FOR I = 1 TO 3`. `LIST` shows lines as you typed them. + +The program runs in line-number order until it reaches `END`, `STOP`, the last +line, or an error. + +## 3. Numbers, variables and strings + +### Numbers + +All numbers are single-precision floating point: about 7 significant digits, +magnitudes from about 1E-38 to 3E+38. Constants may be written `12`, `-3.5`, +`.25`, `6.02E23` or `1E-6`. + +`PRINT` shows numbers like this: + +- At most 6 significant digits. +- A leading space instead of a plus sign, and a trailing space. +- Whole numbers below a million print without a point. +- Values from .001 to 999999 print as decimals. Anything else uses E + notation, such as `1.23457E+08` or `1E-05`. + +### Numeric variables + +A numeric variable is a letter, or a letter followed by one digit: `X`, `N`, +`A1`, `Z9`. That gives 286 of them. All start at zero when the program is run. + +### Arrays + +An array has a one-letter name and one or two subscripts, both counting from 0. +`DIM` declares its size: + +``` +10 DIM A(100), M(8,8) +``` + +An array used without `DIM` is given room for subscripts 0 to 10. An array and +a plain variable of the same letter are separate: `A` and `A(3)` don't interfere. + +### Strings + +String variables are `A$` to `Z$`. Each holds up to 79 characters and starts +empty. String constants are written in double quotes. `+` joins strings: + +``` +10 A$ = "BASYS" +20 B$ = A$ + " 3" +30 PRINT B$ +``` + +String arrays work like numeric ones, with a `$` after the letter. Each element +holds up to 79 characters and starts empty: + +``` +10 DIM N$(4) +20 FOR I = 0 TO 4: READ N$(I): NEXT I +30 PRINT N$(2) +40 DATA RED, GREEN, BLUE, YELLOW, WHITE +``` + +`N$`, `N$( )` and `N( )` are all separate. A string array used without `DIM` +gets subscripts 0 to 10. Every element takes 80 bytes whether it is used or +not, so a string array can have at most 255 elements, and `DIM A$(200)` uses +about 16 KB of the program space. + +## 4. Expressions + +From highest precedence to lowest: + +| Operators | Meaning | +|---|---| +| `( )` | Grouping | +| `^` | Power: `2^10` is 1024 | +| `-` `+` (unary) | Negation: `-2^2` is -4 | +| `*` `/` | Multiply, divide | +| `+` `-` | Add, subtract | +| `=` `<>` `<` `>` `<=` `>=` | Comparisons (also work on strings) | +| `NOT` | Bitwise not | +| `AND` | Bitwise and | +| `OR` | Bitwise or | + +A comparison gives -1 when true and 0 when false. `AND`, `OR` and `NOT` work +on whole numbers from -32768 to 32767, so they combine comparisons the expected +way: + +``` +IF X > 0 AND X < 10 THEN PRINT "SINGLE DIGIT" +``` + +Strings compare in character order: `"APPLE" < "BANANA"` is true. + +## 5. Statements + +In the descriptions below, square brackets mark something you may leave out. + +### LET — assignment + +``` +LET X = 5 +X = 5 +A$ = "TEXT" +M(I,J) = 0 +``` + +The word `LET` is optional. + +### PRINT — output + +``` +PRINT "X IS"; X +PRINT A, B, C +PRINT "NO NEW LINE"; +PRINT TAB(20); "INDENTED" +PRINT +``` + +- A **comma** moves to the next 15-column zone. +- A **semicolon** prints the next item straight after. +- A **comma or semicolon at the end** keeps the cursor on the same line. +- **`TAB(n)`** moves to column *n*, counting from 0. +- `PRINT` on its own prints an empty line. + +### INPUT — read from the keyboard + +``` +INPUT X +INPUT A, B, C +INPUT "YOUR NAME"; N$ +``` + +`INPUT` prints `? ` (after the prompt, if there is one) and waits for a line. +Separate several values with commas. If you give too few, it asks for the rest +with `?? `. A string can be typed bare or in quotes; quotes are needed if it +contains a comma. Typing something that isn't a number for a numeric variable +gives `?REDO` and asks again. Ctrl-C stops the program. + +`LINE INPUT A$` (or `LINE INPUT "PROMPT"; A$`) takes the whole line into one +string, commas and quotes included, and prints no `? `. + +`PRINT #`, `INPUT #` and `LINE INPUT #` do the same with a file (section 11). + +### IF … THEN — decisions + +``` +IF X > 100 THEN 500 +IF X > 100 GOTO 500 +IF A$ = "YES" THEN PRINT "OK": GOTO 20 +``` + +When the condition is true, `THEN` is followed by a line number to jump to, or +by statements to run. When it is false, the rest of the line is skipped, so +statements after the colon run only when the condition is true. Any non-zero +value counts as true. + +### GOTO, GOSUB, RETURN, ON + +``` +GOTO 100 +GOSUB 1000 +RETURN +ON N GOTO 100, 200, 300 +ON N GOSUB 100, 200, 300 +``` + +- `GOSUB` jumps to a subroutine; `RETURN` comes back to the statement after the + `GOSUB`. Subroutines can nest 32 deep. +- `ON` picks the first line when *N* is 1, the second when it is 2, and so on. + If *N* is out of range, the program carries on with the next statement. + +### FOR … NEXT — loops + +``` +FOR I = 1 TO 10 +FOR X = 0 TO 1 STEP .1 +FOR C = 10 TO 1 STEP -1 +NEXT I +NEXT +NEXT J, I +``` + +- The loop runs while the variable has not passed the limit. `STEP` defaults + to 1 and may be negative or fractional. +- If the starting value is already past the limit, the loop body is skipped + altogether. +- `NEXT` without a name closes the innermost loop. +- Loops nest 16 deep. +- Jumping out of a loop with `GOTO` is allowed. Starting a new `FOR` with the + same variable discards the old loop. + +### DIM — arrays + +``` +DIM A(50), B(10,20), N$(30) +``` + +See section 3. A numeric array can hold at most 6000 elements, a string array +255. + +### DEF FN — your own functions + +``` +10 DEF FNA(X) = X*X + 1 +20 DEF FNR(D) = D * 3.14159 / 180 +30 PRINT FNA(3), SIN(FNR(30)) +``` + +A function has a one-letter name and one numeric argument. Other variables used +in its formula are the program's ordinary variables. + +### READ, DATA, RESTORE + +``` +10 READ N, A$ +20 PRINT A$; N +30 DATA 42, "ANSWER" +40 RESTORE +``` + +`READ` takes values from `DATA` statements in line order, wherever they are in +the program. A `DATA` statement takes up the rest of its line. `RESTORE` starts +again from the first item. + +### END, STOP, REM + +- `END` stops the program quietly. +- `STOP` stops it with the message `STOP IN line`. +- `REM` starts a comment that runs to the end of the line. + +### RANDOMIZE + +`RANDOMIZE` mixes the timer into the random number generator, so each run gives +different numbers. Without it, `RND` produces the same sequence every time the +computer is reset. + +### POKE, OUT, CALL and MONITOR + +``` +POKE address, value +OUT port, value +CALL address +MONITOR +``` + +`CALL` runs machine code at *address* as a subroutine, called the standard +RISC-V way: it must end with `RET` and leave `SP`, `GP`, `TP` and `S0`–`S11` as +it found them (`A0`–`A7` and `T0`–`T6` are free to use). `MONITOR` stops BASIC in the +machine-code monitor (section 10). See section 9 for memory and ports. + +### Graphics and text placement + +`CLS`, `COLOR`, `PLOT`, `LINE`, `RECT`, `FILL`, `CIRCLE`, `LOCATE` and `INK` +are described in sections 7 and 8. + +## 6. Functions + +### Arithmetic + +| Function | Result | +|---|---| +| `ABS(X)` | Absolute value | +| `SGN(X)` | -1, 0 or 1 | +| `INT(X)` | Largest whole number not above *X*: `INT(-2.5)` is -3 | +| `SQR(X)` | Square root | +| `EXP(X)` | e to the power *X* | +| `LOG(X)` | Natural logarithm | +| `SIN(X)`, `COS(X)`, `TAN(X)` | Trigonometry, in radians | +| `ATN(X)` | Arctangent, in radians; `4*ATN(1)` is pi | +| `RND` or `RND(X)` | Random number from 0 up to (not including) 1; *X* is ignored | +| `FNx(X)` | A function made with `DEF` | + +A whole number from 1 to 6: `1 + INT(RND * 6)`. + +### Strings + +| Function | Result | +|---|---| +| `LEN(A$)` | Number of characters | +| `VAL(A$)` | The number written in the string (0 if none) | +| `ASC(A$)` | Code of the first character | +| `CHR$(N)` | The character with code *N* | +| `STR$(X)` | The number as text, with a leading space if positive | +| `LEFT$(A$, N)` | First *N* characters | +| `RIGHT$(A$, N)` | Last *N* characters | +| `MID$(A$, S [, N])` | *N* characters (or the rest) starting at position *S* (from 1) | + +### Machine and screen + +| Function | Result | +|---|---| +| `TIM` | Seconds since the computer was reset, to the millisecond | +| `DATE$` | The date and time as `"2026-11-28 09:30:15"`, or `""` if not set (section 11) | +| `EOF(N)` | -1 (true) when file *N* has been read to the end, else 0 (section 11) | +| `POINT(X, Y)` | Colour of the graphics pixel at *X, Y* (0 off screen) | +| `PEEK(A)` | Byte at memory address *A* | +| `INP(P)` | Byte from I/O port *P* | + +`TIM` is handy for delays and for timing: + +``` +10 T = TIM +20 IF TIM - T < 2 THEN 20 +``` + +## 7. Graphics + +The screen has a graphics layer **320 pixels wide and 240 high in 16 colours**. +It is mixed with the 80×30 text: + +- **Coordinates:** *X* runs from 0 at the left to 319, and *Y* from 0 at the + top to 239. Each graphics pixel is a 2×2 block on the monitor. +- **Mixing with text:** text characters are drawn on top of the graphics. The + graphics show through wherever the text screen is blank. +- **Colour 0** is "no graphics": it shows the text background, normally black. + Drawing in colour 0 erases. +- **Clipping:** anything that falls off the edge is simply not drawn, so a + circle may hang off the screen. +- **Text cells:** in 80 columns a text character covers 4×8 graphics pixels. + The character at row *r*, column *c* (as used by `LOCATE`) starts at + *X* = 4(*c*−1), *Y* = 8(*r*−1). The graphics cover rows 1–30; rows 31 and + 32 are text only. + +### Colours + +| Number | Colour | Number | Colour | +|---|---|---|---| +| 0 | None / black | 8 | Dark grey | +| 1 | Red | 9 | Bright red | +| 2 | Green | 10 | Bright green | +| 3 | Brown | 11 | Yellow | +| 4 | Blue | 12 | Bright blue | +| 5 | Magenta | 13 | Bright magenta | +| 6 | Cyan | 14 | Bright cyan | +| 7 | Light grey | 15 | White | + +### Graphics statements + +In every drawing statement the colour is optional. Without it, the colour set +by `COLOR` is used, initially 15 (white). + +| Statement | Draws | +|---|---| +| `CLS` | Clears the text screen and the graphics, cursor to the top left | +| `COLOR C` | Sets the drawing colour for later statements | +| `PLOT X, Y [, C]` | One pixel | +| `LINE X1, Y1, X2, Y2 [, C]` | A straight line between two points | +| `RECT X1, Y1, X2, Y2 [, C]` | The outline of a rectangle with those corners | +| `FILL X1, Y1, X2, Y2 [, C]` | A solid rectangle | +| `CIRCLE X, Y, R [, C]` | A circle centred on *X, Y* with radius *R* | + +`POINT(X, Y)` reads a pixel back (section 6). + +``` +10 CLS +20 FILL 0, 200, 319, 239, 2 +30 CIRCLE 260, 40, 25, 11 +40 FOR I = 0 TO 6 +50 LINE 60 + I*30, 200, 75 + I*30, 140, 3 +60 NEXT I +70 RECT 20, 120, 300, 230, 7 +``` + +### Animation + +Erase something by drawing it again in colour 0, then draw it in its new +place. Use `TIM` to set the pace: + +``` +10 CLS: X = 0 +20 CIRCLE X, 120, 10, 0 +30 X = X + 2: IF X > 319 THEN X = 0 +40 CIRCLE X, 120, 10, 14 +50 T = TIM +60 IF TIM - T < .02 THEN 60 +70 GOTO 20 +``` + +### Sprites + +Sprites are small pictures that the hardware draws over the graphics wherever +you put them. To move one, give it a new position: nothing needs erasing or +redrawing, nothing flickers, and the computer does no drawing work. They are what +moving things in a game should be made of. + +- **32 sprites**, numbered 0–31, each 16 × 16 graphics pixels. +- **64 shapes**, numbered 0–63, that the sprites show. Several sprites can + show the same shape. +- **Colours:** each pixel of a shape is one of the 16 colours; colour 0 is + see-through. +- **Layers:** sprites are in front of the graphics and behind the text. Where + sprites overlap, the lower number is in front. +- **Collisions:** the hardware notices when a sprite touches another sprite, + or touches a graphics pixel that isn't colour 0. + +BASIC drives them with `OUT` and `INP`: + +| Port | `OUT` | `INP` | +|---|---|---| +| 112 | Pick sprite *n* (0–31) for ports 113–117 | — | +| 113, 114 | X: `X AND 255`, then `INT(X / 256)` | — | +| 115 | Y; the sprite moves to the new X and Y together | — | +| 116 | Shape (0–63) | — | +| 117 | 1 = show, 0 = hide; add 2 to flip left-right, 4 to flip upside down | — | +| 118 | Start defining shape *n* (0–63) | — | +| 119 | The next two pixels of the shape: 16 × left colour + right colour | — | +| 120 | — | Frame counter: goes up by one 60 times a second, as each picture is finished | +| 128–131 | — | Sprites that touched another sprite in the last frame: 128 has a bit for sprites 0–7 (1, 2, 4 … 128), 129 for 8–15, 130 for 16–23, 131 for 24–31 | +| 132–135 | — | The same for sprites that touched the graphics | + +**Defining a shape.** `OUT 118, n` and then 128 `OUT 119`s: the 16 rows from +the top, each as 8 bytes of two pixels. A shape stays defined until the power +goes off, even through `NEW`, so define it once. + +**Placing a sprite.** X and Y are its top-left pixel, the same as for `PLOT`. +X can go from 0 to 511 and Y from 0 to 255; values past the edge wrap round, so +X = 500 puts the sprite 12 pixels off the left edge, half showing. + +``` +10 CLS +20 OUT 118, 0: FOR I = 1 TO 128: OUT 119, 204: NEXT I : REM SHAPE 0: COLOUR 12 +30 OUT 112, 0: OUT 116, 0: OUT 117, 1 : REM SPRITE 0 SHOWS IT +40 FOR X = 0 TO 304 +50 OUT 112, 0: OUT 113, X AND 255: OUT 114, INT(X / 256): OUT 115, 100 +60 F = INP(120) +70 IF INP(120) = F THEN 70 : REM WAIT FOR THE NEXT FRAME +80 NEXT X +``` + +Waiting for the frame counter to change, as in lines 60–70, keeps movement +smooth: one step per frame, 60 a second. + +**Collisions.** `IF INP(128) AND 1 THEN …` asks whether sprite 0 touched +another sprite in the last frame; `INP(132) AND 1` whether it touched the +graphics, such as a wall drawn with `FILL`. A collision only counts where +pixels that aren't colour 0 overlap, so the see-through corners of a round +shape don't count. + +**Turning them off.** `CLS` hides every sprite (the shapes are kept), and so +does restarting the computer. `OUT 117, 0` hides the picked one. + +`basic/examples/sprites.bas` is a complete example: a robot steered with +W A S D among bouncing balls, with shapes written as rows of hex digits. + +### Scrolling + +The hardware can scroll the graphics: it shows them starting from any point of +the 320 × 240 picture, wrapping round at the edges, so the whole picture moves +without anything being redrawn. Sprites and text don't move with it. + +| Port | `OUT` | +|---|---| +| 53 | X of the picture to show at the left edge, `X AND 255` | +| 54 | `INT(X / 256)`, plus 2 to hide the edges (below) | +| 55 | Y of the picture to show at the top, 0–239 | + +``` +10 CLS: FOR I = 0 TO 15: FILL I * 20, 0, I * 20 + 19, 239, I: NEXT I +20 FOR X = 0 TO 319 +30 OUT 53, X AND 255: OUT 54, INT(X / 256) +40 F = INP(120) +50 IF INP(120) = F THEN 50 +60 NEXT X +``` + +A program that scrolls a long scene has to draw the strip that comes into view +at one edge each time. To do that unseen, add 2 to the value sent to port 54: +the graphics are then hidden in a border, 4 pixels wide at the sides and 2 at +the top and bottom, and the new strip can be drawn there while it is hidden. +Bastion Raid (section 14) works this way. `PLOT`, `LINE` and the rest still use +the picture's own coordinates. `CLS` puts the scroll back to 0 and turns the +border off. + +### Speed + +`CLS` clears the graphics in under a millisecond, and a line right across the +screen takes about 2 milliseconds. `FILL` is the fastest way to cover a large +area. Most of the time in a graphics program goes on BASIC itself working out +the numbers (see section 9). + +## 8. The text screen + +The text screen is 80 columns by 32 rows; `PRINT CHR$(27);"[?3h"` switches to +132 columns by 64 rows in a smaller font (and clears it), `CHR$(27);"[?3l"` +back. Two statements place and colour text: + +| Statement | Does | +|---|---| +| `LOCATE R, C` | Moves the cursor to row *R* (1–32, or 1–64), column *C* (1–80, or 1–132) | +| `INK F [, B]` | Sets the text colour *F* and, optionally, background *B*, using the colour numbers above | + +``` +10 CLS +20 INK 14: LOCATE 15, 35: PRINT "CENTRED" +30 INK 0, 11: LOCATE 16, 35: PRINT " BLACK ON YELLOW " +``` + +The terminal is a full VT220 with ANSI colour, so anything it understands can be +printed with `CHR$(27)`. For example, `PRINT CHR$(27);"[0m"` returns to normal +colours, `PRINT CHR$(27);"[4m"` turns on underlining, and +`PRINT CHR$(27);"[2K"` erases the current line. + +When the cursor passes the bottom row the text scrolls. The graphics layer +stays where it is. With **SW8** up the scroll is smooth but held to 7.5 lines a +second (15 with SW9 up as well), which slows down long listings; flip SW8 down +for full speed. + +## 9. The machine + +### Memory + +| Addresses | Contents | +|---|---| +| 00000–09FFF | BASIC itself (writes here are ignored) | +| 0A000–0F0B7 | Your program and arrays (machine-code games load at 0A200h, 41472) | +| 0F0B8–11FFF | BASIC's variables and file buffers | +| 12000–12FFF | Free for your machine code (4 KB); BASIC never uses it | +| 13000–13FF7 | The stack | +| 13FF8–13FFF | The clock set by `DATE` | +| 20000–27FFF | The monitor (section 10); writes are ignored | +| 28000–29FFF | The monitor's variables | +| FFFFFE00–FFFFFEFF | 32-bit hardware registers (below) | +| FFFFFF00–FFFFFFFF | The I/O ports: port *N* is at FFFFFF00h + *N* | + +`PEEK` can read anything; `POKE` can change RAM from 0A000h up, including +BASIC's own data, so put machine code at **12000h (73728) to 12FFFh**, which is +kept free for it. Memory is byte-addressed and instructions are 4 bytes, low +byte first. + +The I/O ports below are also memory: `INP(P)` is `PEEK(-256 + P)` and `OUT P, V` +is `POKE -256 + P, V`. Machine code reaches a port in one instruction, relative +to register `ZERO`: `LBU A0,-256(ZERO)` reads port 0 and `SB A0,-255(ZERO)` +writes port 1. The 32-bit registers at FFFFFE00h + *N* (machine code only) are: +0 milliseconds since reset, 4 microseconds since reset, 8 the timer interrupt's +compare value, 10h and 14h the monitor's breakpoint addresses. + +### I/O ports + +| Port | `INP` | `OUT` | +|---|---|---| +| 0 | bit 0: a key is waiting; bit 1: the screen can take a character | — | +| 1 | the waiting key | a character to the screen | +| 16–19 | the millisecond counter, low byte first (reading 16 freezes the other three) | — | +| 32 | — | right two digits of the 7-segment display (hex) | +| 33 | — | left two digits of the 7-segment display | +| 48, 49, 50 | — | graphics X (low byte, high bit), Y | +| 51 | colour at X, Y | plot a pixel at X, Y and move right | +| 52 | bit 0: screen fill in progress | fill the whole graphics layer with a colour; also hides the sprites and resets the scroll, unless 128 is added | +| 53, 54, 55 | — | graphics scroll and border (section 7) | +| 64 | bit 0: flash byte in progress; bit 1: last flash command refused | 1 selects the flash and starts a command, 0 ends it | +| 65 | the byte the flash sent back during the last `OUT 65` | a byte to the flash | +| 96 | why the monitor was entered (used by the monitor) | single step (used by the monitor) | +| 97 | — | enter the monitor (what `MONITOR` does) | +| 103 | — | breakpoints on and off (used by the monitor) | +| 112–120, 128–135 | sprites (section 7) | sprites (section 7) | +| 136 | keys held down, for games (below) | — | +| 137 | 1 if the key picked with `OUT 137` is held down, else 0 | pick a key by its scan code | +| 144–157 | voice volumes now (152–154) | sound (below) | + +``` +10 FOR I = 0 TO 255 +20 OUT 32, I: OUT 33, 255 - I +30 T = TIM +40 IF TIM - T < .05 THEN 40 +50 NEXT I +``` + +A key check that doesn't wait (the key is used up): + +``` +100 IF INP(0) AND 1 THEN K = INP(1): PRINT "YOU PRESSED "; CHR$(K) +``` + +### Keys held down + +Typed characters can't tell a game that a key is being *held*: they arrive +once, then repeat only after a pause. Ports 136 and 137 read the keyboard +directly instead, for as long as a key is down. + +`INP(136)` adds up these values for the keys held now: + +| Value | Keys | +|---|---| +| 1 | up: W, cursor up or keypad 8 | +| 2 | down: S, cursor down or keypad 2 | +| 4 | left: A, cursor left or keypad 4 | +| 8 | right: D, cursor right or keypad 6 | +| 16 | fire: Space or either Ctrl | +| 32 | Enter | +| 64 | either Shift | +| 128 | Esc | + +``` +10 J = INP(136) +20 IF J AND 4 THEN X = X - 1 +30 IF J AND 8 THEN X = X + 1 +40 IF J AND 16 THEN PRINT "BANG" +``` + +For any other key, `OUT 137` its PS/2 scan code (set 2; add 128 for keys whose +code starts with E0), then `INP(137)` is 1 while it is held: `OUT 137, 77: +IF INP(137) THEN …` checks P. The keys still type characters as well, so a +game should throw those away now and then with `IF INP(0) AND 1 THEN K = +INP(1)` in a loop. Held keys only work with the board's own keyboard, not with +characters sent from the PC. + +### Sound + +The board has no speaker of its own. Plug a Digilent **PmodAMP2** into the +top row of Pmod header **JA** (pin 1 at the end marked 1) and headphones or a +powered speaker into its jack. The FPGA has a little sound chip in the style +of the 8-bit computers: three voices that play square-wave tones, a noise +source they can use instead or as well, sixteen volumes and an envelope for +each voice, so a note or a bang fades away by itself. + +| Port | `OUT` | +|---|---| +| 144, 145 | voice 0 pitch: low byte, then high byte (0–15) | +| 146, 147 | voice 1 pitch | +| 148, 149 | voice 2 pitch | +| 150 | noise pitch, 0–31 (higher is lower and rougher) | +| 151 | mixer: add 1, 2, 4 for the tone of voice 0, 1, 2 and 8, 16, 32 for noise on voice 0, 1, 2 | +| 152, 153, 154 | voice 0, 1, 2 volume, 0 (off) to 15, which starts its envelope; `INP` gives the volume it has got to | +| 155, 156, 157 | voice 0, 1, 2 envelope: attack × 16 + decay, each 0–15 | + +- **Pitch** = 125000 ÷ frequency: 284 is the A above middle C (440 Hz), + 477 middle C. Each voice goes from about 30 Hz up beyond hearing. +- **Envelope:** with an attack, the volume climbs from 0 to the volume set, + one step every attack × 4 ms; then, with a decay, it falls back to 0 one step + every decay × 4 ms. 0 means no climb, or hold the volume until it is + changed. An envelope of 3 plays a short note; 8 with noise is an explosion. +- **Waiting for a sound to end:** `IF INP(152) > 0 THEN …` loops until voice + 0 has faded out. +- A voice that has neither its tone nor noise on in the mixer gives a steady + level, so changing its volume clicks; that is how the old chips played + samples. +- `CLS` silences everything (as does restarting the computer). + +``` +10 OUT 151, 1: OUT 155, 3 : REM TONE ON VOICE 0, A SHORT NOTE +20 OUT 144, 28: OUT 145, 1: OUT 152, 15 : REM PITCH 284 = 440 HZ +``` + +`basic/examples/sound.bas` plays a scale, a laser, an explosion and a chord. + +### Speed + +The processor is a 32-bit RISC-V (RV32IM: the base instructions plus +multiply and divide) running at 90 MHz. Most instructions take 2 clocks; loads, +stores, jumps and taken branches 3, a multiply 4 and a divide 35, which comes to +about 2.5 clocks per instruction in BASIC, some 36 million instructions a +second. BASIC does its floating-point arithmetic in software, so in round +numbers: + +| Operation | Time | +|---|---| +| One pass of an empty `FOR … NEXT` loop | 9 µs (about 100,000 a second) | +| `X = I * 1.5` | 43 µs | +| `Y = SIN(X)` | 85 µs | +| `LINE` right across the screen | 0.2 ms | + +Constants in a program are converted from text every time they are used, so a +loop runs a little faster if a constant used inside it is put into a variable +first. + +## 10. The machine-code monitor + +The monitor stops the processor wherever it is and shows what it is doing: +the registers, the instructions at the program counter, the stack and a window +of memory. From there you can step through the program one instruction at a +time, set a breakpoint, change memory and registers, and carry on. It works on +any code, including BASIC itself. + +### Getting in and out + +- Press **Pause/Break** on the keyboard at any time, even when a program has + hung, or type `MONITOR` in BASIC. +- A breakpoint or a single step also comes back to the monitor. +- So does a program that goes wrong: an illegal instruction, a misaligned load, + store or jump, an `EBREAK` or `ECALL`, or an interrupt with no handler. The + title line says which (`STOPPED BY ILLEGAL INSTRUCTION`). After `EBREAK` and + `ECALL` the PC is already past them, so `X` carries on. +- `X` (or `G`) carries on from where the program stopped. + +The monitor has a screen of its own: when you leave, BASIC's screen and the +graphics come back exactly as they were. + +``` + RISC-V MONITOR STOPPED BY BREAKPOINT + PC 00012000 RA 000058B4 SP 00013F70 GP 0001189C TP 00000000 T0 00000000 + T1 00000000 T2 00000000 S0 00013FB0 S1 0000A01E A0 00000000 A1 00012000 + ... + ADDR WORD INSTRUCTION STACK +>*12000 04100513 LI A0,65 13F70 00000000 + 12004 F0A000A3 SB A0,-255(ZERO) 13F74 0000A01E + 12008 00008067 RET ... + MEMORY + 12000 13 05 10 04 A3 00 A0 F0-67 80 00 00 00 00 00 00 ....g........... +``` + +- The registers are the PC and X1–X31 by their usual names (RA, SP, GP, TP, + T0–T6, S0–S11, A0–A7); X0 (ZERO) is always 0. +- `>` marks the next instruction, which is also highlighted, and `*` the + breakpoint. +- The stack column shows the words at SP upwards. + +### Commands + +Type a command on the bottom line and press Enter. Numbers are in hex. + +| Command | Does | +|---|---| +| Enter (empty line) or `S` | Run one instruction | +| `S n` | Run *n* instructions, showing only the last | +| `O` | Step over: run a call (`JAL` or `JALR` that saves its return address in RA) until it returns, otherwise one step | +| `G` or `X` | Carry on (stopping at the breakpoint, if set) | +| `G addr` | Carry on from *addr* | +| `B addr` | Set the breakpoint; `B` alone clears it | +| `D addr` | Show the disassembly from *addr* (`D` alone: from PC) | +| `M addr` | Show memory from *addr* | +| `E addr bytes…` | Write bytes into memory: `E 12000 13 05 10 04` | +| `R reg=value` | Set PC or a register, by name or number: `R A0=1234`, `R X10=1234` | +| `SAVE "NAME" start end` | Save memory *start* to *end* (inclusive) to a file in flash | +| `LOAD "NAME"` | Load a memory file back to where it was saved from | +| `LOAD "NAME" addr` | Load it at *addr* instead (0A000h or above) | +| `DIR` | List the files in flash in the memory window (`M` brings the memory back) | +| `ASM "NAME"` | Assemble a source file into memory (see the assembler, below) | +| `A addr` | Assemble lines as you type them, from *addr*; an empty line ends | +| Up / Down | Scroll the disassembly by one instruction | +| Page Up / Page Down | Scroll the memory window | +| `?` | A short reminder of the commands | +| `:` *record* | An Intel HEX record, written into memory (`tools/send-hex.py` sends whole files this way; see section 12) | + +- **Stepping** runs exactly one instruction of the program. The hardware + counts it, so stepping works on code in ROM as well as RAM. +- **The breakpoint** is checked by hardware as each instruction starts, so it + also works in ROM and costs no speed. When you carry on from the breakpoint + itself, the monitor first steps past it. +- **Memory below 0A000h** is BASIC's ROM and can be viewed but not changed. `E` + says so if you try. +- **The disassembler** shows every RV32IM instruction and the CSR and system + instructions, using the usual short forms where they apply (`LI`, `MV`, `J`, + `RET`, `BEQZ`, `CSRR` and so on), with hex numbers like `1F0H` and `0A200H`; + anything else is shown as `DW` and its value. + +### A machine-code example + +``` +10 FOR I = 0 TO 11: READ B: POKE 73728 + I, B: NEXT I +20 DATA 19,5,16,4, 163,0,160,240, 103,128,0,0 +RUN +MONITOR +``` + +The `POKE`s put `LI A0,65 : SB A0,-255(ZERO) : RET` at 12000h; it prints an +`A` (port 1 is at -255 from address 0). In the monitor, `B 12000` then `X`. +Back in BASIC, `CALL 73728` stops at the breakpoint. Press Enter to step +through each instruction, or `X` to let it finish. + +### The assembler + +The monitor can assemble RISC-V source code into memory, either a whole file +or one line at a time. + +**Writing source.** Type it into BASIC as numbered lines, just like a +program, and save it. BASIC doesn't run it; it just keeps the lines. The +assembler ignores the line numbers, and uses them in its error messages. + +``` +NEW +10 ; PRINT A MESSAGE +20 ORG 12000H +30 START: LA A1,MSG +40 LOOP: LBU A0,0(A1) +50 BEQZ A0,DONE +60 WAIT: LBU T0,-256(ZERO) ; CAN THE SCREEN TAKE A CHARACTER? +70 ANDI T0,T0,2 +80 BEQZ T0,WAIT +90 SB A0,-255(ZERO) +100 ADDI A1,A1,1 +110 J LOOP +120 DONE: RET +130 MSG: DB "HELLO FROM ASSEMBLY",13,10,0 +SAVE "HELLO" +``` + +A text file sent from the PC with `tools/send-bas.py` works the same way, as +long as each line starts with a number. + +**Assembling.** `MONITOR`, then `ASM "HELLO"`. The monitor says +`ASSEMBLED 12000-12041` and shows the code; errors are listed in the memory +window with their line numbers. Back in BASIC (`X`), `CALL 73728` runs it. +Or set a breakpoint first and step through it. + +**One line at a time.** `A 12100` starts the line assembler at 12100h: type +an instruction, press Enter, and it is assembled and shown, then the next +address is offered. An empty line ends. Labels from the last `ASM` can be used. + +**Syntax**: as the disassembler shows it. + +| | | +|---|---| +| Labels | `NAME:` before an instruction, up to 8 letters and digits; `NAME EQU value` for constants | +| Numbers | `123`, `0FFH`, `$FF`, `0x1F`, `1010B`, `'A'`; `$` alone is the current address | +| Expressions | `+ - * / & |` and brackets: `LI A0,END-START`, `LI A1,'Z'-1` | +| Registers | `X0`–`X31` or `ZERO RA SP GP TP T0`–`T6 S0`–`S11 FP A0`–`A7` | +| Memory operands | *offset*`(`*register*`)`: `LW A0,8(SP)`, `SB A0,-255(ZERO)`, `LBU T0,(A1)` | +| CSRs | by name (`MSTATUS`, `MEPC`, `MCAUSE`, `CYCLE`, `TIME`, `INSTRET`, …) or number | +| `ORG addr` | assemble from *addr* (12000h if there is no `ORG`) | +| `DB` / `DEFB` / `DEFM` | bytes and `"strings"`: `DB "HI",13,10,0` | +| `DH` | 16-bit halfwords, low byte first | +| `DW` / `DEFW` | 32-bit words, low byte first | +| `DS n` / `DEFS n` | skip *n* bytes | +| `ALIGN n` | skip to a multiple of *n* (instructions must be on a multiple of 4) | +| `END` | stop here | +| `;` | comment to the end of the line | + +- **Instructions:** all of RV32I and M, `CSRRW`…`CSRRCI`, `ECALL`, `EBREAK`, + `MRET`, `MNRET`, `WFI`, `FENCE`, `FENCE.I`, and the short forms `NOP`, `LI`, + `LA`, `MV`, `NOT`, `NEG`, `SEQZ`, `SNEZ`, `SLTZ`, `SGTZ`, `J`, `JR`, `JAL` + *target* (saving RA), `JALR` *register*, `RET`, `CALL`, `BEQZ`, `BNEZ`, + `BLEZ`, `BGEZ`, `BLTZ`, `BGTZ`, `BGT`, `BLE`, `BGTU`, `BLEU`, `CSRR`, `CSRW`, + `CSRS`, `CSRC`, `CSRWI`, `CSRSI`, `CSRCI`. +- **`LI`** is one instruction (`ADDI`) for a value from −2048 to 2047 that is + known by then, otherwise two (`LUI`, `ADDI`); **`LA`** is always two + (`AUIPC`, `ADDI`); **`CALL`** is `JAL RA`, which reaches 1 MB either way. +- **Where code can go:** RAM from 0A000h up. 12000h–12FFFh is the safe place, + since BASIC doesn't use it. +- **Labels:** up to 200. +- **Typing source into BASIC:** BASIC turns lower case to upper case (except + inside double quotes), so `'a'` becomes `'A'`. Indentation after the line + number isn't kept, so labels need their colon. + +**Errors:** `UNKNOWN INSTRUCTION`, `BAD REGISTER`, `MISSING OPERAND`, `TOO +MANY OPERANDS`, `OFFSET(REGISTER)`, `UNDEFINED LABEL`, `DUPLICATE LABEL`, +`VALUE OUT OF RANGE` (an immediate, offset or `LUI` value that doesn't fit), +`BRANCH TOO FAR` (beyond ±4 KB), `JUMP TOO FAR` (beyond ±1 MB), `NOT ON A +WORD: USE ALIGN 4`, `CAN'T WRITE THERE`, `BAD NUMBER`, `BAD EXPRESSION`. + +### How it works + +Pause, `MONITOR`, a breakpoint or a single step raises the processor's +non-maskable interrupt (NMI); a trap with nowhere else to go comes to the same +place, because BASIC points the trap vector (`mtvec`) at the monitor. + +1. **Entry:** the NMI saves the program counter in `mnepc` and jumps to the + monitor at 20000h, which saves every register and shows them. NMIs are + switched off while the monitor runs. +2. **Memory:** the monitor runs from its own 32 KB of ROM at 20000h, with its + variables at 28000h, so it reads the program's memory directly and takes + none of BASIC's. +3. **Leaving:** the monitor puts the registers back and returns with `MNRET`. + To single-step, it first tells the hardware to raise the NMI again after + one instruction of the program has run. + +## 11. Files in the flash + +The board's configuration flash has room for files next to the bitstream it +boots from: saved programs, and data files that programs write and read. They +stay there when the power is off. + +### Saving programs + +| Command | Does | +|---|---| +| `SAVE "NAME"` | Write the program to flash, replacing any saved program with that name | +| `LOAD "NAME"` | Erase the program in memory and read the saved one in its place | +| `RUN "NAME"` | `LOAD` it, then run it | +| `DIR` | List the saved programs with their sizes in bytes, and the free space | +| `DEL "NAME"` | Delete a saved program | + +``` +SAVE "SPIRO" +DIR +SPIRO 212 2026-11-28 09:30 +1 FILE, 1780K FREE +``` + +- Names are 1 to 8 letters and digits; lower case becomes upper case. The name + can be any string expression, so `SAVE N$` works. +- Up to 64 files, 1,784 KB in all. A program is saved as its listing, in 4 KB + blocks; a file can use at most 8 blocks (32 KB). +- Variables aren't saved, and `LOAD` clears them. +- Each block is read back and checked after it is written. +- If the power goes off while saving, you keep the old version of that file: + the new copy is written to free space first and the list of files is + switched over to it last. +- `DIR` lists programs and data files alike; `LOAD` of a data file keeps only + its lines that start with a number. + +### The date + +`DIR` shows the date and time each file was created. Saving over a file keeps +its original date. + +The board has no clock that runs with the power off, so BASIC only knows the +date once it has been told, and keeps time from then until the computer is +restarted (**BTND**, **BTNC**, power-off or reprogramming). + +| | | +|---|---| +| `DATE "2026-11-28 09:30"` | Set the date and time (seconds optional: `"2026-11-28 09:30:15"`; the time is optional too) | +| `DATE` | Print the date and time, or `DATE NOT SET` | +| `DATE$` | The date and time as a string, `""` if not set | + +`send-bas.py` and `get-bas.py` set it from the PC's clock each time they +connect (section 12; `--no-date` stops them). A file saved before the date is set has no date in +`DIR`, and gets one when it is next saved after the date is set. + +``` +PRINT "TODAY IS "; LEFT$(DATE$, 10) +``` + +### Memory files + +A memory file holds a block of memory, for machine code or data: its address +(4 bytes, low first) followed by the bytes. The +monitor's `SAVE`/`LOAD` (section 10) and BASIC's statements below read and write +the same files. + +| Statement | Does | +|---|---| +| `BSAVE "NAME", start, length` | Save *length* bytes from *start* | +| `BLOAD "NAME"` | Load them back to the address they came from | +| `BLOAD "NAME", address` | Load them at *address* instead | + +``` +BSAVE "CODE", 73728, 12 +BLOAD "CODE", 74240: CALL 74240 +``` + +Only RAM from 0A000h up can be loaded into. A memory file is up to 32 KB. +Don't `LOAD` one as a program: it isn't text. + +### Data files + +A program can write text to a file and read it back, with up to three files +open at once, numbered 1 to 3. + +| Statement | Does | +|---|---| +| `OPEN "NAME" FOR OUTPUT AS #1` | Start a new file (replacing any file of that name when it is closed) | +| `OPEN "NAME" FOR APPEND AS #1` | Add to the end of a file (or start it if there isn't one) | +| `OPEN "NAME" FOR INPUT AS #1` | Read a file from the start | +| `PRINT #1, items` | Write, just as `PRINT` writes to the screen | +| `INPUT #1, A, B$` | Read values separated by commas or line ends | +| `LINE INPUT #1, A$` | Read a whole line | +| `EOF(1)` | -1 once everything has been read | +| `CLOSE #1` | Finish with a file; `CLOSE` alone closes them all | + +The `#` is optional everywhere, and the name can be any string expression. + +``` +10 OPEN "SCORES" FOR OUTPUT AS #1 +20 FOR I = 1 TO 5 +30 PRINT #1, "PLAYER"; I; ","; I * 100 +40 NEXT I +50 CLOSE #1 +60 OPEN "SCORES" FOR INPUT AS #1 +70 IF EOF(1) THEN CLOSE #1: END +80 INPUT #1, N$, S +90 PRINT N$, S +100 GOTO 70 +``` + +- A file written with `OUTPUT` or `APPEND` only appears, or changes, when it is + closed. Until then `DIR` and other readers see the old version, and a power + cut leaves the old version. `END`, the end of the program, `RUN`, `NEW`, + `LOAD` and `BYE` close every open file; an error or Ctrl-C doesn't, so the + file can still be closed by hand. +- `PRINT #` writes exactly what `PRINT` would show, so numbers have their + spaces, and the separator for `INPUT #` must be written as `","` as above. + A string that contains a comma needs quotes around it for `INPUT #`, or read + it with `LINE INPUT #`. +- `APPEND` copies the file's last part-filled 4 KB block to a new one; the full + blocks are shared with the old version, so appending to a big file is quick. +- Lines are separated by a single line feed (code 10). + +The flash also holds the bitstream the board starts from. The hardware refuses +to erase or write anything below the area kept for programs, so no program can +stop the board from starting, even one that sends commands to the flash itself +with `OUT` (ports 64 and 65, section 9). + +## 12. Programs on the PC + +Programs can also be kept as plain text files on the PC, one numbered line per +line. SW14 links the PC's serial port to the computer: what the PC sends is typed +into BASIC, and what BASIC prints is also sent back to the PC. The tools need: + +1. **SW15** and **SW14** up. +2. Nothing else using the serial port. A login getty on it is worse than in the + way: it takes BASIC's output for login names and its "Login incorrect" + replies are typed back into BASIC, round and round. Keep it off until the + next reboot with: + ``` + sudo systemctl mask --runtime serial-getty@ttyUSB1 + sudo systemctl stop serial-getty@ttyUSB1 + ``` + If the port is then only open to root (`ls -l /dev/ttyUSB1`), the getty left + it that way; `sudo chmod 666 /dev/ttyUSB1` opens it again. +3. The baud rate set by SW1:0: `00` 115200, `01` 9600, `10` 921600, `11` + 3,000,000. The tools take `--baud` with any of these; 3,000,000 is the + fastest and works fine, since the board paces the PC with XON/XOFF. The + examples below use 9600. + +**Sending a program to the board:** + +``` +tools/send-bas.py basic/examples/graphics-demo.bas --baud 9600 --run +``` + +This sends `NEW`, then the program, then `RUN`. Leave out `--run` to only load +it, and add `--keep` to merge it into the program already there. Pasting into a +terminal program such as `picocom` works too. + +**Copying the program in memory to the PC:** + +``` +tools/get-bas.py myprog.bas --baud 9600 +``` + +**Running a command and seeing the answer on the PC:** + +``` +tools/get-bas.py --baud 9600 --cmd 'DIR' --cmd 'LOAD "SPIRO"' --cmd 'LIST' +``` + +`--cmd` can be repeated; each one waits for `READY` (up to `--timeout` +seconds, 30 by default). Program lines typed this way get no `READY`, so they +take the full timeout each; use `send-bas.py` for those. + +**Sending machine code compiled on the PC:** + +``` +tools/send-hex.py prog.ihx --save PROG --baud 3000000 +``` + +This enters the monitor, sends the Intel HEX file (as `objcopy -O ihex` and +most assemblers write it) a record at a time, saves the bytes as the memory +file `PROG`, and goes back to BASIC. `BLOAD "PROG"` then loads it where it was +compiled for. It must be at 0A000h or above. That's how The Iron Keep +(section 14) gets onto the board. + +When you're done, flip SW14 back down, and bring the getty back with +`sudo systemctl unmask --runtime serial-getty@ttyUSB1` (a reboot does it too). +Don't do that with SW14 up. + +## 13. Error messages + +An error stops the program and reports the line, for example +`?DIVISION BY ZERO IN 120`. + +| Message | Cause | +|---|---| +| `SYNTAX ERROR` | A statement BASIC can't make sense of | +| `UNDEFINED LINE NUMBER` | `GOTO`, `GOSUB`, `THEN` or `RUN` to a line that doesn't exist | +| `RETURN WITHOUT GOSUB` | `RETURN` with no `GOSUB` to go back to | +| `NEXT WITHOUT FOR` | `NEXT` with no loop open (or the wrong variable) | +| `OUT OF DATA` | `READ` after the last `DATA` item | +| `SUBSCRIPT OUT OF RANGE` | An array subscript below 0 or beyond its `DIM` | +| `DIVISION BY ZERO` | Dividing by 0 | +| `OUT OF MEMORY` | The program and arrays don't fit | +| `TYPE MISMATCH` | A string where a number belongs, or the other way round | +| `STRING TOO LONG` | A string over 79 characters, or a program line too long to store (also from `RENUM`) | +| `ILLEGAL FUNCTION CALL` | A bad argument: `SQR(-1)`, `LOG(0)`, a colour over 15, `AND` on a number beyond ±32767, a file number other than 1–3, an impossible `DATE`, a `RENUM` past 65535 or with a step of 0 | +| `UNDEFINED FUNCTION` | `FNx` used before its `DEF` | +| `FOR NESTED TOO DEEPLY` | More than 16 loops open | +| `GOSUB NESTED TOO DEEPLY` | More than 32 subroutines in progress | +| `FILE NOT FOUND` | `LOAD`, `RUN` or `DEL` of a name not in `DIR` | +| `BAD FILE NAME` | A name that is empty, longer than 8 or not just letters and digits | +| `DISK FULL` | Not enough free flash for the program | +| `TOO MANY FILES` | 64 programs are saved already | +| `FILE TOO BIG` | A program listing or data file over 32 KB | +| `FILE ALREADY OPEN` | `OPEN` with a number that is already in use | +| `FILE NOT OPEN` | `PRINT #`, `INPUT #`, `LINE INPUT #` or `EOF` on a number that isn't open that way | +| `INPUT PAST END` | `INPUT #` or `LINE INPUT #` after the last line | +| `FLASH ERROR` | The flash didn't answer, or read back wrong after writing | +| `BREAK IN n` | You pressed Ctrl-C | +| `STOP IN n` | The program ran `STOP` | + +## 14. Example programs + +### Times table + +``` +10 FOR I = 1 TO 9 +20 FOR J = 1 TO 9 +30 PRINT TAB(J*5); I*J; +40 NEXT J +50 PRINT +60 NEXT I +``` + +### Guess the number + +``` +10 RANDOMIZE +20 N = 1 + INT(RND * 100): G = 0 +30 PRINT "I'M THINKING OF A NUMBER FROM 1 TO 100." +40 INPUT "YOUR GUESS"; X +50 G = G + 1 +60 IF X < N THEN PRINT "HIGHER": GOTO 40 +70 IF X > N THEN PRINT "LOWER": GOTO 40 +80 PRINT "RIGHT IN"; G; "GUESSES!" +``` + +### Spirograph + +``` +10 CLS: C = 1 +20 FOR A = 0 TO 6.283 STEP .0628 +30 X = 160 + 100*COS(A) + 15*COS(A*7) +40 Y = 120 + 100*SIN(A) - 15*SIN(A*7) +50 IF A > 0 THEN LINE U, V, X, Y, C +60 U = X: V = Y: C = C + 1: IF C > 15 THEN C = 1 +70 NEXT A +``` + +### The graphics demo + +`basic/examples/graphics-demo.bas` shows everything in turn. It draws colour +bars, circles, a burst of lines, sine and cosine curves, random rectangles, a +bouncing ball and a Mandelbrot set, then prints how long it all took. + +### The Iron Keep + +A game in machine code. You are a prisoner in a castle of twelve rooms: +steal the king's crown from the throne room and escape down the stairs. +Guards patrol, and shoot when they can see you along a row or column of the +castle; some come after you. Keys open locked doors, chests hold gold, crates +hold ammunition. You have three lives. + +``` +RUN "KEEP" +``` + +- **Moving:** the cursor keys or W A S D. **Shooting:** Space or Ctrl, in the + direction you face. +- **P** pauses; **Esc** gives up the game. Esc on the title or the final + screen goes back to BASIC. +- **Score:** 100 a chest, 50 a guard, 1,000 for the crown, and 500 plus 200 a + remaining life for getting out. + +`KEEP` is a four-line BASIC program that loads the game, the memory file +`KEEPGAME`, at 0A200h, just past itself, and `CALL`s it. The game overwrites +the rest of BASIC's program area while it runs, so save your own program +first. It is written in C (`games/keep/` on the PC, with its build and +install steps). + +### Bastion Raid + +An isometric scrolling shooter, also in machine code. Fly over a fortress that +scrolls towards you and destroy the reactor core at its far end. + +``` +RUN "RAID" +``` + +- **Up and down** climb and dive; **left and right** steer across the + fortress; **Space** or **Ctrl** fires straight ahead. +- **Walls:** climb over the low ones. The tall ones are too high: fly low + through the doorway, the gap with the bright lintel. +- **Height:** your shadow on the floor and the ALT bar show how high you are. + Shots only hit things on the ground when you fly low. +- **Fuel** runs down; shoot the red fuel tanks to fill up. Turrets fire at you + when you are in front of them, and between the two fortresses fighters come + at you at all heights. +- **Score:** 100 a turret, 150 a fuel tank, 300 a radar dish, 200 a fighter, + 2,000 for the reactor and 500 for each level. At each level the turrets fire + sooner and the fighters come more often. +- **P** pauses; **Esc** gives up, and Esc at the title goes back to BASIC. + +`RAID` loads the memory file `RAIDGAME` at 0A200h, like `KEEP`. The game draws +the fortress pixel by pixel into the scrolled graphics, two new columns and a +row each frame, and everything that moves is a sprite (`games/raid/` on the +PC). + +### Star Warden + +A planet defence game in machine code, scrolling left and right round a +planet. Landers come down to snatch the humanoids walking on the ground and +carry them up; one that gets a humanoid to the top turns into a mutant that +hunts you. Shoot the landers, and catch the humanoids they drop before they +hit the ground. + +``` +RUN "WARDEN" +``` + +- **Left and right** fly that way, with momentum, and turn the ship round; + **up and down** climb and dive; **Space** or **Ctrl** fires the laser. +- **Shift** sets off a smart bomb, which destroys everything on the screen + (three to start with); **Enter** jumps into hyperspace, somewhere at random. +- **The scanner** across the top shows the whole planet with your ship in the + middle: landers green, mutants magenta, bombers blue, humanoids as dots. +- **Bombers** drift across and leave mines. A humanoid dropped from high up + dies when it lands; catch it on the way down for 500. +- **Waves** end when every enemy is gone, with a bonus for each humanoid + still alive. If they are all lost, every lander becomes a mutant; the + humanoids come back every fifth wave. +- **Score:** 150 a lander or mutant, 250 a bomber, 50 a mine, 500 a humanoid + caught, 250 for one landing safely. A new ship and smart bomb every 10,000. +- **P** pauses; **Esc** gives up, and Esc at the title goes back to BASIC. + +`WARDEN` loads the memory file `WARDGAME` at 0A200h. The planet is 1,280 pixels +round, four times the graphics' width, so the game scrolls the graphics and +draws each column of mountains and stars as it comes into view +(`games/warden/` on the PC). + +### Star Swarm + +An alien swarm sways in formation across the top of the screen, and its +members peel off in looping dives at your ship, firing as they come. Those +that miss loop round and fly back into their places. + +``` +RUN "SWARM" +``` + +- **Left and right** move the ship; **Space** or **Ctrl** fires. You have one + shot in the air at a time, so make it count. +- **The swarm:** blue drones, purple warriors, red escorts and two yellow + flagships at the top. A flagship dives with up to two escorts; shoot both + escorts before the flagship for 800. +- **Score:** each alien is worth twice as much diving as in formation: + drones 30 / 60, warriors 40 / 80, escorts 50 / 100, flagships 60 / 150 + (300 with an escort still flying). A new ship every 7,000. +- **Waves:** clear the swarm and a new one arrives, diving more often and + more of them at once. +- **P** pauses; **Esc** gives up, and Esc at the title goes back to BASIC. + +`SWARM` loads the memory file `SWARMGAM` at 0A200h. The 46 aliens are more than +the 32 sprites, so the formation is drawn into the graphics, and its sway is +the hardware scroll; a diving alien is wiped from the graphics and flies as a +sprite until it is back in its place (`games/swarm/` on the PC). + +### Crystal Cavern + +A maze chase. You are a miner gathering the crystals in a cave, chased by four +bats; gather every crystal to reach the next, faster cave. + +``` +RUN "CAVERN" +``` + +- **The cursor keys** or **W A S D** steer the miner. Hold a direction before + a junction and it turns there; it can turn back at any time. +- **The bats** each hunt their own way: the red one comes straight for you, + the magenta one heads you off, the green one works with the red, and the + orange one keeps its distance. Now and then they all break off and go to + their corners for a while. +- **Lanterns** (the four yellow lights) scare the bats blue for a few seconds: + catch them then, and their eyes fly back to the roost in the middle. They + flash white just before they recover. +- **The side tunnels** wrap round to the other side; bats are slow in them. +- **Score:** 10 a crystal, 50 a lantern, 200, 400, 800 and 1,600 for bats + caught on one lantern, and a gold nugget (500 a cave) that appears twice a + cave where you started. An extra life every 10,000. +- **P** pauses; **Esc** gives up, and Esc at the title goes back to BASIC. + +`CAVERN` loads the memory file `CAVEGAME` at 0A200h. The maze was made by +`gen.py`, which joins up a grid of junctions and takes links away at random +while keeping the cave connected, mirrored and free of dead ends +(`games/cavern/` on the PC). + +## 15. Limits at a glance + +| Item | Limit | +|---|---| +| Program and arrays together | about 20.2 KB | +| Line numbers | 0 – 65535 | +| Line length | 250 characters typed | +| Numeric variables | A–Z and A0–Z9 | +| String variables | A$–Z$, 79 characters each; string arrays A$( )–Z$( ), up to 255 elements | +| Arrays | A–Z, 1 or 2 subscripts, up to 6000 elements each | +| User functions | FNA–FNZ, one argument each | +| FOR nesting / GOSUB nesting | 16 / 32 | +| Graphics | 320 × 240, 16 colours | +| Sprites | 32 on screen, 64 shapes, 16 × 16 pixels each | +| Text | 80 × 32, or 132 × 64 | +| Files in flash | 64, 1,784 KB in all, 32 KB each | +| Open data files | 3 | diff --git a/docs/basic-manual.pdf b/docs/basic-manual.pdf new file mode 100644 index 0000000..915af5c Binary files /dev/null and b/docs/basic-manual.pdf differ diff --git a/docs/build-manual.sh b/docs/build-manual.sh new file mode 100755 index 0000000..64271ba --- /dev/null +++ b/docs/build-manual.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Turn docs/basic-manual.md into docs/basic-manual.pdf (needs python3-markdown and Chrome). +set -e +cd "$(dirname "$0")" +python3 - <<'PY' +import markdown +body = markdown.markdown(open("basic-manual.md").read(), extensions=["tables", "fenced_code"]) +css = """ +@page { size: A4; margin: 18mm 16mm; } +body { font-family: "DejaVu Serif", Georgia, serif; font-size: 10.5pt; line-height: 1.45; color: #111; } +h1 { font-size: 24pt; margin: 0 0 4pt; } +h1 + p { font-size: 12pt; color: #444; margin-bottom: 18pt; } +h2 { font-size: 15pt; border-bottom: 1px solid #999; padding-bottom: 2pt; margin-top: 22pt; + page-break-after: avoid; } +h3 { font-size: 12pt; margin-top: 14pt; page-break-after: avoid; } +code, pre { font-family: "DejaVu Sans Mono", monospace; font-size: 9pt; } +pre { background: #f2f2f2; border-left: 3px solid #4a7; padding: 6pt 8pt; page-break-inside: avoid; } +table { border-collapse: collapse; margin: 6pt 0; page-break-inside: avoid; } +th, td { border: 1px solid #bbb; padding: 3pt 6pt; vertical-align: top; text-align: left; } +th { background: #e8e8e8; } +""" +open("basic-manual.html", "w").write( + "Basys 3 RISC-V BASIC" + "%s" % (css, body)) +PY +google-chrome --headless --disable-gpu --no-pdf-header-footer \ + --print-to-pdf="$PWD/basic-manual.pdf" "file://$PWD/basic-manual.html" 2>/dev/null +rm basic-manual.html +echo "wrote docs/basic-manual.pdf" diff --git a/font/font.mem b/font/font.mem new file mode 100644 index 0000000..3f8b992 --- /dev/null +++ b/font/font.mem @@ -0,0 +1,4097 @@ +// CP437 order, 256 glyphs x 16 rows, from: Uni2-VGA16.psf.gz, FullGreek-VGA16.psf.gz, Vietnamese-TerminusBoldVGA16.psf.gz +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7e +81 +a5 +81 +81 +a5 +99 +81 +81 +7e +00 +00 +00 +00 +00 +00 +7e +ff +db +ff +ff +db +e7 +ff +ff +7e +00 +00 +00 +00 +00 +00 +00 +00 +6c +fe +fe +fe +fe +7c +38 +10 +00 +00 +00 +00 +00 +00 +00 +00 +10 +38 +7c +fe +7c +38 +10 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +3c +e7 +e7 +e7 +18 +18 +3c +00 +00 +00 +00 +00 +00 +00 +18 +3c +7e +ff +ff +7e +18 +18 +3c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +3c +18 +00 +00 +00 +00 +00 +00 +ff +ff +ff +ff +ff +ff +e7 +c3 +c3 +e7 +ff +ff +ff +ff +ff +ff +00 +00 +3c +42 +81 +81 +81 +81 +81 +81 +42 +3c +00 +00 +00 +00 +ff +ff +c3 +bd +7e +7e +7e +7e +7e +7e +bd +c3 +ff +ff +ff +ff +00 +00 +1e +06 +0e +1a +78 +cc +cc +cc +cc +78 +00 +00 +00 +00 +00 +00 +3c +66 +66 +66 +66 +3c +18 +7e +18 +18 +00 +00 +00 +00 +00 +00 +30 +3c +3e +32 +30 +30 +30 +70 +f0 +e0 +00 +00 +00 +00 +00 +00 +70 +7f +6f +63 +63 +63 +63 +e3 +e7 +c7 +06 +00 +00 +00 +00 +00 +00 +10 +10 +54 +28 +c6 +28 +54 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +0c +06 +ff +06 +0c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +30 +60 +ff +60 +30 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +7e +18 +18 +18 +7e +3c +18 +00 +00 +00 +00 +00 +00 +00 +66 +66 +66 +66 +66 +66 +66 +00 +66 +66 +00 +00 +00 +00 +00 +00 +7f +db +db +db +7b +1b +1b +1b +1b +1b +00 +00 +00 +00 +00 +7c +c6 +60 +38 +6c +c6 +c6 +6c +38 +0c +c6 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +fe +fe +fe +fe +00 +00 +00 +00 +00 +00 +18 +3c +7e +18 +18 +18 +7e +3c +18 +7e +00 +00 +00 +00 +00 +00 +18 +3c +7e +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +7e +3c +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +0c +06 +ff +06 +0c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +30 +60 +ff +60 +30 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +c0 +c0 +c0 +c0 +c0 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +24 +66 +ff +66 +24 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +7e +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +7e +3c +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +3c +3c +18 +18 +18 +00 +18 +18 +00 +00 +00 +00 +00 +66 +66 +66 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +6c +6c +fe +6c +6c +6c +fe +6c +6c +00 +00 +00 +00 +18 +18 +7c +c6 +c2 +c0 +7c +06 +06 +86 +c6 +7c +18 +18 +00 +00 +00 +00 +00 +00 +c2 +c6 +0c +18 +30 +60 +c6 +86 +00 +00 +00 +00 +00 +00 +38 +6c +6c +38 +76 +dc +cc +cc +cc +76 +00 +00 +00 +00 +00 +30 +30 +30 +20 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +0c +18 +30 +30 +30 +30 +30 +30 +18 +0c +00 +00 +00 +00 +00 +00 +30 +18 +0c +0c +0c +0c +0c +0c +18 +30 +00 +00 +00 +00 +00 +00 +00 +00 +00 +66 +3c +ff +3c +66 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +7e +18 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +30 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +00 +00 +00 +00 +00 +00 +00 +00 +02 +06 +0c +18 +30 +60 +c0 +80 +00 +00 +00 +00 +00 +00 +38 +6c +c6 +c6 +d6 +d6 +c6 +c6 +6c +38 +00 +00 +00 +00 +00 +00 +18 +38 +78 +18 +18 +18 +18 +18 +18 +7e +00 +00 +00 +00 +00 +00 +7c +c6 +06 +0c +18 +30 +60 +c0 +c6 +fe +00 +00 +00 +00 +00 +00 +7c +c6 +06 +06 +3c +06 +06 +06 +c6 +7c +00 +00 +00 +00 +00 +00 +0c +1c +3c +6c +cc +fe +0c +0c +0c +1e +00 +00 +00 +00 +00 +00 +fe +c0 +c0 +c0 +fc +06 +06 +06 +c6 +7c +00 +00 +00 +00 +00 +00 +38 +60 +c0 +c0 +fc +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +fe +c6 +06 +06 +0c +18 +30 +30 +30 +30 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +7c +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +7e +06 +06 +06 +0c +78 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +00 +00 +00 +18 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +00 +00 +00 +18 +18 +30 +00 +00 +00 +00 +00 +00 +00 +06 +0c +18 +30 +60 +30 +18 +0c +06 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7e +00 +00 +7e +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +60 +30 +18 +0c +06 +0c +18 +30 +60 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +0c +18 +18 +18 +00 +18 +18 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +de +de +de +dc +c0 +7c +00 +00 +00 +00 +00 +00 +10 +38 +6c +c6 +c6 +fe +c6 +c6 +c6 +c6 +00 +00 +00 +00 +00 +00 +fc +66 +66 +66 +7c +66 +66 +66 +66 +fc +00 +00 +00 +00 +00 +00 +3c +66 +c2 +c0 +c0 +c0 +c0 +c2 +66 +3c +00 +00 +00 +00 +00 +00 +f8 +6c +66 +66 +66 +66 +66 +66 +6c +f8 +00 +00 +00 +00 +00 +00 +fe +66 +62 +68 +78 +68 +60 +62 +66 +fe +00 +00 +00 +00 +00 +00 +fe +66 +62 +68 +78 +68 +60 +60 +60 +f0 +00 +00 +00 +00 +00 +00 +3c +66 +c2 +c0 +c0 +de +c6 +c6 +66 +3a +00 +00 +00 +00 +00 +00 +c6 +c6 +c6 +c6 +fe +c6 +c6 +c6 +c6 +c6 +00 +00 +00 +00 +00 +00 +3c +18 +18 +18 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +1e +0c +0c +0c +0c +0c +cc +cc +cc +78 +00 +00 +00 +00 +00 +00 +e6 +66 +66 +6c +78 +78 +6c +66 +66 +e6 +00 +00 +00 +00 +00 +00 +f0 +60 +60 +60 +60 +60 +60 +62 +66 +fe +00 +00 +00 +00 +00 +00 +c6 +ee +fe +fe +d6 +c6 +c6 +c6 +c6 +c6 +00 +00 +00 +00 +00 +00 +c6 +e6 +f6 +fe +de +ce +c6 +c6 +c6 +c6 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +fc +66 +66 +66 +7c +60 +60 +60 +60 +f0 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +c6 +c6 +c6 +d6 +de +7c +0c +0e +00 +00 +00 +00 +fc +66 +66 +66 +7c +6c +66 +66 +66 +e6 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +60 +38 +0c +06 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +7e +7e +5a +18 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +6c +38 +10 +00 +00 +00 +00 +00 +00 +c6 +c6 +c6 +c6 +d6 +d6 +d6 +fe +ee +6c +00 +00 +00 +00 +00 +00 +c6 +c6 +6c +7c +38 +38 +7c +6c +c6 +c6 +00 +00 +00 +00 +00 +00 +66 +66 +66 +66 +3c +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +fe +c6 +86 +0c +18 +30 +60 +c2 +c6 +fe +00 +00 +00 +00 +00 +00 +3c +30 +30 +30 +30 +30 +30 +30 +30 +3c +00 +00 +00 +00 +00 +00 +00 +80 +c0 +e0 +70 +38 +1c +0e +06 +02 +00 +00 +00 +00 +00 +00 +3c +0c +0c +0c +0c +0c +0c +0c +0c +3c +00 +00 +00 +00 +10 +38 +6c +c6 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ff +00 +00 +30 +30 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +e0 +60 +60 +78 +6c +66 +66 +66 +66 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +c0 +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +1c +0c +0c +3c +6c +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +fe +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +38 +6c +64 +60 +f0 +60 +60 +60 +60 +f0 +00 +00 +00 +00 +00 +00 +00 +00 +00 +76 +cc +cc +cc +cc +cc +7c +0c +cc +78 +00 +00 +00 +e0 +60 +60 +6c +76 +66 +66 +66 +66 +e6 +00 +00 +00 +00 +00 +00 +18 +18 +00 +38 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +06 +06 +00 +0e +06 +06 +06 +06 +06 +06 +66 +66 +3c +00 +00 +00 +e0 +60 +60 +66 +6c +78 +78 +6c +66 +e6 +00 +00 +00 +00 +00 +00 +38 +18 +18 +18 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +00 +00 +00 +ec +fe +d6 +d6 +d6 +d6 +c6 +00 +00 +00 +00 +00 +00 +00 +00 +00 +dc +66 +66 +66 +66 +66 +66 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +dc +66 +66 +66 +66 +66 +7c +60 +60 +f0 +00 +00 +00 +00 +00 +00 +76 +cc +cc +cc +cc +cc +7c +0c +0c +1e +00 +00 +00 +00 +00 +00 +dc +76 +66 +60 +60 +60 +f0 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +60 +38 +0c +c6 +7c +00 +00 +00 +00 +00 +00 +10 +30 +30 +fc +30 +30 +30 +30 +36 +1c +00 +00 +00 +00 +00 +00 +00 +00 +00 +cc +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +00 +00 +00 +66 +66 +66 +66 +66 +3c +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +c6 +c6 +d6 +d6 +d6 +fe +6c +00 +00 +00 +00 +00 +00 +00 +00 +00 +c6 +6c +38 +38 +38 +6c +c6 +00 +00 +00 +00 +00 +00 +00 +00 +00 +c6 +c6 +c6 +c6 +c6 +c6 +7e +06 +0c +f8 +00 +00 +00 +00 +00 +00 +fe +cc +18 +30 +60 +c6 +fe +00 +00 +00 +00 +00 +00 +0e +18 +18 +18 +70 +18 +18 +18 +18 +0e +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +70 +18 +18 +18 +0e +18 +18 +18 +18 +70 +00 +00 +00 +00 +00 +00 +76 +dc +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +38 +6c +c6 +c6 +c6 +fe +00 +00 +00 +00 +00 +00 +00 +3c +66 +c2 +c0 +c0 +c0 +c0 +c2 +66 +3c +18 +0c +38 +00 +00 +00 +cc +cc +00 +cc +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +0c +18 +00 +7c +c6 +fe +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +10 +38 +6c +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +6c +6c +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +60 +30 +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +38 +6c +38 +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +c0 +c0 +c0 +c6 +7c +18 +0c +38 +00 +00 +10 +38 +6c +00 +7c +c6 +fe +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +6c +6c +00 +7c +c6 +fe +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +60 +30 +00 +7c +c6 +fe +c0 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +66 +66 +00 +38 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +10 +38 +6c +00 +38 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +30 +18 +00 +38 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +6c +6c +00 +10 +38 +6c +c6 +c6 +fe +c6 +c6 +c6 +00 +00 +00 +00 +38 +6c +38 +10 +38 +6c +c6 +c6 +fe +c6 +c6 +c6 +00 +00 +00 +00 +0c +18 +00 +fe +66 +62 +68 +78 +68 +62 +66 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +cc +76 +36 +7e +d8 +d8 +6e +00 +00 +00 +00 +00 +00 +3e +6c +cc +cc +fe +cc +cc +cc +cc +ce +00 +00 +00 +00 +00 +10 +38 +6c +00 +7c +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +6c +6c +00 +7c +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +60 +30 +00 +7c +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +10 +38 +6c +00 +cc +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +60 +30 +00 +cc +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +6c +6c +00 +c6 +c6 +c6 +c6 +c6 +c6 +7e +06 +0c +f8 +00 +6c +6c +00 +7c +c6 +c6 +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +6c +6c +00 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +18 +18 +3c +66 +60 +60 +60 +66 +3c +18 +18 +00 +00 +00 +00 +00 +38 +6c +64 +60 +f0 +60 +60 +60 +60 +e6 +fc +00 +00 +00 +00 +00 +00 +66 +66 +3c +18 +7e +18 +7e +18 +18 +18 +00 +00 +00 +00 +00 +00 +fc +66 +66 +7c +62 +66 +6f +66 +66 +f3 +00 +00 +00 +00 +00 +00 +1c +36 +32 +30 +78 +30 +30 +30 +30 +30 +30 +30 +e0 +00 +00 +00 +18 +30 +00 +78 +0c +7c +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +0c +18 +00 +38 +18 +18 +18 +18 +18 +3c +00 +00 +00 +00 +00 +00 +0c +18 +00 +7c +c6 +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +18 +30 +00 +cc +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +76 +dc +00 +dc +66 +66 +66 +66 +66 +66 +00 +00 +00 +00 +76 +dc +00 +c6 +e6 +f6 +fe +de +ce +c6 +c6 +c6 +00 +00 +00 +00 +00 +3c +6c +6c +3e +00 +7e +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +38 +6c +6c +38 +00 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +30 +30 +00 +30 +30 +60 +c0 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +c0 +c0 +c0 +c0 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +06 +06 +06 +06 +00 +00 +00 +00 +00 +00 +c0 +c0 +c2 +c6 +cc +18 +30 +60 +dc +86 +0c +18 +3e +00 +00 +00 +c0 +c0 +c2 +c6 +cc +18 +30 +66 +ce +9e +3e +06 +06 +00 +00 +00 +00 +18 +18 +00 +18 +18 +18 +3c +3c +3c +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +36 +6c +d8 +6c +36 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +d8 +6c +36 +6c +d8 +00 +00 +00 +00 +00 +00 +11 +44 +11 +44 +11 +44 +11 +44 +11 +44 +11 +44 +11 +44 +11 +44 +55 +aa +55 +aa +55 +aa +55 +aa +55 +aa +55 +aa +55 +aa +55 +aa +dd +77 +dd +77 +dd +77 +dd +77 +dd +77 +dd +77 +dd +77 +dd +77 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +f8 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +f8 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +f8 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +ff +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +ff +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +1f +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ff +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +ff +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ff +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +ff +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ff +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +1f +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +1f +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +1f +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +1f +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ff +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +f8 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +1f +18 +18 +18 +18 +18 +18 +18 +18 +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +ff +00 +00 +00 +00 +00 +00 +00 +00 +ff +ff +ff +ff +ff +ff +ff +ff +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +f0 +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +0f +ff +ff +ff +ff +ff +ff +ff +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +76 +cc +cc +cc +cc +cc +76 +00 +00 +00 +00 +00 +00 +3c +66 +66 +66 +6c +66 +66 +66 +66 +ec +00 +00 +00 +00 +00 +00 +fe +66 +62 +60 +60 +60 +60 +60 +60 +f0 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +6c +6c +6c +6c +6c +66 +00 +00 +00 +00 +00 +00 +fe +c6 +62 +30 +18 +18 +30 +62 +c6 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +7e +cc +cc +cc +cc +cc +78 +00 +00 +00 +00 +00 +00 +00 +00 +00 +cc +cc +cc +cc +cc +cc +f6 +c0 +c0 +c0 +00 +00 +00 +00 +00 +00 +7e +18 +18 +18 +18 +18 +0e +00 +00 +00 +00 +00 +00 +10 +7c +d6 +d6 +d6 +d6 +d6 +7c +10 +10 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +fe +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +c6 +c6 +6c +6c +6c +ee +00 +00 +00 +00 +00 +00 +3c +66 +30 +18 +7c +c6 +c6 +c6 +c6 +7c +00 +00 +00 +00 +00 +00 +00 +00 +00 +76 +db +db +6e +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +6c +d6 +d6 +d6 +d6 +d6 +7c +10 +10 +10 +00 +00 +00 +00 +00 +00 +7c +c6 +c0 +78 +c0 +c6 +7c +00 +00 +00 +00 +00 +00 +00 +00 +7c +c6 +c6 +c6 +c6 +c6 +c6 +c6 +00 +00 +00 +00 +00 +00 +00 +00 +fe +00 +00 +fe +00 +00 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +7e +18 +18 +00 +7e +00 +00 +00 +00 +00 +00 +00 +00 +00 +e0 +38 +0e +38 +e0 +00 +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +0e +38 +e0 +38 +0e +00 +fe +00 +00 +00 +00 +00 +00 +00 +0e +1b +1b +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +d8 +d8 +d8 +70 +00 +00 +00 +00 +00 +00 +00 +00 +18 +18 +00 +7e +00 +18 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +76 +dc +00 +76 +dc +00 +00 +00 +00 +00 +00 +00 +38 +6c +6c +38 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +3c +3c +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +03 +03 +06 +06 +06 +0c +cc +6c +38 +18 +00 +00 +00 +00 +00 +00 +b0 +d8 +d8 +d8 +d8 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +70 +d8 +30 +60 +c8 +f8 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +fe +fe +fe +fe +fe +fe +fe +fe +fe +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 diff --git a/games/build-game.sh b/games/build-game.sh new file mode 100755 index 0000000..182464d --- /dev/null +++ b/games/build-game.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Build one game: games/build-game.sh NAME -> games/NAME/NAME.ihx, Intel HEX +# for tools/send-hex.py. It runs at A200h, inside BASIC's program area +# (A000h-F0B7h) and clear of the loader program at its start. +set -e +cd "$(dirname "$0")" +source ../scripts/rv_env.sh +G=$1 +mkdir -p $G/out +python3 $G/gen.py $G/out/data.h +CFLAGS="$RV_ARCH -Os -mno-relax -ffunction-sections -fdata-sections -fno-common -Wall -I../include -I$G/out" +${RV_PREFIX}gcc $CFLAGS -c -o $G/out/crt0.o crt0.S +${RV_PREFIX}gcc $CFLAGS -c -o $G/out/$G.o $G/$G.c +${RV_PREFIX}gcc $CFLAGS -c -o $G/out/string.o ../lib/string.c +${RV_PREFIX}gcc $RV_ARCH -nostdlib -nostartfiles -T game.ld -Wl,--no-relax -Wl,--gc-sections \ + -Wl,--build-id=none -Wl,--no-warn-rwx-segments -Wl,-Map,$G/out/$G.map -o $G/out/$G.elf $G/out/crt0.o $G/out/$G.o $G/out/string.o -lgcc +${RV_PREFIX}objcopy -O ihex -j .text -j .data $G/out/$G.elf $G/$G.ihx +${RV_PREFIX}nm -n $G/out/$G.elf > $G/out/$G.sym +data=$(${RV_PREFIX}size -A $G/out/$G.elf | awk '$1 == ".data" {print $2}') +python3 - $G/out/$G.sym "${data:-0}" <<'PY' +import sys +s = {f[2]: int(f[0], 16) for f in (l.split() for l in open(sys.argv[1])) if len(f) == 3} +code_end, end = s["__bss_start"], s["__bss_end"] +print("code A200-%05X (%d bytes), variables to %05X" % (code_end - 1, code_end - 0xA200, end - 1)) +assert end <= 0xF0B8, "the program runs past BASIC's program area" +assert sys.argv[2] == "0", "initialised variables are not supported" +PY diff --git a/games/cavern/cavern.bas b/games/cavern/cavern.bas new file mode 100644 index 0000000..ca2e414 --- /dev/null +++ b/games/cavern/cavern.bas @@ -0,0 +1,4 @@ +10 REM CRYSTAL CAVERN: LOAD THE GAME (MEMORY FILE CAVEGAME) AND PLAY IT +20 REM THE GAME RUNS AT A200H, PAST THIS PROGRAM, AND COMES BACK HERE +30 BLOAD "CAVEGAME": CALL 41472 +40 CLS diff --git a/games/cavern/cavern.c b/games/cavern/cavern.c new file mode 100644 index 0000000..885b02b --- /dev/null +++ b/games/cavern/cavern.c @@ -0,0 +1,650 @@ +/* Crystal Cavern: a maze chase game for the Basys 3 RISC-V computer. + + You are a miner gathering crystals in a cave, chased by four bats. Each + hunts its own way: the red one comes straight for you, the magenta one + heads you off, the green one works with the red, and the orange one keeps + its distance. A lantern scares them for a while: catch them then and their + eyes fly back to the roost. Gold nuggets turn up for bonus points, and the + side tunnels wrap round. Gather every crystal to reach the next cave. + + The maze is drawn into the graphics in 8 x 8 tiles; the miner, the bats and + the nugget are sprites. It runs at A200h, loaded by the CAVERN program in + BASIC. */ + +typedef unsigned char u8; +typedef signed char i8; +typedef unsigned short u16; +typedef short i16; + +#include "basys3.h" + +#define con_stat IO8(0x00) +#define con_data IO8(0x01) +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) +#define gfill IO8(0x34) +#define sp_sel IO8(0x70) +#define sp_xlo IO8(0x71) +#define sp_xhi IO8(0x72) +#define sp_y IO8(0x73) +#define sp_shape IO8(0x74) +#define sp_ctl IO8(0x75) +#define sp_load IO8(0x76) +#define sp_data IO8(0x77) +#define frame_ctr IO8(0x78) +#define joy IO8(0x88) + +#include "data.h" /* out/data.h, made by gen.py */ + +#define J_UP 1 +#define J_DOWN 2 +#define J_LEFT 4 +#define J_RIGHT 8 +#define J_FIRE 16 +#define J_ENTER 32 +#define J_ESC 128 + +#define MX0 48 /* the maze's top left on the screen */ +#define MY0 8 +#define PW (MW * 8) /* maze width in pixels */ + +#define T_OPEN 0 +#define T_WALL 1 +#define T_CRYS 2 +#define T_LAMP 3 +#define T_DOOR 4 +#define T_ROOST 5 +#define T_TUNNEL 6 + +#define D_RIGHT 0 +#define D_DOWN 1 +#define D_LEFT 2 +#define D_UP 3 +#define D_NONE 4 +static const i8 ddx[5] = { 1, 0, -1, 0, 0 }; +static const i8 ddy[5] = { 0, 1, 0, -1, 0 }; + +/* bats */ +#define NB 4 +#define B_ROOST 0 +#define B_LEAVE 1 +#define B_HUNT 2 +#define B_EYES 3 +#define B_HOME 4 /* eyes back in the roost, going down */ + +#define DOOR_X 108 /* column 13's centre: the way in and out of the roost */ +#define OUT_Y 76 /* row 9's centre, just above the door */ +#define ROOM_Y 108 /* the roost's middle */ + +#define SP_MINER 0 +#define SP_BAT 1 /* 4 */ +#define SP_NUGGET 5 +#define SP_BOOM 6 + +static const u8 bat_shape[NB] = { S_BAT_R, S_BAT_M, S_BAT_G, S_BAT_O }; +static const i8 corner_x[NB] = { 26, 1, 26, 1 }; +static const i8 corner_y[NB] = { -2, -2, 30, 30 }; +static const u8 roost_x[NB] = { DOOR_X, DOOR_X, 92, 124 }; +/* scatter and chase, in seconds: then chase for good */ +static const u8 mode_secs[6] = { 7, 20, 7, 20, 5, 255 }; + +/* ---------------------------------------------------------------- state */ +/* not static: test-cavern.py reads these from the link map */ +u8 maze[MH][MW]; +i16 mx, my; /* miner, maze pixels (tile centre = 8t + 4) */ +u8 lives, level, dead, shield, left; +u16 score; +u8 bstate[NB]; +i16 bx[NB], by[NB]; + +static u8 mdir, mwant, macc, manim; +static u8 bdir[NB], bacc[NB], bwait[NB]; +static u8 fright, fright_flash, combo; +static u16 fright_time, mode_time; +static u8 mode, mode_i, eaten; +static u16 nugget_time; +static u8 nugget_on, boom_time, dead_time, lamp_blink; +static u16 next_extra; +static u8 last_frame, quit, hud_dirty; +static u16 rnd_state; +static const char *msg; +static u8 msg_time; + +/* ----------------------------------------------------------------- text */ +static void putch(char c) { while (!(con_stat & 2)); con_data = c; } +static void puts_(const char *s) { while (*s) putch(*s++); } +static void putn(u16 n, u8 width) +{ + char b[6]; + u8 i = 0; + do { b[i++] = '0' + n % 10; n /= 10; } while (n); + while (width > i) { putch('0'); width--; } + while (i) putch(b[--i]); +} +static void at(u8 r, u8 c) { putch(27); putch('['); putn(r, 0); putch(';'); putn(c, 0); putch('H'); } +static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); } +static void centre(u8 r, const char *s) +{ + u8 n = 0; + while (s[n]) n++; + at(r, 41 - n / 2); + puts_(s); +} + +static u16 rnd(void) +{ + rnd_state ^= rnd_state << 7; + rnd_state ^= rnd_state >> 9; + rnd_state ^= rnd_state << 8; + return rnd_state; +} + +static void wait_frame(void) +{ + while (frame_ctr == last_frame); + last_frame = frame_ctr; +} + +static u8 drain_keys(void) +{ + u8 c, p = 0; + while (con_stat & 1) { + c = con_data; + if (c == 'p' || c == 'P') p = 1; + } + return p; +} + +static void say(const char *s) { msg = s; msg_time = 120; hud_dirty = 1; } +static i16 absd(i16 v) { return v < 0 ? -v : v; } + +/* ------------------------------------------------------------ the maze */ +static u8 tile(i16 tx, i16 ty) +{ + if (ty < 0 || ty >= MH) return T_WALL; + if (tx < 0) tx += MW; + if (tx >= MW) tx -= MW; + return maze[ty][tx]; +} + +static u8 is_open(u8 t) { return t == T_OPEN || t == T_CRYS || t == T_LAMP || t == T_TUNNEL; } + +static void plot_row(u16 x, u8 y, const u8 *c) +{ + u8 i; + gx_lo = (u8)x; gx_hi = (u8)(x >> 8); gy_p = y; + for (i = 0; i < 8; i++) gpix = c[i]; +} + +static u8 wall_ink; + +/* Draw tile (tx, ty): walls are outlined where they meet a passage. */ +static void draw_tile(u8 tx, u8 ty) +{ + u8 t = maze[ty][tx], r, c, row[8], up, dn, lf, rt; + u16 x = MX0 + tx * 8; + u8 y = MY0 + ty * 8; + for (r = 0; r < 8; r++) { + for (c = 0; c < 8; c++) row[c] = 0; + if (t == T_WALL) { + up = !(tile(tx, ty - 1) == T_WALL); + dn = !(tile(tx, ty + 1) == T_WALL); + lf = !(tile(tx - 1, ty) == T_WALL) && tx > 0; + rt = !(tile(tx + 1, ty) == T_WALL) && tx < MW - 1; + for (c = 0; c < 8; c++) + if ((r == 1 && up) || (r == 6 && dn) || (c == 1 && lf) || (c == 6 && rt)) + row[c] = wall_ink; + /* tidy the corners where two outlines meet */ + if ((r < 1 && up) || (r > 6 && dn)) for (c = 0; c < 8; c++) row[c] = 0; + if (lf) row[0] = 0; + if (rt) row[7] = 0; + } else if (t == T_DOOR) { + if (r == 3 || r == 4) for (c = 0; c < 8; c++) row[c] = 13; + } else if (t == T_CRYS) { + if (r == 3 || r == 4) row[3] = row[4] = 14; + } else if (t == T_LAMP && lamp_blink) { + if (r >= 1 && r <= 6) for (c = (r == 1 || r == 6) ? 2 : 1; c < ((r == 1 || r == 6) ? 6 : 7); c++) row[c] = 11; + if (r == 3 || r == 4) row[3] = row[4] = 15; + } + plot_row(x, y + r, row); + } +} + +static void draw_maze(void) +{ + u8 x, y; + for (y = 0; y < MH; y++) + for (x = 0; x < MW; x++) + draw_tile(x, y); +} + +static void draw_lamps(void) +{ + u8 x, y; + for (y = 0; y < MH; y++) + for (x = 0; x < MW; x++) + if (maze[y][x] == T_LAMP) draw_tile(x, y); +} + +static void reset_maze(void) +{ + u8 x, y; + left = 0; + for (y = 0; y < MH; y++) + for (x = 0; x < MW; x++) { + maze[y][x] = maze_start[y][x]; + if (maze[y][x] == T_CRYS || maze[y][x] == T_LAMP) left++; + } +} + +/* -------------------------------------------------------------- sprites */ +static void spr_at(u8 n, i16 x, i16 y, u8 shape, u8 ctl) +{ + sp_sel = n; + if (x < -15 || x > 319 || y < -15 || y > 239) { sp_ctl = 0; return; } + sp_xlo = (u8)x; sp_xhi = (u8)(x >> 8) & 1; sp_y = (u8)y; + sp_shape = shape; sp_ctl = ctl; +} +static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; } +static void all_off(void) { u8 i; for (i = 0; i < 32; i++) spr_off(i); } + +/* a figure at maze pixel (x, y); hidden in the tunnels beyond the maze */ +static void figure(u8 n, i16 x, i16 y, u8 shape, u8 ctl) +{ + if (x < 4 || x > PW - 4) { spr_off(n); return; } + spr_at(n, MX0 + x - 8, MY0 + y - 8, shape, ctl); +} + +static void load_shapes(void) +{ + const u8 *p = shape_data; + u8 s, i; + for (s = 0; s < N_SHAPES; s++) { + sp_load = s; + for (i = 0; i < 128; i++) sp_data = *p++; + } +} + +/* ------------------------------------------------------------------ HUD */ +static void hud(void) +{ + hud_dirty = 0; + at(1, 1); ink("0;93"); puts_("CRYSTAL CAVERN "); + ink("0;37"); puts_("SCORE "); ink("0;97"); putn(score, 6); + ink("0;37"); puts_(" LIVES "); ink("0;97"); putn(lives, 0); + ink("0;37"); puts_(" CAVE "); ink("0;97"); putn(level, 0); + if (msg && msg_time) { ink("0;96"); puts_(" "); puts_(msg); } + puts_("\033[K"); + ink("0"); +} + +static void add_score(u16 n) +{ + score += n; + if (score >= next_extra) { next_extra += 10000; lives++; say("EXTRA LIFE"); } + hud_dirty = 1; +} + +/* --------------------------------------------------------------- moving */ +static u8 at_centre(i16 x, i16 y) { return (x & 7) == 4 && (y & 7) == 4; } + +static void wrap(i16 *x) +{ + if (*x < -8) *x += PW + 16; + else if (*x >= PW + 8) *x -= PW + 16; +} + +static u8 can_go(i16 x, i16 y, u8 d) +{ + return is_open(tile((x >> 3) + ddx[d], (y >> 3) + ddy[d])); +} + +/* ---------------------------------------------------------------- miner */ +static void miner_step(void) +{ + u8 t; + i16 tx, ty; + if (mwant != D_NONE && mwant == ((mdir + 2) & 3)) mdir = mwant; /* turning back: any time */ + if (at_centre(mx, my)) { + tx = mx >> 3; ty = my >> 3; + t = tile(tx, ty); + if (t == T_CRYS || t == T_LAMP) { + if (tx >= 0 && tx < MW) { + maze[ty][tx] = T_OPEN; + draw_tile((u8)tx, (u8)ty); + } + left--; + if (t == T_CRYS) add_score(10); + else { + add_score(50); + fright = 1; combo = 0; + fright_time = level < 7 ? 360 - 40 * level : 100; + { u8 b; for (b = 0; b < NB; b++) if (bstate[b] == B_HUNT) bdir[b] = (bdir[b] + 2) & 3; } + } + eaten++; + } + if (mwant != D_NONE && can_go(mx, my, mwant)) mdir = mwant; + if (mdir == D_NONE || !can_go(mx, my, mdir)) return; /* against a wall */ + } + if (mdir == D_NONE) return; + mx += ddx[mdir]; my += ddy[mdir]; + wrap(&mx); + manim++; +} + +static void miner(u8 j) +{ + u8 spd; + if (j & J_LEFT) mwant = D_LEFT; + else if (j & J_RIGHT) mwant = D_RIGHT; + else if (j & J_UP) mwant = D_UP; + else if (j & J_DOWN) mwant = D_DOWN; + spd = 16 + (level < 5 ? level : 5); + macc += spd; + while (macc >= 16) { macc -= 16; miner_step(); } + figure(SP_MINER, mx, my, S_MINER + ((manim >> 2) & 1), mdir == D_LEFT ? 3 : 1); +} + +/* ----------------------------------------------------------------- bats */ +static void bat_target(u8 b, i16 *tx, i16 *ty) +{ + i16 mtx = mx >> 3, mty = my >> 3, d; + u8 md = mdir == D_NONE ? D_LEFT : mdir; + if (bstate[b] == B_EYES) { *tx = 13; *ty = 9; return; } + if (!mode) { *tx = corner_x[b]; *ty = corner_y[b]; return; } /* scatter */ + switch (b) { + case 0: *tx = mtx; *ty = mty; break; + case 1: *tx = mtx + 4 * ddx[md]; *ty = mty + 4 * ddy[md]; break; + case 2: + *tx = 2 * (mtx + 2 * ddx[md]) - (bx[0] >> 3); + *ty = 2 * (mty + 2 * ddy[md]) - (by[0] >> 3); + break; + default: + d = absd((bx[b] >> 3) - mtx) + absd((by[b] >> 3) - mty); + if (d > 8) { *tx = mtx; *ty = mty; } + else { *tx = corner_x[b]; *ty = corner_y[b]; } + } +} + +/* At a junction: the way (not back) that ends nearest the target, or a + random one when frightened. */ +static void bat_choose(u8 b) +{ + i16 tx, ty, nx, ny, d, best = 32767; + u8 k, back = (bdir[b] + 2) & 3, pick = back, start; + if (fright && bstate[b] == B_HUNT) { + start = rnd() & 3; + for (k = 0; k < 4; k++) { + u8 dd = (start + k) & 3; + if (dd != back && can_go(bx[b], by[b], dd)) { bdir[b] = dd; return; } + } + bdir[b] = back; + return; + } + bat_target(b, &tx, &ty); + for (k = 0; k < 4; k++) { + if (k == back || !can_go(bx[b], by[b], k)) continue; + nx = (bx[b] >> 3) + ddx[k] - tx; + ny = (by[b] >> 3) + ddy[k] - ty; + d = absd(nx) + absd(ny); + /* break ties in the order up, left, down, right */ + if (d < best || (d == best && (k == D_UP || (k == D_LEFT && pick != D_UP)))) { best = d; pick = k; } + } + bdir[b] = pick; +} + +static void bat_step(u8 b) +{ + switch (bstate[b]) { + case B_ROOST: + by[b] += (bwait[b] & 8) ? 1 : -1; + if (by[b] < ROOM_Y - 3) by[b] = ROOM_Y - 3; + if (by[b] > ROOM_Y + 3) by[b] = ROOM_Y + 3; + return; + case B_LEAVE: + if (bx[b] < DOOR_X) bx[b]++; + else if (bx[b] > DOOR_X) bx[b]--; + else if (by[b] > OUT_Y) by[b]--; + else { bstate[b] = B_HUNT; bdir[b] = D_LEFT; } + return; + case B_HOME: + if (by[b] < ROOM_Y) by[b]++; + else bstate[b] = B_LEAVE; + return; + } + if (at_centre(bx[b], by[b])) { + if (bstate[b] == B_EYES && bx[b] == DOOR_X && by[b] == OUT_Y) { bstate[b] = B_HOME; return; } + bat_choose(b); + } + bx[b] += ddx[bdir[b]]; by[b] += ddy[bdir[b]]; + wrap(&bx[b]); +} + +static void kill_miner(void) +{ + if (dead || shield) return; + dead = 1; dead_time = 100; + boom_time = 60; + say("THE BATS GOT YOU"); +} + +static void bats(void) +{ + u8 b, spd, s, n; + for (b = 0; b < NB; b++) { + bwait[b]++; + if (bstate[b] == B_ROOST) { + /* let them out by crystals eaten or by time */ + if ((b == 1) || (b == 2 && (eaten >= 30 || bwait[b] > 240)) || + (b == 3 && (eaten >= 60 || bwait[b] > 250 && eaten >= 20))) + bstate[b] = B_LEAVE; + } + if (bstate[b] == B_EYES || bstate[b] == B_HOME) spd = 40; + else if (bstate[b] == B_HUNT && fright) spd = 8; + else if (bstate[b] == B_HUNT && (by[b] >> 3) == TUNNEL_Y && ((bx[b] >> 3) < 6 || (bx[b] >> 3) > MW - 7)) spd = 8; + else spd = 14 + (level < 5 ? level : 5); + bacc[b] += spd; + while (bacc[b] >= 16) { bacc[b] -= 16; bat_step(b); } + if (!dead && bstate[b] == B_HUNT && absd(bx[b] - mx) < 6 && absd(by[b] - my) < 6) { + if (fright) { + bstate[b] = B_EYES; + add_score(200 << combo); + if (combo < 3) combo++; + } else kill_miner(); + } + n = (bwait[b] >> 3) & 1; + if (bstate[b] == B_EYES || bstate[b] == B_HOME) s = S_EYES; + else if (fright && bstate[b] != B_ROOST && bstate[b] != B_LEAVE) + s = (fright_time < 120 && (fright_time & 8)) ? S_FLASH + n : S_SCARED + n; + else s = bat_shape[b] + n; + figure(SP_BAT + b, bx[b], by[b], s, 1); + } +} + +static void modes(void) +{ + if (fright) { + if (!--fright_time) fright = 0; + return; + } + if (mode_secs[mode_i] == 255) return; + if (++mode_time >= (u16)mode_secs[mode_i] * 60) { + u8 b; + mode_time = 0; mode_i++; mode ^= 1; + for (b = 0; b < NB; b++) if (bstate[b] == B_HUNT) bdir[b] = (bdir[b] + 2) & 3; + } +} + +static void nugget(void) +{ + if (!nugget_on && (eaten == 70 || eaten == 170) && nugget_time == 0) { + nugget_on = 1; nugget_time = 540; + } + if (nugget_time) { + nugget_time--; + if (!nugget_time) nugget_on = 0; + } + if (nugget_on && !dead && absd(mx - (START_X * 8 + 8)) < 6 && absd(my - (START_Y * 8 + 4)) < 6) { + nugget_on = 0; nugget_time = 1; + add_score(500 * level); + say("GOLD!"); + } + if (nugget_on) figure(SP_NUGGET, START_X * 8 + 8, START_Y * 8 + 4, S_NUGGET, 1); + else spr_off(SP_NUGGET); +} + +static void place_all(void) +{ + u8 b; + mx = START_X * 8 + 8; my = START_Y * 8 + 4; /* between columns 13 and 14 */ + mdir = D_LEFT; mwant = D_LEFT; macc = 0; + for (b = 0; b < NB; b++) { + bx[b] = roost_x[b]; by[b] = ROOM_Y; bacc[b] = 0; bwait[b] = b * 40; + bstate[b] = B_ROOST; bdir[b] = D_UP; + } + bx[0] = DOOR_X; by[0] = OUT_Y; bstate[0] = B_HUNT; bdir[0] = D_LEFT; + fright = 0; mode = 0; mode_i = 0; mode_time = 0; + nugget_on = 0; nugget_time = 0; + boom_time = 0; spr_off(SP_BOOM); +} + +/* ------------------------------------------------------------- screens */ +static void clear_all(void) +{ + gfill = 0; + while (gfill & 1); + all_off(); +} + +static u8 wait_fire(void) +{ + u8 j; + while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); } + for (;;) { + wait_frame(); drain_keys(); rnd(); + j = joy; + if (j & J_ESC) return 0; + if (j & (J_FIRE | J_ENTER)) return 1; + } +} + +static void get_ready(void) +{ + u8 i; + ink("1;93"); at(19, 36); puts_("GET READY"); ink("0"); + figure(SP_MINER, mx, my, S_MINER, 3); /* everyone waits where they are */ + for (i = 0; i < NB; i++) figure(SP_BAT + i, bx[i], by[i], bat_shape[i], 1); + for (i = 0; i < 100; i++) { wait_frame(); drain_keys(); } + at(19, 36); puts_(" "); +} + +static u8 title(void) +{ + u8 b; + clear_all(); + puts_("\033[0m\033[2J"); + reset_maze(); + wall_ink = 12; lamp_blink = 1; + draw_maze(); + place_all(); + figure(SP_MINER, mx, my, S_MINER, 1); + for (b = 0; b < NB; b++) figure(SP_BAT + b, bx[b], by[b], bat_shape[b], 1); + ink("1;93"); centre(5, " C R Y S T A L C A V E R N "); + ink("0;97"); + centre(8, " Gather every crystal in the cave, and keep away from the bats. "); + centre(9, " A lantern scares them for a while: then you can catch them. "); + centre(11, " ARROWS or W A S D move P pause ESC give up "); + ink("1;96"); centre(25, " PRESS SPACE TO BEGIN "); + ink("0"); + return wait_fire(); +} + +static void play(void) +{ + u8 j, i; + lives = 3; score = 0; level = 1; next_extra = 10000; + clear_all(); + puts_("\033[2J"); + for (;;) { /* each cave */ + reset_maze(); + wall_ink = 12; lamp_blink = 1; + draw_maze(); + eaten = 0; + place_all(); + dead = 0; + msg = 0; hud(); + get_ready(); + for (;;) { /* each frame */ + wait_frame(); + if (drain_keys()) { + at(1, 60); ink("0;93"); puts_("PAUSED - P TO GO ON\033[K"); ink("0"); + for (;;) { + wait_frame(); + if (joy & J_ESC) { quit = 1; return; } + if (drain_keys()) break; + } + hud_dirty = 1; + } + j = joy; + if (j & J_ESC) return; + if (!(last_frame & 15)) { lamp_blink ^= 1; draw_lamps(); } + if (!dead) { + miner(j); + modes(); + bats(); + nugget(); + } else { + spr_at(SP_BOOM, MX0 + mx - 8, MY0 + my - 8, S_BOOM, (boom_time & 4) ? 1 : 0); + spr_off(SP_MINER); + if (boom_time) boom_time--; + if (!--dead_time) { + if (!--lives) { + hud(); + ink("0;44;97"); + centre(14, " "); + centre(15, " GAME OVER "); + centre(16, " "); + ink("0"); + for (i = 0; i < 150; i++) { wait_frame(); drain_keys(); } + return; + } + place_all(); + dead = 0; + hud_dirty = 1; + hud(); + get_ready(); + } + } + if (msg_time && !--msg_time) hud_dirty = 1; + if (hud_dirty) hud(); + if (!left) break; /* every crystal gathered */ + } + say("CAVE CLEARED"); + hud(); + for (i = 0; i < 8; i++) { /* the walls flash */ + wall_ink = (i & 1) ? 12 : 15; + draw_maze(); + for (j = 0; j < 12; j++) { wait_frame(); drain_keys(); } + } + all_off(); + level++; + } +} + +int main(void) +{ + rnd_state = 0x1980 ^ frame_ctr; + last_frame = frame_ctr; + puts_("\033[?3l\033[?25l"); + load_shapes(); + quit = 0; + while (!quit) { + if (!title()) break; + play(); + } + clear_all(); + puts_("\033[0m\033[2J\033[H\033[?25h"); + while (con_stat & 1) (void)con_data; +} diff --git a/games/cavern/cavern.ihx b/games/cavern/cavern.ihx new file mode 100644 index 0000000..534d067 --- /dev/null +++ b/games/cavern/cavern.ihx @@ -0,0 +1,738 @@ +:10A2000097320000938282DF173300001303C316D6 +:10A2100063F8620023A00200938242006FF05FFFA8 +:10A2200017130000670003C2834700F093F727006D +:10A23000E38C07FEA300A0F067800000130101FF7C +:10A240002324810023261100130405000345040084 +:10A25000631A05008320C10003248100130101015A +:10A26000678000001304140097000000E78000FCE2 +:10A270006FF0DFFD130101FE232C8100232A9100E2 +:10A28000232E110093840500130400009306A00000 +:10A29000130690003377D5029307040093870701D4 +:10A2A000B3872700130414001374F40F1307070374 +:10A2B000238CE7FE930705003355D502E36CF6FCCB +:10A2C000636E9400631804028320C101032481019A +:10A2D000832441011301010267800000130500037C +:10A2E0009384F4FF97000000E78040F493F4F40FA8 +:10A2F0006FF01FFD1304F4FF1374F40F93070401B0 +:10A30000B387270003C587FF97000000E78000F2AE +:10A310006FF05FFB130101FF2322910093040500FE +:10A320001305B001232611002324810013840500A6 +:10A3300097000000E78080EF1305B005970000004C +:10A34000E780C0EE9305000013850400970000002D +:10A35000E78080F21305B00397000000E78000ED6E +:10A36000130504009305000097000000E780C0F08B +:10A37000032481008320C10083244100130580044D +:10A380001301010117030000670043EA130101FFF5 +:10A3900023248100130405001305B00123261100B6 +:10A3A00097000000E78080E81305B00597000000E3 +:10A3B000E780C0E71305040097000000E78040E84D +:10A3C000032481008320C1001305D006130101017D +:10A3D00017030000670083E5130101FF23248100B8 +:10A3E0002326110013840500930700003307F400AF +:10A3F00003470700631A070293D7170093059002DB +:10A40000B385F54093F5F50F97000000E780C0F0A5 +:10A4100013050400032481008320C10013010101FE +:10A42000170300006700C3E19387170093F7F70F46 +:10A430006FF0DFFBB7D7000003D5070013177500D7 +:10A440003345E50013150501135505011357950014 +:10A450003345E500131785003345E5001315050165 +:10A46000135505012390A70067800000B7D70000AF +:10A4700003C74700834680F7E38EE6FE034780F775 +:10A480002382E700678000001305000093060005A3 +:10A49000834700F093F7170063940700678000007C +:10A4A000034710F01377F70D6304D70093070500F7 +:10A4B000138507006FF0DFFDB7D80000B7D50000A7 +:10A4C00037D50000238F0802130600001303000095 +:10A4D000930700009385C5CC930E100013058504E7 +:10A4E000130FC001930FC03293060600130700003C +:10A4F0003388B600034E08001308EEFF1378F80FF8 +:10A5000063E80E019387170093F7F70F130310000A +:10A510003388A600130717002300C8011377F70F2D +:10A5200093861600E316E7FD1306C601E31EF6FB4D +:10A5300063040300238FF80267800000130101FF0A +:10A54000B7D7000093051000130510002326110053 +:10A55000238107002324810023229100970000001B +:10A56000E78080DB37C500001305851E97000000DB +:10A57000E78000E237C500001305051F97000000C3 +:10A58000E78000CCB7C4000013854420970000008A +:10A59000E78000E037C500001305C52097000000E4 +:10A5A000E78000CA37C4000013054421970000006B +:10A5B000E78000DEB7D7000003D5C703930560002E +:10A5C00097000000E78040CB1385442097000000EF +:10A5D000E78000DC37C500001305C52197000000A7 +:10A5E000E78000C61305442197000000E78040DAA9 +:10A5F000B7D7000003C527049305000097000000AB +:10A60000E78080C71385442097000000E78040D88A +:10A6100037C500001305852297000000E78040C27F +:10A620001305442197000000E78080D6B7D70000CB +:10A6300003C517049305000097000000E780C0C31E +:10A64000B7D7000003A4C7FF630E0402B7D700000A +:10A6500083C797FF6388070237C5000013054523AA +:10A6600097000000E780C0D237C500001305C5235E +:10A6700097000000E780C0BC1305040097000000AD +:10A68000E78000BC37C500001305052497000000D3 +:10A69000E78000BB032481008320C10083244100A4 +:10A6A00037C50000130545241301010117030000FD +:10A6B000670003CEB7D7000003D7C703B7D60000A3 +:10A6C0003305E5001315050113550501239EA70267 +:10A6D00083D766006360F50437270000130707710E +:10A6E000B387E70037D700002393F600834727049A +:10A6F000938717002301F704B7C7000037D700007E +:10A7000093878724232EF7FEB7D70000130780070F +:10A71000A38CE7FEB7D70000130710002381E700E2 +:10A7200067800000B7D70000130700072393E704F2 +:10A73000B7D700001307C00B2392E704930720004C +:10A7400037D70000A303F70237D700002303F7022F +:10A75000B7066C0037D70000A30207029386C6062F +:10A7600037D7000037067C002328D7021306C6051A +:10A77000130707032322C7003737507813070780D2 +:10A7800037D60000232CE60037070303B7D50000B7 +:10A790001307373037D5000023A0E502232C05022C +:10A7A000230CF5022380F502B7D70000A38B070026 +:10A7B000B7D7000023880700B7D70000A38707009A +:10A7C000B7D700002399070037D70000B7D700009C +:10A7D00037066C00232E0700A385070037D700003B +:10A7E000B7D700001306C6042324C7022396070028 +:10A7F00013078702B7D70000238507002322D7005D +:10A80000930760002308F0F6A30A00F667800000B3 +:10A81000230A00F2834740F393F71700E39C07FEF7 +:10A82000130700022308F0F693871700A30A00F627 +:10A8300093F7F70FE398E7FE678000001397050191 +:10A84000135707019307C00163E2E7046358050249 +:10A850001305C50113150501135505411307C00163 +:10A86000B385E502B7D7000093878704B387B700A5 +:10A87000B387A70003C50700678000009307B001F6 +:10A88000E3DEA7FC130545FE6FF0DFFC13051000A7 +:10A89000678000001307C0013387E502B7D70000C7 +:10A8A00093878704130101F923248106232291064B +:10A8B000232C410593046500232A510523286105B3 +:10A8C000B387E70023267105232291052320A105E4 +:10A8D000232EB103B387A7002326110623202107C7 +:10A8E000232E31052324810503CC070093D7540080 +:10A8F0002324F1009317050193D707411387F5FF30 +:10A900002320F1009317070193D707412326F10075 +:10A91000938715002328F1009397050193D70741EA +:10A92000930AF5FF2322F10093970A0193D7074179 +:10A9300013943500139A34001374F40F232AF10092 +:10A9400093071500930D0500930CD00F130D000015 +:10A9500093041000232CF100B7DA0000130B8000E1 +:10A96000930B60001304B400137AFA0F232401023E +:10A9700023260102631E9C168325C10003250100C6 +:10A9800097000000E780C0EB8325010193090500D3 +:10A990000325010097000000E78080EA832541003D +:10A9A000130905000325410197000000E78040E9F5 +:10A9B00013030000630485013333B0018325410094 +:10A9C00003258101232E610097000000E78040E706 +:10A9D0000323C101930500006304950093B5BD01F5 +:10A9E00003C58AFF13070000631C9D00639EA90135 +:10A9F0006316970C631A0300130720006FF0DFFE45 +:10AA0000E3187DFFE30699FE93078102338EE7008A +:10AA10002300AE0013071700E31867FD1377FD0F3F +:10AA20006316070A13071000639AE90A631E030AF4 +:10AA300063840500A3070102230840F383278100F4 +:10AA400033878C001377F70FA308F0F22309E0F2A5 +:10AA50001307000093078102B385E70083C5050053 +:10AA600013071700A309B0F2E31667FF93871C00D2 +:10AA700093FCF70F13075000130D1D00E398ECEE45 +:10AA80008320C1060324810683244106032901068D +:10AA90008329C105032A8105832A4105032B01056A +:10AAA000832BC104032C8104832C4104032D010456 +:10AAB000832DC1031301010767800000E31C77F5B4 +:10AAC000E39405F4130770006FF01FF21305700094 +:10AAD000E31EA7F413071000E30AE9F4232401029C +:10AAE000232601026FF09FF4230401026FF05FF44C +:10AAF00093074000631EFC00E3E094F537170D0D4B +:10AB00001307D7D02324E1022326E1026FF0DFF2FE +:10AB100093072000631CFC001307E000E3EE94F1B0 +:10AB20002306E102A305E1026FF01FF113073000D5 +:10AB3000E314ECF037D7000003478700E30E07EE7D +:10AB400013872C001377F70F93055000E3E6E5EE2B +:10AB5000130720043357A7019375170013B7150087 +:10AB600013076700938515001305B00063CAE5005D +:10AB700013071000E36297ED1307F0006FF05FFA20 +:10AB8000930781023383B7002300A3009385150048 +:10AB90006FF0DFFD130101FE232A9100232821011C +:10ABA00023263101232E1100232C81009304000061 +:10ABB0001309C0019309D001130400001305040018 +:10ABC00013041400938504001374F40F970000001D +:10ABD000E78080CCE31424FF9384140093F4F40FF3 +:10ABE000E39C34FD8320C1010324810183244101BE +:10ABF000032901018329C1001301010267800000BC +:10AC0000B7C700009387C743B387C7008387070090 +:10AC100093D5354013553540B385F500B7C70000CF +:10AC2000938747443386C700830706009395050141 +:10AC3000130101FF3305F5001315050193D50541F7 +:10AC4000135505412326110097000000E78040BFFF +:10AC50009307600063EEA7009307D00433D5A700E5 +:10AC6000137515008320C1001301010167800000E6 +:10AC7000130500006FF01FFF9387F50093970701FE +:10AC80002308A0F693D707011305E014636CF500C1 +:10AC90009307F6009397070193D707011305E00F79 +:10ACA0006376F500A30A00F66780000093F7F50FBE +:10ACB00093D58540A308F0F693F515002309B0F667 +:10ACC0001376F60FA309C0F6230AD0F6A30AE0F61E +:10ACD000678000009395050193D505011388C5FF92 +:10ACE00013180801135808019308800D63F8080130 +:10ACF0002308A0F6A30A00F667800000938585026A +:10AD00009395050193D5054117030000670003F7EC +:10AD100037C50000130101FE13054525232E110040 +:10AD2000232C8100232A910023282101232631018D +:10AD30002324410197F0FFFFE780806593054002DF +:10AD40001305300197F0FFFFE780005D37C5000075 +:10AD50001305C52597F0FFFFE780804E37C500003B +:10AD60001305452497F0FFFFE7808062B7D7000006 +:10AD700003964704B7D70000839567041307300094 +:10AD80009306000013050000B7D9000037D9000072 +:10AD9000B7C4000097000000E78000F4938909031E +:10ADA000130989029384844313040000130A4000AA +:10ADB00083C60400031609008395090013041400D8 +:10ADC0001374F40F1307100013050400970000001C +:10ADD000E78080F0938929001309290093841400E7 +:10ADE000E31844FD130440061304F4FF97F0FFFF3B +:10ADF000E78000681374F40F97F0FFFFE7800069A5 +:10AE0000E31404FE130530019305400297F0FFFFA1 +:10AE1000E7808050032481018320C1018324410104 +:10AE2000032901018329C100032A810037C50000DD +:10AE3000130585261301010217F3FFFF6700434046 +:10AE4000130101F8232E1106232C8106232A9106D3 +:10AE500023282107232631072324410723225107D2 +:10AE600023206107232E7105232C8105232A9105B8 +:10AE70002328A1052326B105834780F73727000043 +:10AE800013070798B3C7E70037D700002310F70070 +:10AE9000834780F737C5000037D7000013054527E3 +:10AEA0002302F70097F0FFFFE7808039B7C7000063 +:10AEB0009387C7441307000093061001230BE0F6A5 +:10AEC0001386070883C5070093871700A30BB0F606 +:10AED000E39AC7FE130717001377F70FE310D7FEA7 +:10AEE000B7D70000B7C90000A38107009389494480 +:10AEF000B7D7000003C437006312041A970000009C +:10AF0000E7804091B7C700001385072897F0FFFF3F +:10AF1000E780003397F0FFFFE780405A9307C000B7 +:10AF200037D70000230CF7FEB7D700001307100037 +:10AF30002384E70097000000E78000C697F0FFFF3A +:10AF4000E780807EB7D7000003964704B7D700009C +:10AF50008395670413071000930600001305000093 +:10AF600097000000E78040D7B7C7000037D900003E +:10AF7000B7D40000138A874393878743938484025E +:10AF800013090903232EF100930A400083460A00A7 +:10AF90000396040083150900130414001374F40FBE +:10AFA000130710001305040097000000E780C0D2CB +:10AFB0001309290093842400130A1A00E31854FD8E +:10AFC00037C500001305452597F0FFFFE780403C9B +:10AFD000B7C500009385C5281305500097F0FFFF03 +:10AFE000E780C03F37C500001305452197F0FFFFFC +:10AFF000E780003AB7C500009385C52A1305800095 +:10B0000097F0FFFFE780803DB7C500009385052FCF +:10B010001305900097F0FFFFE780403CB7C50000A4 +:10B02000938505331305B00097F0FFFFE780003BE1 +:10B0300037C500001305853697F0FFFFE7804035E0 +:10B04000B7C50000130590019385053797F0FFFF02 +:10B05000E780C03837C500001305452497F0FFFF8F +:10B06000E7800033834780F893F7070B639C07085A +:10B0700097F0FFFFE780C03F97F0FFFFE7800041B8 +:10B0800097F0FFFFE780403B834780F813F7F70F07 +:10B090009397870193D7874163D0070897F0FFFF05 +:10B0A000E780407737C500001305853897F0FFFF2C +:10B0B000E7800019834700F093F7170063840700C7 +:10B0C0006F10400F8320C1070324810783244107A9 +:10B0D000032901078329C106032A8106832A410621 +:10B0E000032B0106832BC105032C8105832C41050D +:10B0F000032D0105832DC104130500001301010870 +:10B100006780000097F0FFFFE780803697F0FFFF31 +:10B11000E780C0376FF01FF593770703E38A07F4E2 +:10B12000B7D70000130730002381E704B7D700002A +:10B13000239E070213071000B7D70000A380E7047F +:10B14000B72700009387077137D700002313F70054 +:10B1500097F0FFFFE780006C37C500001305452816 +:10B1600097F0FFFFE780C00D1304100037DA0000EE +:10B1700097F0FFFFE78080349307C00037D70000C7 +:10B18000230CF7FE13071000B7D700002384E70055 +:10B1900097000000E78040A0B7D700002387070092 +:10B1A00097F0FFFFE7804058B7D7000023800704DF +:10B1B000B7D7000023AE07FE37C9000097F0FFFFA6 +:10B1C000E780003897000000E780C0B49307C943C8 +:10B1D0002324F10097F0FFFFE780802997F0FFFF1D +:10B1E000E780C02A630205089305C0031305100019 +:10B1F00097F0FFFFE780401237C500001305851E5A +:10B2000097F0FFFFE780C01837C500001305C53968 +:10B2100097F0FFFFE780C00237C500001305452403 +:10B2200097F0FFFFE780C01697F0FFFFE78040240C +:10B23000834780F89397870193D7874163DA0700A4 +:10B240009307100037D70000A301F7006FF05FCA23 +:10B2500097F0FFFFE7808023E30805FCB7D70000E5 +:10B26000130710002381E700834780F893FBF70F53 +:10B270009397870193D78741E3CC07C6B7D70000E0 +:10B2800083C4470093F4F4006390040637D70000AA +:10B290008347870037DB0000130B8B0493C717002D +:10B2A0002304F700130C3000930CC001130DD001E0 +:10B2B000930A0000B3075B0183C70700639A870105 +:10B2C0009385040013F5FA0F97F0FFFFE780C05C49 +:10B2D000938A1A00E3909AFF9384140093F4F40F76 +:10B2E000130BCB01E396A4FD37DB000083470B046F +:10B2F000B7D40000B7DA00008395640403964A04CB +:10B30000E394074A93F74B00638A0700B7D700001E +:10B31000130720002383E7026F00400193F78B009F +:10B320006384073CB7D7000023830702B7DC000023 +:10B3300083C71C0493065000B7DB00001387070087 +:10B3400063F4F6001307500083C75B0237DC00008C +:10B35000B7DD000093870701B387E700A382FB02F4 +:10B36000130C8C0383C75B021307F0006362F73A88 +:10B37000B7D7000083C64702B7D70000839564049F +:10B3800083C4770293D626009307200003964A04CD +:10B3900093F61600130710006394F40013073000AF +:10B3A0001305000097000000E780009303477A012F +:10B3B000B7D7000037D80000938A07021308880324 +:10B3C000630A075837D70000835747019387F7FF71 +:10B3D0009397070193D70701231AF7006394070097 +:10B3E000A30B0A009387C4FF130C2000638407009B +:10B3F000138C04009377FC0FB7DC00002328F100C6 +:10B4000093878C012326F100B7D7000037DB0000BB +:10B41000138C8702B7D7000013090800130BCB0168 +:10B42000938C0703930D000093F7FD0F232CF1007D +:10B430008327C1000347090083C4070093841400D5 +:10B4400093F4F40F238097006314070263888D5CE4 +:10B45000130720006390ED5A37D700008346E700BA +:10B460001307D001636CD75A1307000F6368975A0C +:10B4700003460900130780029306D6FF93F6F60FE2 +:10B480006372D40613072000631EE60283467A0126 +:10B49000130780006398060483160C001306E0006F +:10B4A00093D636406390C60283960C001306F000D4 +:10B4B00093D636409386A6FF9396060193D606014F +:10B4C0006362D60237D70000834617041306500084 +:10B4D000138706006374D600130750001307E700B4 +:10B4E0001377F70F83460B003307D7002300EB00D9 +:10B4F00013D73400137717009306F0FF6304070097 +:10B50000930610009397060193D70701232AF100B1 +:10B5100037DD000003470B009306F00003460900E7 +:10B5200063E2E650B7DB000083C50B0483960C0092 +:10B5300003170C00639A050A930520006316B60AE8 +:10B54000B7D5000083D56504232AC100B386B64071 +:10B550009395060193D5054193D5F540B3C6D50023 +:10B56000B386B6409396060193D6064193055000E4 +:10B5700063CCD506B7D6000083D646043307D74040 +:10B580009316070193D6064193D6F64033C7E600DB +:10B590003307D740131707011357074163C6E50464 +:10B5A00037D7000003477701E306070CB7D7000041 +:10B5B00003CD67011305800C130730003315A50177 +:10B5C000131505012300E9001355050197F0FFFF4E +:10B5D000E780800E032641016368A601130D1D005C +:10B5E000B7D70000238BA701034609009306E000AC +:10B5F0001307D6FF1377F70F637AE40203477A0144 +:10B6000093D4340093F61400E304070CE372C40CE3 +:10B6100037D700000357470113067007E366E60AB1 +:10B6200013778700E302070A9386C6008327810108 +:10B6300003160C0083950C001385170013071000E8 +:10B640001375F50F97F0FFFFE78000698327C100AE +:10B65000938D1D0013074000938717002326F100E8 +:10B6600013091900938C2C00130C2C00130B1B00D6 +:10B67000938A1A00E39AEDDAB7D6000083C7B600C2 +:10B6800037D70000639A0702B7D7000083C7E700E7 +:10B69000130660046386C7001306A00A639EC700F2 +:10B6A0008357C700639A070093071000A385F6002D +:10B6B0009307C0212316F7008357C700E3860702CC +:10B6C0009387F7FF9397070193D707012316F70096 +:10B6D000E39C0700A3850600930750002308F0F6BB +:10B6E000A30A00F66F00501E93F71B006388070043 +:10B6F000B7D70000130730006FF0DFC193FB2B00BA +:10B70000E3860BC2B7D70000130710006FF09FC08D +:10B7100003CB6D02938707FFA382FB0293074000D0 +:10B72000630EFB0037D7000083477702938727001B +:10B7300093F737006314FB00A303670303976404C4 +:10B7400093064000039D4A0493777700638AD706E7 +:10B75000B7D7000083C677021307400083976404BD +:10B7600003964A04E380E6C0832581003387D9002D +:10B7700003070700B386D50083860600B387E7007A +:10B780001397070193970701B306D60093D7074194 +:10B790002392DA042393F404930680FF13570701DE +:10B7A00063D2D71A1307070F2393E40437D7000097 +:10B7B00083474702938717002302F7026FF09FBA6F +:10B7C00093767D00E396F6F813573740135D3D40BE +:10B7D00093050D00130507002326E10097F0FFFFF6 +:10B7E000E78000069307E5FF93F7F70F13090500BD +:10B7F000636CF4060327C1001306B0019317070119 +:10B8000093D707016368F6021306C0013306CD0221 +:10B81000B7D70000938787049375FD0F1375F70F53 +:10B82000B387C700B387E7002380070097F0FFFFC7 +:10B83000E780800637D700008347E7039387F7FF49 +:10B84000230FF70293072000631AF9061305A000DF +:10B8500097F0FFFFE78040E637D700008347E70017 +:10B86000938717002307F70013074000039D640424 +:10B8700083954A0437D900006302EB0213060B00DC +:10B8800013050D002326B10097F0FFFFE7808037F6 +:10B890008325C10063040500A303690303467902FD +:10B8A00093074000E300F6AC13050D0097F0FFFF8F +:10B8B000E7804035E31E05E86FF0DFAA130520039B +:10B8C00097F0FFFFE78040DF93071000A30BFA001B +:10B8D000B7D70000238B070083C71C0493066000C2 +:10B8E0001307400663ECF600130780FDB387E702F9 +:10B8F000938787161397070113570701B7D70000DF +:10B90000239AE700B7D70000938707029306000049 +:10B910009305200013064000338786010347070084 +:10B92000631AB70003C70700130727001377370010 +:10B930002380E7009386160093871700E39EC6FCDA +:10B940006FF09FF19306700EE3D2F6E6130707F14E +:10B950006FF09FE537D500008345F50037C700003D +:10B96000130787423307B700834607001307F00F1A +:10B97000E38AE6A69308C003B386160337D6000011 +:10B980000357260113071700131707011357070161 +:10B990006356D7002319E6006FF0DFA41387150064 +:10B9A000B7D60000A307E50003C706012319060068 +:10B9B00093870702134717002388E60093052000AA +:10B9C0009306000013064000338706010347070073 +:10B9D000631AB70003C70700130727001377370060 +:10B9E0002380E7009386160093871700E39EC6FC2A +:10B9F0006FF05F9F13073000E39CEDA637D7000080 +:10BA00000347E7009306B00363EAE6009306A00F3E +:10BA1000E3F096A693063001E3FCE6A42300890038 +:10BA20006FF01FA5130707FF2300EB0063068604D2 +:10BA3000130740006308E6086314060A03570C0066 +:10BA400083274101930680063387E7001317070118 +:10BA50001357074163DAE6009306F00663CAE6006F +:10BA60002310EC006FF01FAB130790066FF05FFF21 +:10BA70002310DC006FF01FAA03970C009306B0069A +:10BA800063C8E600130717002390EC006FF09FA82F +:10BA90009306C0066306D7001307F7FF6FF0DFFEBB +:10BAA00003170C009306C00463D6E6001307F7FFE4 +:10BAB0006FF01FFB130720002300E9002380EA003A +:10BAC0006FF05FA503170C009306B00663C6E6008F +:10BAD000130717006FF0DFF8230089006FF09FA3B2 +:10BAE000039E0C0083150C0093767E00639EE6088F +:10BAF00013F77500631AD70893063000631ED6004B +:10BB00009306C006631ADE009306C0046396D50050 +:10BB10002300E9006FF01FA083CB0A0003477A01DE +:10BB2000938B2B0093FB3B006304070C130720004F +:10BB30006310E60C97F0FFFFE78000909376F50F17 +:10BB400013070000130E40003386E600137636001C +:10BB50006386CB0883150C0003950C002324E102B7 +:10BB60002322D1022320C10297F0FFFFE780800942 +:10BB7000032601028326410203278102130E40009F +:10BB8000630E05042380CA0003C60A0083278100D0 +:10BB90003387C9008306070003D70C003386C7002C +:10BBA0008305060003560C003307D70093160701E0 +:10BBB000131707013306B600135707412310CC00B3 +:10BBC0002390EC00130680FF93D60601635CC72820 +:10BBD0009386060F2390DC006FF0DF9313071700A6 +:10BBE0001377F70FE312C7F723807A016FF0DFF9BD +:10BBF00037D70000130F300083166D040317470476 +:10BC000013553E4093DE3540630EE62337D60000E1 +:10BC1000034606016314061237C7000013074743A3 +:10BC20003387ED008306070037C70000130707437B +:10BC30003387ED0003070700B38EEE403305D54090 +:10BC400093160501939E0E01B78F000093D606014F +:10BC500093DE0E01138F0B0013070000938FFFFF7D +:10BC6000930240001376F70F6302760D13050E0062 +:10BC7000232ED103232CD102232AE1032328F1030D +:10BC80002326E1022322B1022320C1032324C1027F +:10BC900097F0FFFFE78000F7032E010283254102A2 +:10BCA0000327C102832F0103032F4103832681034E +:10BCB000832EC10393024000630A05063305370152 +:10BCC0000305050083278100032681023385A60032 +:10BCD0009313050193D3034193D3F34033C5A300DA +:10BCE00033057540B303F70083830300B3837E00FD +:10BCF0009390030193D0004193D0F040B3C3700000 +:10BD0000B383134033057500131505011355054121 +:10BD10006340F515631CF501130530006300A7149B +:10BD20009303200063147700631AAF121307170000 +:10BD3000E31A57F22380EA016FF01FE593D63640ED +:10BD40001357374063808D0613062000638CCD089F +:10BD5000E3840DEE3306D540131F0601135F0F4138 +:10BD6000135FFF403346CF003306E641338FEE408A +:10BD7000931F0F0193DF0F4193DFFF4033CFEF019C +:10BD8000330FFF413306E601131606011356060171 +:10BD9000130F8000E362CFEA1307E001930610005F +:10BDA0006FF09FE9832701013386F900030606003F +:10BDB0008327810013162600B306D600032601014F +:10BDC0009396060193D606413386C7000306060004 +:10BDD000131626003307E600131707011357074110 +:10BDE0006FF09FE5832701013386F9000306060003 +:10BDF0008327810013161600B306D60037D600003D +:10BE0000031606039396160013563640B386C640B3 +:10BE1000032601019396060193D606413386C70097 +:10BE200003060600131616003307E60037D6000097 +:10BE30000316860213171700135636403307C74000 +:10BE40006FF09FF9130790009306D0006FF0DFDECC +:10BE5000130F0600930F05006FF05FED130F060040 +:10BE60006FF0DFEC1306700E6356E6EA938606F178 +:10BE70006FF05FD637D700000347F703631607F666 +:10BE800037D7000013064006A304C70037D70000C9 +:10BE90001306C0032305C70037C7000037D60000CC +:10BEA0001307473B232EE6FE37D700001306800713 +:10BEB00093061000A30CC7FE37D700002380DB04D5 +:10BEC0002301D7006FF04FF29386A6006FF00FF6B4 +:10BED0008327C1013387B70103470700B386E60014 +:10BEE00093F6F60F6FF08FF483C7B600638607FEF4 +:10BEF00083C70B046394072CB7D7000083D767046C +:10BF000093055000938707F91396070113560641CE +:10BF10001356F640B347F600B387C740939707011F +:10BF200093D7074163CCF528B7D7000083D74704E0 +:10BF3000938747F413960701135606411356F640AC +:10BF4000B347F600B387C7409397070193D70741DC +:10BF500063C6F526B7D7000003C517049307401F33 +:10BF6000930410003305F50223169700A3850600FD +:10BF7000131505011355050197E0FFFFE780C07316 +:10BF8000B7C7000037D700009387873C232EF7FE02 +:10BF9000B7D7000013078007A38CE7FEB7D70000D0 +:10BFA000238197006FF04FF3B7D4000003C7A400BC +:10BFB0009385850293950501135727401377170042 +:10BFC0009306000193D505411305600097F0FFFF2C +:10BFD000E780C0CA230800F6A30A00F683C7A400BE +:10BFE000638607009387F7FF2385F40037D70000A7 +:10BFF000834797009387F7FF93F7F70FA304F700A2 +:10C000006394070C37D70000834727049387F7FF13 +:10C0100093F7F70F2301F7046394070897E0FFFFF6 +:10C02000E780005237C500001305053D97E0FFFF8C +:10C03000E780003637C400009305843D1305E00017 +:10C0400097E0FFFFE7808039B7C500009385853F03 +:10C050001305F00097E0FFFFE78040389305843D2B +:10C060001305000197E0FFFFE780403737C5000068 +:10C070001305452497E0FFFFE78080311304600932 +:10C080001304F4FF97E0FFFFE780803E1374F40F82 +:10C0900097E0FFFFE780803FE31404FE6FE05FE579 +:10C0A00097E0FFFFE7804068B7D700001307100054 +:10C0B0002381E70023000B0497E0FFFFE78040485F +:10C0C00097F0FFFFE78000C537DB000083479BFF49 +:10C0D000B7D40000638407029387F7FF93F7F70F45 +:10C0E000A30CFBFE639C0700930710002381F40060 +:10C0F00097E0FFFFE780C0446F00C00083C72400C3 +:10C10000E39807FEB7D7000083CAE70363940A8C5D +:10C11000B7C7000037D7000093878741232EF7FE6B +:10C1200093078007A30CFBFE930710002381F40004 +:10C1300097E0FFFFE780C0409304800093F71A0068 +:10C140001307F000638407001307C000B7D700008F +:10C15000238CE7FE1309C00097F0FFFFE780C0A320 +:10C160001309F9FF97E0FFFFE78080301379F90F9B +:10C1700097E0FFFFE7808031E31409FE938A1A00FD +:10C1800093FAFA0FE39C9AFA93070002230820F728 +:10C1900013091900A30A00F61379F90FE318F9FE41 +:10C1A00037D700008347170493871700A300F704CD +:10C1B0006FE01FFC834710F06FE0DFEF9307500044 +:10C1C0002308F0F6930780F9A308F0F6230900F698 +:10C1D0009307C0FBA309F0F69307F000230AF0F6DB +:10C1E000A30A80F66FF05FEE303B393300000000A9 +:10C1F0004352595354414C2043415645524E2020FE +:10C2000020000000303B33370000000053434F5202 +:10C2100045200000303B3937000000002020204C32 +:10C220004956455320000000202020434156452018 +:10C2300000000000303B39360000000020202000C4 +:10C240001B5B4B00300000004558545241204C49C4 +:10C2500046450000313B393300000000474554207B +:10C260005245414459000000202020202020202059 +:10C27000200000001B5B3F336C1B5B3F32356C00C2 +:10C280001B5B306D1B5B324A0000000020432052D4 +:10C290002059205320542041204C2020204320416D +:10C2A000205620452052204E200000002047617477 +:10C2B000686572206576657279206372797374613E +:10C2C0006C20696E2074686520636176652C20613E +:10C2D0006E64206B65657020617761792066726F8E +:10C2E0006D2074686520626174732E200000000068 +:10C2F0002041206C616E7465726E2073636172659B +:10C3000073207468656D20666F722061207768699C +:10C310006C653A207468656E20796F752063616E74 +:10C32000206361746368207468656D2E20000000CE +:10C33000204152524F5753206F72205720412053B3 +:10C34000204420206D6F7665202020202050207012 +:10C35000617573652020202020455343206769764E +:10C360006520757020000000313B39360000000068 +:10C3700020505245535320535041434520544F20A1 +:10C38000424547494E2000001B5B306D1B5B324A23 +:10C390001B5B481B5B3F3235680000005041555322 +:10C3A0004544202D205020544F20474F204F4E1BF6 +:10C3B0005B4B0000544845204241545320474F54A2 +:10C3C00020594F5500000000474F4C442100000009 +:10C3D000303B34343B3937002020202020202020DF +:10C3E000202020202020202020202020202020204D +:10C3F000202020202020000020202020202020207D +:10C40000202047414D45204F5645522020202020D6 +:10C4100020202020202000004341564520434C4549 +:10C4200041524544000000000714071405FF0000B6 +:10C43000FEFE1E1E1A011A0102040608000100FF7A +:10C44000000000000100FF000000000000000000EC +:10C450000000000000000BBBBBB000000000B333C5 +:10C460003333F00000033333333FF0000009999970 +:10C47000999900000009909909990000000999997B +:10C48000999900000000999009900000000CCCCC14 +:10C49000CCCC000000CCCCCCCCCC9000009CCCCC44 +:10C4A000CCCC000000044444444400000004440098 +:10C4B0000444000000077000007700000000000046 +:10C4C000000000000000000000000000000000006C +:10C4D0000000000000000BBBBBB000000000B33345 +:10C4E0003333F00000033333333FF00000099999F0 +:10C4F00099990000000990990999000000099999FB +:10C50000999900000000999009900000000CCCCC93 +:10C51000CCCC000000CCCCCCCCCC9000009CCCCCC3 +:10C52000CCCC0000000444444444000000004440DB +:10C530004440000000000770770000000000000089 +:10C5400000000000000000000000000000000000EB +:10C5500000000000000000000000000009000000D2 +:10C5600000000090099000000000099009990099CE +:10C5700099009990099999999999999000999F99F9 +:10C5800099F999000009999999999000000090995A +:10C5900099090000000009099090000000000000C7 +:10C5A000000000000000000000000000000000008B +:10C5B000000000000000000000000000000000007B +:10C5C000000000000000000000000000000000006B +:10C5D000000000000000000000000000000000005B +:10C5E00000000000000000000000000000000099B2 +:10C5F00099000000090999999999909009999F9932 +:10C6000099F9999009999999999999900990999975 +:10C61000999909900900009999000090000009007B +:10C62000009000000000000000000000000000007A +:10C6300000000000000000000000000000000000FA +:10C6400000000000000000000000000000000000EA +:10C650000000000000000000000000000D000000CD +:10C66000000000D00DD0000000000DD00DDD00DD79 +:10C67000DD00DDD00DDDDDDDDDDDDDD000DDDFDD8C +:10C68000DDFDDD00000DDDDDDDDDD0000000D0DDF5 +:10C69000DD0D000000000D0DD0D0000000000000F6 +:10C6A000000000000000000000000000000000008A +:10C6B000000000000000000000000000000000007A +:10C6C000000000000000000000000000000000006A +:10C6D000000000000000000000000000000000005A +:10C6E000000000000000000000000000000000DD6D +:10C6F000DD0000000D0DDDDDDDDDD0D00DDDDFDD89 +:10C70000DDFDDDD00DDDDDDDDDDDDDD00DD0DDDD00 +:10C71000DDDD0DD00D0000DDDD0000D000000D00DE +:10C7200000D0000000000000000000000000000039 +:10C7300000000000000000000000000000000000F9 +:10C7400000000000000000000000000000000000E9 +:10C750000000000000000000000000000A000000CF +:10C76000000000A00AA0000000000AA00AAA00AA77 +:10C77000AA00AAA00AAAAAAAAAAAAAA000AAAFAA1C +:10C78000AAFAAA00000AAAAAAAAAA0000000A0AABF +:10C79000AA0A000000000A0AA0A000000000000091 +:10C7A0000000000000000000000000000000000089 +:10C7B0000000000000000000000000000000000079 +:10C7C0000000000000000000000000000000000069 +:10C7D0000000000000000000000000000000000059 +:10C7E000000000000000000000000000000000AA9F +:10C7F000AA0000000A0AAAAAAAAAA0A00AAAAFAA86 +:10C80000AAFAAAA00AAAAAAAAAAAAAA00AA0AAAA96 +:10C81000AAAA0AA00A0000AAAA0000A000000A0012 +:10C8200000A0000000000000000000000000000068 +:10C8300000000000000000000000000000000000F8 +:10C8400000000000000000000000000000000000E8 +:10C8500000000000000000000000000003000000D5 +:10C8600000000030033000000000033003330033C9 +:10C8700033003330033333333333333000333F3318 +:10C8800033F33300000333333333300000003033ED +:10C8900033030000000003033030000000000000FC +:10C8A0000000000000000000000000000000000088 +:10C8B0000000000000000000000000000000000078 +:10C8C0000000000000000000000000000000000068 +:10C8D0000000000000000000000000000000000058 +:10C8E0000000000000000000000000000000003315 +:10C8F00033000000030333333333303003333F332B +:10C9000033F33330033333333333333003303333A0 +:10C9100033330330030000333300003000000300E2 +:10C9200000300000000000000000000000000000D7 +:10C9300000000000000000000000000000000000F7 +:10C9400000000000000000000000000000000000E7 +:10C9500000000000000000000000000004000000D3 +:10C960000000004004400000000004400444004473 +:10C9700044004440044444444444444000444F443C +:10C9800044F4440000044444444440000000404453 +:10C9900044040000000004044040000000000000C7 +:10C9A0000000000000000000000000000000000087 +:10C9B0000000000000000000000000000000000077 +:10C9C0000000000000000000000000000000000067 +:10C9D0000000000000000000000000000000000057 +:10C9E0000000000000000000000000000000004403 +:10C9F00044000000040444444444404004444F4480 +:10CA000044F44440044444444444444004404444C2 +:10CA1000444404400400004444000040000004007A +:10CA200000400000000000000000000000000000C6 +:10CA300000000000000000000000000000000000F6 +:10CA400000000000000000000000000000000000E6 +:10CA50000000000000000000000000000F000000C7 +:10CA6000000000F00FF0000000000FF00FFF00FFCB +:10CA7000FF00FFF00FFFFFFFFFFFFFF000FFFFFFD2 +:10CA8000FFFFFF00000FFFFFFFFFF0000000F0FFBF +:10CA9000FF0F000000000F0FF0F00000000000008A +:10CAA0000000000000000000000000000000000086 +:10CAB0000000000000000000000000000000000076 +:10CAC0000000000000000000000000000000000066 +:10CAD0000000000000000000000000000000000056 +:10CAE000000000000000000000000000000000FF47 +:10CAF000FF0000000F0FFFFFFFFFF0F00FFFFFFF31 +:10CB0000FFFFFFF00FFFFFFFFFFFFFF00FF0FFFF42 +:10CB1000FFFF0FF00F0000FFFF0000F000000F000C +:10CB200000F0000000000000000000000000000015 +:10CB300000000000000000000000000000000000F5 +:10CB400000000000000000000000000000000000E5 +:10CB500000000000000000000000000000000000D5 +:10CB600000000000000000000000000000000000C5 +:10CB70000000000000000000000000000000FF00B6 +:10CB800000FF00000000F40000F4000000000000BE +:10CB90000000000000000000000000000000000095 +:10CBA0000000000000000000000000000000000085 +:10CBB0000000000000000000000000000000000075 +:10CBC0000000000000000000000000000000000065 +:10CBD0000000000000000000000000000000000055 +:10CBE000000000000000000000000000000000BB8A +:10CBF000B00000000000BBBFBBB00000000BBFBB1B +:10CC0000BBBB0000000BBBBBB3BB00000000BB3BC9 +:10CC1000BBB0000000000BBBB00000000000000033 +:10CC20000000000000000000000000000000000004 +:10CC300000000000000000000000000000000000F4 +:10CC400000000000000000000000000000000000E4 +:10CC500000000000000F00000000F0000000F00BDA +:10CC6000B00F000000000F0BB0F00000000000BF8C +:10CC7000FB0000000BBB0BFFFFB0BBB0000000BF10 +:10CC8000FB00000000000F0BB0F000000000F00BF4 +:10CC9000B00F0000000F00000000F00000000000D6 +:10CCA0000000000000000000000000000000000084 +:10CCB0000000000000000000000000000000000074 +:10CCC0000000000000000000000000000101010160 +:10CCD0000101010101010101010101010101010144 +:10CCE000010101010101010101020202020202022D +:10CCF0000202010102020202010102020202020218 +:10CD0000020202010102010101020101010201010D +:10CD100002010102010102010101020101010201FE +:10CD200001020101010201010102010102010102EE +:10CD300001010201010102010101020101020101DF +:10CD400001020101010201010201010201010201CE +:10CD500001010201010102010103010101020202BC +:10CD600002020202020101020202020202020201A6 +:10CD7000010103010102010101020101010101019F +:10CD8000020101020101010101010201010102018F +:10CD9000010201010102010101010101020101027F +:10CDA0000101010101010201010102010102010170 +:10CDB0000102010101010101020101020101010160 +:10CDC000010102010101020101020101010202024D +:10CDD0000202010100000000010102020202020140 +:10CDE0000101020101020101010101010102010130 +:10CDF0000100000101010201010101010101020123 +:10CE0000010201010101010101020101010404010A +:10CE100001010201010101010101020101020101FF +:10CE200001010101010201050505050505010201D8 +:10CE300001010101010102010102010101010101E0 +:10CE400001020105050505050501020101010101B8 +:10CE500001010201060601010106020202020105AA +:10CE6000050505050501020202020601010106068B +:10CE7000010201010102010101020105050505058B +:10CE8000050102010101020101010201010201018A +:10CE9000010201010102010101010101010102017F +:10CEA000010102010101020101020101010201016E +:10CEB000010201010101010101010201010102015F +:10CEC000010102010102010101020101010201014E +:10CED000010101010101020101010201010102013F +:10CEE0000102020202020101010202020202020226 +:10CEF000020202010101020202020201010101011A +:10CF0000010101010101010102010102010101010F +:10CF10000101010101010101010101010101010101 +:10CF200001010101020101020101010101010101EF +:10CF300001010101010101010101010101010101E1 +:10CF400002010102010101010101010101010101CF +:10CF500001030202020202020202020202000002B5 +:10CF600002020202020202020202030101020101A4 +:10CF7000010201010102010102010102010102019C +:10CF8000010102010101020101020101010201018D +:10CF9000010201010201010201010201010102017C +:10CFA000010102010102010101020101010201016D +:10CFB000020101020101020101010201010102015C +:10CFC0000102020202020101010202020201010247 +:10CFD0000202020101010202020202010101010139 +:10CFE0000101010101010101010101010101010131 +:08CFF000010101010101010131 +:040000030000A20057 +:00000001FF diff --git a/games/cavern/gen.py b/games/cavern/gen.py new file mode 100644 index 0000000..cbf4667 --- /dev/null +++ b/games/cavern/gen.py @@ -0,0 +1,250 @@ +#!/usr/bin/env python3 +"""Make data.h for cavern.c: the maze and the sprite shapes. + +The maze is 28 x 29 tiles of 8 x 8 pixels, mirrored left to right. It is +built from a grid of junctions joined by straight corridors: every link is +made, then links are taken away at random as long as every junction keeps at +least two, the whole cave stays connected and the fixed parts (the crossings +at the roost and the start, the side tunnels) stay. So there are no dead ends, +which a chase game can't have. The bats' roost sits in the middle. + +Tiles: 0 open, 1 wall, 2 crystal, 3 lantern, 4 roost door, 5 roost, 6 tunnel. +""" +import random +import sys +from collections import deque + +W, H = 28, 29 +NX = [1, 5, 9, 12] # junction columns on the left (12 mirrors to 15) +NY = [1, 5, 9, 14, 19, 23, 27] # junction rows +ROOST = (10, 11, 17, 16) # cols 10-17, rows 11-16 (x0, y0, x1, y1) +TUNNEL_Y = 14 +START = (13, 23) # the miner starts between 13 and 14 on row 23 +LANTERNS = [(1, 5), (1, 23)] # and their mirror images + + +def mirror(x): + return W - 1 - x + + +def build(seed): + rnd = random.Random(seed) + nodes = {(x, y) for x in NX for y in NY} + nodes.discard((12, 14)) # inside the roost + edges = set() + for y in NY: + row = [x for x in NX if (x, y) in nodes] + for a, b in zip(row, row[1:]): + if not (y == 14 and b == 12): + edges.add(((a, y), (b, y))) + if (12, y) in nodes: + edges.add(((12, y), (15, y))) # across the middle + for x in NX: + col = [y for y in NY if (x, y) in nodes] + for a, b in zip(col, col[1:]): + if x == 12 and a < ROOST[3] and b > ROOST[1]: + continue # would run through the roost + edges.add(((x, a), (x, b))) + fixed = {((12, 9), (15, 9)), ((12, 23), (15, 23))} + + def full(es): + g = {} + for (a, b) in es: + for p, q in ((a, b), (b, a)): + g.setdefault(p, set()).add(q) + if a[0] == 12 and b[0] == 15: + continue + ma, mb = (mirror(a[0]), a[1]), (mirror(b[0]), b[1]) + g.setdefault(ma, set()).add(mb) + g.setdefault(mb, set()).add(ma) + return g + + def ok(es): + g = full(es) + # the tunnel ends count as a link for (1, 14) + deg = {n: len(v) + (1 if n[1] == TUNNEL_Y and n[0] in (1, mirror(1)) else 0) for n, v in g.items()} + if any(d < 2 for d in deg.values()): + return False + start = next(iter(g)) + seen, q = {start}, deque([start]) + while q: + for m in g[q.popleft()]: + if m not in seen: + seen.add(m); q.append(m) + return len(seen) == len(g) + + order = sorted(edges - fixed) + rnd.shuffle(order) + for e in order: + if rnd.random() < 0.45 and ok(edges - {e}): + edges.discard(e) + assert ok(edges) + + grid = [[1] * W for _ in range(H)] + def carve(x, y, t=2): + for xx in (x, mirror(x)): + if grid[y][xx] == 1: + grid[y][xx] = t + for (a, b) in edges: + if a[1] == b[1]: + for x in range(min(a[0], b[0]), max(a[0], b[0]) + 1): + carve(x, a[1]) + else: + for y in range(min(a[1], b[1]), max(a[1], b[1]) + 1): + carve(a[0], y) + # the roost: walls round a room, a door at the top, a way up to row 9 + x0, y0, x1, y1 = ROOST + for y in range(y0, y1 + 1): + for x in range(x0, x1 + 1): + grid[y][x] = 1 if y in (y0, y1) or x in (x0, x1) else 5 + grid[y0][13] = grid[y0][14] = 4 + grid[10][13] = grid[10][14] = 0 + # tunnels: from the side junctions out through the wall + for x in (0,): + carve(x, TUNNEL_Y, 6) + for x in range(1, NX[0] + 1): + if grid[TUNNEL_Y][x] == 1: + carve(x, TUNNEL_Y, 6) + # no crystals in the tunnel, by the roost door, or where the miner starts + for x in range(0, 6): + for xx in (x, mirror(x)): + if grid[TUNNEL_Y][xx] == 2: + grid[TUNNEL_Y][xx] = 6 + for x in (12, 13, 14, 15): + if grid[9][x] == 2: + grid[9][x] = 0 + for x in (13, 14): + grid[START[1]][x] = 0 + for (x, y) in LANTERNS: + assert grid[y][x] == 2, (x, y) + grid[y][x] = grid[y][mirror(x)] = 3 + return grid + + +def check(grid): + open_t = lambda t: t in (0, 2, 3, 6) + for y in range(H): + for x in range(W): + if not open_t(grid[y][x]): + continue + n = 0 + for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): + nx, ny = (x + dx) % W, y + dy + if 0 <= ny < H and (open_t(grid[ny][nx]) or grid[ny][nx] == 4): + n += 1 + assert n >= 2, "dead end at %d,%d" % (x, y) + for y in range(H): + assert grid[y] == grid[y][::-1], "row %d is not mirrored" % y + + +# ---------------------------------------------------------------- shapes +Z = "0" * 16 +MINER_A = [Z, + "00000BBBBBB00000", + "0000B3333333F000", # helmet with a lamp + "00033333333FF000", + "0009999999990000", + "0009909909990000", + "0009999999990000", + "0000999009900000", + "000CCCCCCCCC0000", + "00CCCCCCCCCC9000", + "009CCCCCCCCC0000", + "000444444444000", + "0004440004440000", + "0007700000770000", +] + [Z] * 2 +MINER_A[11] = MINER_A[11] + "0" +MINER_B = MINER_A[:11] + [ + "0004444444440000", + "0000444044400000", + "0000077077000000", +] + [Z] * 2 + + +def bat(c, frame): + if frame == 0: + rows = [Z, Z, + "0C000000000000C0", + "0CC0000000000CC0", + "0CCC00CCCC00CCC0", + "0CCCCCCCCCCCCCC0", + "00CCCFCCCCFCCC00", + "000CCCCCCCCCC000", + "0000C0CCCC0C0000", + "00000C0CC0C00000", + "000000000000000" + "0"] + [Z] * 5 + else: + rows = [Z, Z, Z, Z, + "000000CCCC000000", + "0C0CCCCCCCCCC0C0", + "0CCCCFCCCCFCCCC0", + "0CCCCCCCCCCCCCC0", + "0CC0CCCCCCCC0CC0", + "0C0000CCCC0000C0", + "00000C0000C00000"] + [Z] * 5 + return [r.replace("C", c) for r in rows] + + +EYES = [Z] * 6 + ["0000FF0000FF0000", "0000F40000F40000"] + [Z] * 8 +NUGGET = [Z] * 4 + [ + "000000BBB0000000", + "0000BBBFBBB00000", + "000BBFBBBBBB0000", + "000BBBBBB3BB0000", + "0000BB3BBBB00000", + "00000BBBB0000000", +] + [Z] * 6 +BOOM = [Z, + "000F00000000F000", + "0000F00BB00F0000", + "00000F0BB0F00000", + "000000BFFB000000", + "0BBB0BFFFFB0BBB0", + "000000BFFB000000", + "00000F0BB0F00000", + "0000F00BB00F0000", + "000F00000000F000", +] + [Z] * 6 + +SHAPES = [("S_MINER", MINER_A), ("S_MINER2", MINER_B), + ("S_BAT_R", bat("9", 0)), ("S_BAT_R2", bat("9", 1)), + ("S_BAT_M", bat("D", 0)), ("S_BAT_M2", bat("D", 1)), + ("S_BAT_G", bat("A", 0)), ("S_BAT_G2", bat("A", 1)), + ("S_BAT_O", bat("3", 0)), ("S_BAT_O2", bat("3", 1)), + ("S_SCARED", bat("4", 0)), ("S_SCARED2", bat("4", 1)), + ("S_FLASH", bat("F", 0)), ("S_FLASH2", bat("F", 1)), + ("S_EYES", EYES), ("S_NUGGET", NUGGET), ("S_BOOM", BOOM)] + + +def main(out, seed=11): + grid = build(seed) + check(grid) + crystals = sum(r.count(2) + r.count(3) for r in grid) + L = ["/* made by gen.py - edit that instead */", ""] + L.append("#define MW %d\n#define MH %d" % (W, H)) + L.append("#define START_X %d\n#define START_Y %d\n#define TUNNEL_Y %d" % (START[0], START[1], TUNNEL_Y)) + L.append("#define CRYSTALS %d" % crystals) + L.append("static const u8 maze_start[MH][MW] = {") + for row in grid: + L.append(" {" + ",".join(str(t) for t in row) + "},") + L.append("};") + for i, (name, img) in enumerate(SHAPES): + assert len(img) == 16 and all(len(r) == 16 for r in img), name + L.append("#define %s %d" % (name, i)) + L.append("#define N_SHAPES %d" % len(SHAPES)) + L.append("static const u8 shape_data[N_SHAPES * 128] = {") + for name, img in SHAPES: + b = [int(r[x], 16) << 4 | int(r[x + 1], 16) for r in img for x in range(0, 16, 2)] + L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % name) + L.append("};") + open(out, "w").write("\n".join(L) + "\n") + print("data.h: maze %d x %d, %d crystals, %d shapes" % (W, H, crystals, len(SHAPES))) + return grid + + +if __name__ == "__main__": + g = main(sys.argv[1] if len(sys.argv) > 1 else "data.h", int(sys.argv[2]) if len(sys.argv) > 2 and sys.argv[2].isdigit() else 11) + if "--show" in sys.argv: + for row in g: + print("".join(" ##..oo==-- "[t * 2:t * 2 + 2][0] if False else " #.o=- "[t] for t in row)) diff --git a/games/cavern/test-cavern.py b/games/cavern/test-cavern.py new file mode 100644 index 0000000..1be51f8 --- /dev/null +++ b/games/cavern/test-cavern.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +"""Run Crystal Cavern in tools/rv32emu.py on a model of the board +(tools/boardemu.py) and take screenshots. + + python3 test-cavern.py [--shots DIR] [--play] + +It checks the title screen, measures the Z-80 instructions each frame takes +(a 60 Hz frame has about 550,000 at 90 MHz), checks that walls stop the miner, +that crystals score and that the bats leave the roost, and with --play lets +an autopilot gather every crystal in the cave by breadth-first search. The +autopilot can't be caught (it keeps the miner shielded), so this checks the +maze and the rules, not its skill. +""" +import argparse +import os +import sys +from collections import deque + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "tools")) +from boardemu import Board, load_ihx, load_font, load_syms # noqa: E402 + +UP, DOWN, LEFT, RIGHT, FIRE, ESC = 1, 2, 4, 8, 16, 128 +MW, MH = 28, 29 +OPEN = (0, 2, 3, 6) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--shots", help="write PNG screenshots here") + ap.add_argument("--play", action="store_true", help="let the autopilot clear a cave") + a = ap.parse_args() + mem, hi = load_ihx(os.path.join(HERE, "cavern.ihx")) + b = Board(mem, code_end=hi) + font = load_font() if a.shots else None + if a.shots: + os.makedirs(a.shots, exist_ok=True) + sym = {"_" + n: a for n, a in load_syms(os.path.join(HERE, "out", "cavern.sym")).items()} + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def s16(n, k=0): + v = b.m[sym[n] + 2 * k] | b.m[sym[n] + 2 * k + 1] << 8 + return v - 65536 if v & 0x8000 else v + + def u8(n, k=0): + return b.m[sym[n] + k] + + def maze(x, y): + return b.m[sym["_maze"] + y * MW + (x % MW)] if 0 <= y < MH else 1 + + def screen(): + return b.screen_text().display + + b.run_frames(5) + check("title screen", "C R Y S T A L C A V E R N" in "\n".join(screen())) + if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font) + b.run_frames(3, FIRE) + b.run_frames(110) # GET READY + check("game starts", "CAVE 1" in screen()[0] and "LIVES 3" in screen()[0]) + b.m[sym["_shield"]] = 1 + left0 = u8("_left") + c0 = b.steps + worst = 0 + for f in range(120): + c1 = b.steps + b.run_frames(1, LEFT) + worst = max(worst, b.steps - c1) + print("%.0f instructions a frame on average, %d at most (%.0f%%)" % + ((b.steps - c0) / 120, worst, worst / 5500)) + check("every frame fits in a 60th of a second", worst < 550000) + check("crystals are gathered and score", u8("_left") < left0 and s16("_score") > 0) + x0 = s16("_mx") + b.run_frames(20, LEFT) + check("a wall stops the miner", s16("_mx") == x0 or (s16("_mx") & 7) == 4) + check("the bats leave the roost", sum(1 for k in range(4) if u8("_bstate", k) == 2) >= 2) + if a.shots: b.shot(os.path.join(a.shots, "2-chase.png"), font) + + if a.play: + frame = 0 + want = LEFT + while frame < 30000 and b.pc != 0: + b.m[sym["_shield"]] = 1 + mx, my = s16("_mx"), s16("_my") + if (mx & 7) == 4 and (my & 7) == 4: + start = (mx >> 3, my >> 3) + prev = {start: None} + q = deque([start]) + goal = None + while q: + p = q.popleft() + if maze(*p) in (2, 3) and p != start: + goal = p + break + for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): + n = ((p[0] + dx) % MW, p[1] + dy) + if n not in prev and maze(*n) in OPEN: + prev[n] = p; q.append(n) + if goal: + while prev[goal] != start: + goal = prev[goal] + dx = (goal[0] - start[0] + MW // 2) % MW - MW // 2 + dy = goal[1] - start[1] + want = RIGHT if dx > 0 else LEFT if dx < 0 else DOWN if dy > 0 else UP + b.run_frames(1, want) + frame += 1 + if frame == 900 and a.shots: b.shot(os.path.join(a.shots, "3-midgame.png"), font) + if "CAVE 2" in screen()[0]: + break + print(screen()[0]) + check("autopilot gathered every crystal in %d frames" % frame, "CAVE 2" in screen()[0]) + b.run_frames(110) # the next cave's GET READY + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc gives up the game", "PRESS SPACE TO BEGIN" in "\n".join(screen())) + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc returns to BASIC", b.pc == 0) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/games/crt0.S b/games/crt0.S new file mode 100644 index 0000000..5c8b431 --- /dev/null +++ b/games/crt0.S @@ -0,0 +1,13 @@ +# Start-up for a machine-code program that BASIC CALLs at A200h: clear the +# variables, run main, and return to BASIC. Programs have no initialised +# variables (gen.py's tables are const, so they stay with the code). + .section .text.start, "ax" + .globl _start +_start: + la t0, __bss_start + la t1, __bss_end +1: bgeu t0, t1, 2f + sw zero, 0(t0) + addi t0, t0, 4 + j 1b +2: tail main # main's return goes back to BASIC diff --git a/games/game.ld b/games/game.ld new file mode 100644 index 0000000..ddd0bbe --- /dev/null +++ b/games/game.ld @@ -0,0 +1,22 @@ +/* A game: loaded at A200h inside BASIC's program area (A000h-F0B7h), after + the loader program at its start. Code, constants, then the variables. */ +OUTPUT_ARCH("riscv") +ENTRY(_start) +SECTIONS +{ + . = 0xA200; + .text : { + KEEP(*(.text.start)) + *(.text .text.*) + *(.rodata .rodata.* .srodata .srodata.*) + . = ALIGN(4); + } + .data : { *(.data .data.* .sdata .sdata.*) } + .bss (NOLOAD) : ALIGN(4) { + __bss_start = .; + *(.sbss .sbss.* .bss .bss.* COMMON) + . = ALIGN(4); + __bss_end = .; + } + /DISCARD/ : { *(.comment) *(.riscv.attributes) } +} diff --git a/games/keep/gen.py b/games/keep/gen.py new file mode 100644 index 0000000..9e069da --- /dev/null +++ b/games/keep/gen.py @@ -0,0 +1,454 @@ +#!/usr/bin/env python3 +"""Turn the art and the castle map below into data.h for keep.c. + +Shapes and tiles are 16 rows of 16 hex digits, one colour per pixel (the +terminal's 16 colours; 0 is see-through). The castle is 4 x 3 rooms; each room +is 18 x 12 tiles inside a wall border that gen.py adds, with gaps where two +rooms connect. Map characters: + + # wall D locked door (a key opens it) X stairs out + . floor P where the player starts + K key G gold chest A ammunition C the crown + h guard patrolling left-right v guard patrolling up-down + c guard that chases you once it has seen you + +The script checks that every room's objects fit the sprite budget and that +everything can be reached from the start, counting a key for every door. +""" +import sys +from collections import deque + +# ------------------------------------------------------------------ shapes +PLAYER_DOWN_TOP = [ + "0000033333300000", + "0000333333330000", + "0000399999930000", + "0000390990930000", + "0000099999900000", + "0000000990000000", +] +PLAYER_UP_TOP = [ + "0000033333300000", + "0000333333330000", + "0000333333330000", + "0000333333330000", + "0000033333300000", + "0000000990000000", +] +BODY_FRONT = [ + "000CCCCCCCCCC000", + "00CCCCCCCCCCCC00", + "009CCCCCCCCCC900", + "009CCCCCCCCCC900", + "0000CCCCCCCC0000", + "0000444444440000", +] +LEGS_FRONT_A = [ + "0000444004440000", + "0000444004440000", + "0000777007770000", + "0000000000000000", +] +LEGS_FRONT_B = [ + "0000044004400000", + "0000044004400000", + "0000077007700000", + "0000000000000000", +] +PLAYER_SIDE_TOP = [ + "0000033333300000", + "0000333333330000", + "0000333399990000", + "0000333990990000", + "0000033999990000", + "0000000999000000", + "00000CCCCCC00000", + "0000CCCCCCCC0000", + "0000CCCCC9990000", + "0000CCCCCC000000", + "00000CCCCC000000", + "0000044444400000", +] +LEGS_SIDE_A = [ + "0000044004400000", + "0000444000440000", + "0000777000770000", + "0000000000000000", +] +LEGS_SIDE_B = [ + "0000004444000000", + "0000004444000000", + "0000007777000000", + "0000000000000000", +] +PLAYER = [ + PLAYER_DOWN_TOP + BODY_FRONT + LEGS_FRONT_A, + PLAYER_DOWN_TOP + BODY_FRONT + LEGS_FRONT_B, + PLAYER_UP_TOP + BODY_FRONT + LEGS_FRONT_A, + PLAYER_UP_TOP + BODY_FRONT + LEGS_FRONT_B, + PLAYER_SIDE_TOP + LEGS_SIDE_A, + PLAYER_SIDE_TOP + LEGS_SIDE_B, +] +# guards: grey helmet, green tunic, dark grey trousers, brown boots +GUARD = [[r.translate(str.maketrans("3C47", "7283")) for r in s] for s in PLAYER] + + +def dot(c): + rows = ["0" * 16] * 16 + for y in range(6, 10): + rows[y] = "000000" + c * 4 + "000000" + return rows + + +KEY = ["0" * 16] * 3 + [ + "000BBB0000000000", + "00B000B000000000", + "00B000BBBBBBBBB0", + "00B000B0000B0B00", + "000BBB00000B0B00", +] + ["0" * 16] * 8 +CHEST = ["0" * 16] * 3 + [ + "0003333333333000", + "0033333333333300", + "003BBBBBBBBBB300", + "0033333BB3333300", + "0033333BB3333300", + "0033333333333300", + "0033333333333300", + "003BBBBBBBBBB300", + "0033333333333300", +] + ["0" * 16] * 4 +AMMO = ["0" * 16] * 3 + [ + "0022222222222200", + "0028888888888200", + "0028BB8BB8BB8200", + "0028BB8BB8BB8200", + "0028BB8BB8BB8200", + "0028888888888200", + "0022222222222200", +] + ["0" * 16] * 6 +CROWN = ["0" * 16] * 3 + [ + "000B000BB000B000", + "000BB0BBBB0BB000", + "000BBBBBBBBBB000", + "000BB9BBBB9BB000", + "000BBBBCCBBBB000", + "000BBBBBBBBBB000", + "0000000000000000", + "000BBBBBBBBBB000", +] + ["0" * 16] * 5 +PUFF = [ + "0000000000000000", + "000F00000000F000", + "0000F00BB00F0000", + "00000F0BB0F00000", + "000000BFFB000000", + "0BBB0BFFFFB0BBB0", + "000000BFFB000000", + "00000F0BB0F00000", + "0000F00BB00F0000", + "000F00000000F000", +] + ["0" * 16] * 6 + +SHAPES = PLAYER + GUARD + [dot("B"), dot("9"), KEY, CHEST, AMMO, CROWN, PUFF] +SHAPE_NAMES = ["S_PDOWN", "S_PDOWN2", "S_PUP", "S_PUP2", "S_PSIDE", "S_PSIDE2", + "S_GDOWN", "S_GDOWN2", "S_GUP", "S_GUP2", "S_GSIDE", "S_GSIDE2", + "S_SHOT", "S_GSHOT", "S_KEY", "S_CHEST", "S_AMMO", "S_CROWN", "S_PUFF"] + +# ------------------------------------------------------------------- tiles +WALL = (["8888888888888888", "7777777877777778", "7777777877777778", "7777777877777778", + "8888888888888888", "7778777777787777", "7778777777787777", "7778777777787777"] * 2) +DOOR = (["8888888888888888"] + ["8333833383338338"] * 6 + + ["8333833BB3338338"] * 2 + ["8333833383338338"] * 6 + ["8888888888888888"]) +STAIRS = ["EEEEEEEEEEEEEEEE", "6666666666666666", "8888888888888888", "0000000000000000"] * 4 +TILES = [["0" * 16] * 16, WALL, DOOR, STAIRS] # floor, wall, door, stairs + +# -------------------------------------------------------------------- map +ROOMS = [[None] * 4 for _ in range(3)] +NAMES = [[None] * 4 for _ in range(3)] + +def room(r, c, name, rows): + ROOMS[r][c] = rows + NAMES[r][c] = name + +room(0, 0, "GATEHOUSE", [ + "..................", + "..P...............", + "..................", + "....####....####..", + "....#..........#..", + "....#...A......#..", + "....#..........#..", + "....####....####..", + "..................", + "..................", + "..................", + "..................", +]) +room(0, 1, "GUARD ROOM", [ + "..................", + ".h................", + "..................", + "..###.......###...", + "..#...........#...", + "..#.....K.....#...", + "..#...........#...", + "..###.......###...", + "..................", + "...........h......", + "..................", + "..................", +]) +room(0, 2, "CHAPEL", [ + "..................", + ".v..........v.....", + "..................", + "......######......", + "......#G.G#.......", + "......#...D.......", + "......#####.......", + "..................", + "..................", + "....h.............", + "..................", + "..................", +]) +room(0, 3, "ARMOURY", [ + "..................", + "..A............A..", + "..................", + ".####.......####..", + "..................", + "........h.........", + "..................", + ".####.......####..", + "..................", + "..................", + ".......c..........", + "..................", +]) +room(1, 0, "CORRIDOR", [ + "..................", + ".v.......####.....", + ".........#........", + ".........#....h...", + "#######..#........", + "..................", + "..................", + "#######..########.", + ".........#........", + "..A......#........", + ".........#....v...", + "..................", +]) +room(1, 1, "GREAT HALL", [ + "..................", + "..G............G..", + "..................", + "....##......##....", + "....##..h...##....", + "..................", + "..................", + "....##......##....", + "....##...h..##....", + "..................", + ".c...........v....", + "..................", +]) +room(1, 2, "CELLARS", [ + "...#.......#......", + "...#.#####.#.####.", + "...#.#.....#....#.", + ".....#.#######..#.", + "######.#.....#..#.", + ".......#..A..#....", + ".#######.....###..", + ".#.......###......", + ".#.#######.#.####.", + ".#.........#.#....", + ".#####.#####.#.h..", + ".......#.......#..", +]) +room(1, 3, "LIBRARY", [ + "..................", + ".##.##.##.##.##.#.", + "..................", + ".##.##.##.##.##.#.", + "..........h.......", + "..................", + ".##.##.##.##.##.#.", + "..................", + ".##.##.##.##.##.#.", + "........K.........", + "...v..............", + "..................", +]) +room(2, 0, "STAIRWELL", [ + "..................", + "..................", + "..######..######..", + "..#............#..", + "..#.....XX.....#..", + "..#.....XX.....#..", + "..#............#..", + "..######..######..", + "..................", + "....h.............", + "..................", + "..................", +]) +room(2, 1, "DUNGEON", [ + ".#..#..#..#..#..#.", + ".#..#..#..#..#..#.", + ".#..#..#..#..#..#.", + ".##.####..####.##.", + "..................", + "........v.........", + "..................", + ".##.####..####.##.", + ".#..#..#..#..#..#.", + ".#K.#..#..#.G#..#.", + ".#..#..#..#..#..#.", + "..................", +]) +room(2, 2, "TREASURY", [ + "..................", + "..h...............", + "..................", + ".....##########...", + ".....#G..G...G#...", + ".....#........#...", + ".....######D###...", + "..................", + "..................", + ".........v........", + "..................", + "..................", +]) +room(2, 3, "THRONE ROOM", [ + "#######D##########", + "..................", + ".c..............c.", + "..................", + "...####....####...", + "...#..........#...", + "...#....C.....#...", + "...#..........#...", + "...####....####...", + "..................", + ".v..............v.", + "..................", +]) + +# links: (room, room) side by side or one above the other +H_LINKS = {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)} # (r, c) to (r, c+1) +V_LINKS = {(0, 0), (1, 0), (0, 3), (1, 3), (1, 1)} # (r, c) to (r+1, c) + +W, H = 20, 14 +GAP_ROWS = (6, 7) # side gaps, in room rows +GAP_COLS = (8, 9) # top/bottom gaps, in room columns +OBJ = "PKGAChvc" + + +def full_room(r, c): + inner = ROOMS[r][c] + assert len(inner) == 12 and all(len(x) == 18 for x in inner), NAMES[r][c] + g = [["#"] * W for _ in range(H)] + for y in range(12): + for x in range(18): + g[y + 1][x + 1] = inner[y][x] + if (r, c) in H_LINKS: + for y in GAP_ROWS: g[y][W - 1] = "." + if (r, c - 1) in H_LINKS: + for y in GAP_ROWS: g[y][0] = "." + if (r, c) in V_LINKS: + for x in GAP_COLS: g[H - 1][x] = "." + if (r - 1, c) in V_LINKS: + for x in GAP_COLS: g[0][x] = "." + return g + + +FULL = [[full_room(r, c) for c in range(4)] for r in range(3)] + +# one big grid to check reachability across rooms +BIG = [[FULL[gy // H][gx // W][gy % H][gx % W] for gx in range(4 * W)] for gy in range(3 * H)] + +def check(): + start = [(x, y) for y in range(3 * H) for x in range(4 * W) if BIG[y][x] == "P"] + assert len(start) == 1 + doors = sum(row.count("D") for row in BIG) + keys = sum(row.count("K") for row in BIG) + assert keys >= doors, f"{keys} keys for {doors} doors" + # with every door open, every non-wall tile must be reachable + seen = {start[0]} + q = deque(seen) + while q: + x, y = q.popleft() + for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): + nx, ny = x + dx, y + dy + if 0 <= nx < 4 * W and 0 <= ny < 3 * H and (nx, ny) not in seen and BIG[ny][nx] != "#": + seen.add((nx, ny)); q.append((nx, ny)) + lost = [(x, y, BIG[y][x]) for y in range(3 * H) for x in range(4 * W) + if BIG[y][x] != "#" and (x, y) not in seen] + objs_lost = [t for t in lost if t[2] != "."] + assert not objs_lost, f"unreachable objects: {objs_lost}" + # rooms' sprite budgets: 6 guards, 8 items + for r in range(3): + for c in range(4): + s = "".join("".join(row) for row in FULL[r][c]) + assert sum(s.count(ch) for ch in "hvc") <= 6, NAMES[r][c] + assert sum(s.count(ch) for ch in "KGAC") <= 8, NAMES[r][c] + assert s.count("D") <= 8, NAMES[r][c] + return len(lost) + + +def nib(c): + return int(c, 16) + + +def main(out): + unreach = check() + L = ["/* made by gen.py - edit that instead */", ""] + L.append("#define N_SHAPES %d" % len(SHAPES)) + for i, n in enumerate(SHAPE_NAMES): + L.append("#define %s %d" % (n, i)) + for i, s in enumerate(SHAPES): + assert len(s) == 16 and all(len(row) == 16 for row in s), SHAPE_NAMES[i] + L.append("static const u8 shape_data[N_SHAPES * 128] = {") + for s in SHAPES: + b = [nib(row[x]) << 4 | nib(row[x + 1]) for row in s for x in range(0, 16, 2)] + L.append(" " + ",".join(str(v) for v in b) + ",") + L.append("};") + L.append("static const u8 tile_data[4 * 256] = {") + for t in TILES: + assert len(t) == 16 and all(len(row) == 16 for row in t) + L.append(" " + ",".join(str(nib(ch)) for row in t for ch in row) + ",") + L.append("};") + # rooms: tiles packed two per byte (low nibble first), then object lists + code = {".": 0, "#": 1, "D": 2, "X": 3} + L.append("static const u8 room_tiles[12][140] = {") + objs = [] + for r in range(3): + for c in range(4): + g = FULL[r][c] + t = [code.get(g[y][x], 0) for y in range(H) for x in range(W)] + L.append(" {" + ",".join(str(t[i] | t[i + 1] << 4) for i in range(0, W * H, 2)) + "},") + ol = [(g[y][x], x, y) for y in range(H) for x in range(W) if g[y][x] in OBJ] + objs.append(ol) + L.append("};") + L.append("/* objects: type, tile x, tile y; ends with 0 */") + L.append("static const u8 room_objs[12][3 * 16 + 1] = {") + for ol in objs: + assert len(ol) <= 16 + L.append(" {" + ",".join("'%s',%d,%d" % o for o in ol) + (",0}," if ol else "0},")) + L.append("};") + L.append("static const char *const room_names[12] = {") + L.append(" " + ", ".join('"%s"' % NAMES[r][c] for r in range(3) for c in range(4))) + L.append("};") + open(out, "w").write("\n".join(L) + "\n") + print("data.h: %d shapes, 12 rooms (%d floor tiles only reachable through nothing)" % + (len(SHAPES), unreach)) + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else "data.h") diff --git a/games/keep/keep.bas b/games/keep/keep.bas new file mode 100644 index 0000000..c6fc48a --- /dev/null +++ b/games/keep/keep.bas @@ -0,0 +1,4 @@ +10 REM THE IRON KEEP: LOAD THE GAME (MEMORY FILE KEEPGAME) AND PLAY IT +20 REM THE GAME RUNS AT A200H, PAST THIS PROGRAM, AND COMES BACK HERE +30 BLOAD "KEEPGAME": CALL 41472 +40 CLS diff --git a/games/keep/keep.c b/games/keep/keep.c new file mode 100644 index 0000000..f726432 --- /dev/null +++ b/games/keep/keep.c @@ -0,0 +1,647 @@ +/* The Iron Keep: a top-down escape game for the Basys 3 RISC-V computer. + + You are a prisoner in a castle of twelve rooms. Steal the crown from the + throne room and get out down the stairs. Guards patrol, and shoot when they + can see you along a row or a column; some come after you. Keys open locked + doors, chests hold gold, crates hold ammunition. + + It runs at A200h, loaded by the KEEP program in BASIC, and returns to BASIC + when you quit. It uses the hardware sprites (ports 70h-78h), the graphics + layer (30h-34h), the held-key port (88h) and the terminal for text. + Build with build.sh; gen.py makes data.h from the art and the map. */ + +typedef unsigned char u8; +typedef signed char i8; +typedef unsigned short u16; +typedef short i16; + +#include "basys3.h" + +#define con_stat IO8(0x00) /* bit 0: key waiting, bit 1: can send */ +#define con_data IO8(0x01) +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) /* plot, then X + 1 */ +#define gfill IO8(0x34) /* fill the graphics (and turn sprites off) */ +#define sp_sel IO8(0x70) +#define sp_xlo IO8(0x71) +#define sp_xhi IO8(0x72) +#define sp_y IO8(0x73) +#define sp_shape IO8(0x74) +#define sp_ctl IO8(0x75) +#define sp_load IO8(0x76) +#define sp_data IO8(0x77) +#define frame_ctr IO8(0x78) +#define joy IO8(0x88) + +#include "data.h" /* out/data.h, made by gen.py */ + +#define J_UP 1 +#define J_DOWN 2 +#define J_LEFT 4 +#define J_RIGHT 8 +#define J_FIRE 16 +#define J_ENTER 32 +#define J_ESC 128 + +/* directions */ +#define D_DOWN 0 +#define D_UP 1 +#define D_LEFT 2 +#define D_RIGHT 3 +static const i8 dir_dx[4] = { 0, 0, -1, 1 }; +static const i8 dir_dy[4] = { 1, -1, 0, 0 }; + +/* tiles */ +#define T_FLOOR 0 +#define T_WALL 1 +#define T_DOOR 2 +#define T_STAIRS 3 +#define T_OUT 0xFF + +/* sprite numbers: lower numbers are in front */ +#define SP_PLAYER 0 +#define SP_PSHOT 1 /* 2 */ +#define SP_GUARD 3 /* 6 */ +#define SP_GSHOT 9 /* 4 */ +#define SP_ITEM 13 /* 8 */ +#define SP_PUFF 21 + +#define NG 6 +#define NI 8 +#define NPS 2 +#define NGS 4 + +/* the hit box inside a 16 x 16 figure */ +#define HB_X0 3 +#define HB_X1 12 +#define HB_Y0 2 +#define HB_Y1 14 + +/* -------------------------------------------------------------- state */ +static u8 map[14][20]; +/* not static: test-keep.py finds these in the link map */ +u8 room; /* 0-11: row * 4 + column */ +static u16 gone[12]; /* objects taken or guards beaten, by index */ +static u8 opened[12]; /* doors opened, by order in the room */ + +i16 px, py; /* player */ +static i16 ex, ey; /* where it entered the room */ +static u8 pdir, panim, fire_cool, fire_held; +u8 inv, lives, keys, ammo, crown; +static u16 gold, kills; + +static i16 gx[NG], gy[NG]; +static u8 gdir[NG], gon[NG], gkind[NG], gcool[NG], gsee[NG], gobj[NG]; +static i16 ix[NI], iy[NI]; +static u8 itype[NI], ion[NI], iobj[NI]; +static i16 psx[NPS], psy[NPS], gsx[NGS], gsy[NGS]; +static u8 psd[NPS], pson[NPS], gsd[NGS], gson[NGS]; +static u8 puff; +static i16 puff_x, puff_y; + +static u8 last_frame, quit, status_dirty, msg_time; +u8 over, won; +static const char *msg; +static u16 rnd_state; + +/* -------------------------------------------------------------- text */ +static void putch(char c) { while (!(con_stat & 2)); con_data = c; } +static void puts_(const char *s) { while (*s) putch(*s++); } +static void putn(u16 n) +{ + char b[6]; + u8 i = 0; + do { b[i++] = '0' + n % 10; n /= 10; } while (n); + while (i) putch(b[--i]); +} +static void at(u8 r, u8 c) { putch(27); putch('['); putn(r); putch(';'); putn(c); putch('H'); } +static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); } +static void centre(u8 r, const char *s) +{ + u8 n = 0; + while (s[n]) n++; + at(r, 41 - n / 2); + puts_(s); +} + +static u16 rnd(void) +{ + rnd_state ^= rnd_state << 7; + rnd_state ^= rnd_state >> 9; + rnd_state ^= rnd_state << 8; + return rnd_state; +} + +static void wait_frame(void) +{ + while (frame_ctr == last_frame); + last_frame = frame_ctr; +} + +/* Keys also arrive as characters; throw them away (P pauses). */ +static u8 drain_keys(void) +{ + u8 c, p = 0; + while (con_stat & 1) { + c = con_data; + if (c == 'p' || c == 'P') p = 1; + } + return p; +} + +/* ----------------------------------------------------------- graphics */ +static void clear_gfx(void) +{ + gfill = 0; /* also turns every sprite off */ + while (gfill & 1); +} + +static void draw_tile(u8 tx, u8 ty, u8 t) +{ + const u8 *p = tile_data + ((u16)t << 8); + u16 x = tx << 4; + u8 y = 16 + (ty << 4), r, i; + for (r = 0; r < 16; r++) { + gx_lo = x; gx_hi = x >> 8; gy_p = y + r; + for (i = 0; i < 16; i++) gpix = *p++; + } +} + +static void spr_at(u8 n, i16 x, i16 y) +{ + sp_sel = n; sp_xlo = x; sp_xhi = (x >> 8) & 1; sp_y = y; +} +static void spr_show(u8 n, u8 shape, u8 ctl) +{ + sp_sel = n; sp_shape = shape; sp_ctl = ctl; +} +static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; } + +static void load_shapes(void) +{ + const u8 *p = shape_data; + u8 s, i; + for (s = 0; s < N_SHAPES; s++) { + sp_load = s; + for (i = 0; i < 128; i++) sp_data = *p++; + } +} + +/* --------------------------------------------------------------- map */ +static u8 tile_at(i16 x, i16 y) +{ + if (x < 0 || x > 319 || y < 16 || y > 239) return T_OUT; + return map[(u8)((y - 16) >> 4)][(u8)(x >> 4)]; +} + +static u8 hit_tx, hit_ty; + +/* What stops a figure at (x, y): 0 nothing, T_WALL or T_DOOR (hit_tx/ty say + which tile). Off the room is open for the player, a wall for guards. */ +static u8 blocked(i16 x, i16 y, u8 guard) +{ + static const u8 cx[4] = { HB_X0, HB_X1, HB_X0, HB_X1 }; + static const u8 cy[4] = { HB_Y0, HB_Y0, HB_Y1, HB_Y1 }; + u8 i, t; + for (i = 0; i < 4; i++) { + t = tile_at(x + cx[i], y + cy[i]); + if (t == T_WALL || t == T_DOOR) { + hit_tx = (u8)((x + cx[i]) >> 4); + hit_ty = (u8)((y + cy[i] - 16) >> 4); + return t; + } + if (t == T_OUT && guard) return T_WALL; + } + return 0; +} + +static u8 door_index(u8 tx, u8 ty) +{ + const u8 *p = room_tiles[room]; + u8 n = 0, i, t; + u16 k, want = ty * 20 + tx; + for (k = 0; k < want; k++) { + i = p[k >> 1]; + t = (k & 1) ? i >> 4 : i & 15; + if (t == T_DOOR) n++; + } + return n; +} + +static void say(const char *s) +{ + msg = s; + msg_time = 180; + status_dirty = 1; +} + +/* ------------------------------------------------------------- status */ +static void status(void) +{ + status_dirty = 0; + at(1, 1); ink("0;93"); puts_("THE IRON KEEP"); ink("0;37"); puts_(" "); + puts_(room_names[room]); + puts_("\033[K"); + if (msg && msg_time) { at(1, 40); ink("0;96"); puts_(msg); } + at(2, 1); ink("0;37"); + puts_("LIVES "); ink("0;97"); putn(lives); ink("0;37"); + puts_(" KEYS "); ink("0;97"); putn(keys); ink("0;37"); + puts_(" AMMO "); ink("0;97"); putn(ammo); ink("0;37"); + puts_(" GOLD "); ink("0;97"); putn(gold); ink("0;37"); + if (crown) { puts_(" "); ink("0;93"); puts_("CROWN"); } + puts_("\033[K"); + ink("0"); +} + +/* --------------------------------------------------------------- rooms */ +static void enter_room(void) +{ + const u8 *p = room_tiles[room], *o = room_objs[room]; + u8 x, y, i, t, d = 0, ng = 0, ni = 0, k = 0; + + clear_gfx(); + for (y = 0; y < 14; y++) + for (x = 0; x < 20; x += 2) { + i = *p++; + map[y][x] = i & 15; + map[y][x + 1] = i >> 4; + } + for (y = 0; y < 14; y++) + for (x = 0; x < 20; x++) { + t = map[y][x]; + if (t == T_DOOR && (opened[room] & (1 << d++))) t = map[y][x] = T_FLOOR; + if (t != T_FLOOR) draw_tile(x, y, t); + } + + for (i = 0; i < NG; i++) gon[i] = 0; + for (i = 0; i < NI; i++) ion[i] = 0; + for (; *o; o += 3, k++) { + if (gone[room] & (1 << k)) continue; + t = o[0]; + if (t == 'h' || t == 'v' || t == 'c') { + gx[ng] = o[1] << 4; gy[ng] = 16 + (o[2] << 4); + gkind[ng] = t; gon[ng] = 1; gsee[ng] = 0; gobj[ng] = k; + gdir[ng] = t == 'v' ? D_DOWN : D_RIGHT; + gcool[ng] = 30 + (rnd() & 31); + ng++; + } else if (t != 'P') { + ix[ni] = o[1] << 4; iy[ni] = 16 + (o[2] << 4); + itype[ni] = t; ion[ni] = 1; iobj[ni] = k; + spr_at(SP_ITEM + ni, ix[ni], iy[ni]); + spr_show(SP_ITEM + ni, t == 'K' ? S_KEY : t == 'G' ? S_CHEST : t == 'A' ? S_AMMO : S_CROWN, 1); + ni++; + } + } + for (i = 0; i < NPS; i++) pson[i] = 0; + for (i = 0; i < NGS; i++) gson[i] = 0; + puff = 0; + ex = px; ey = py; + status_dirty = 1; +} + +/* Leave by an edge into the next room. */ +static void edges(void) +{ + if (px + HB_X0 < 0) { room--; px = 304; } + else if (px + HB_X1 > 319) { room++; px = 0; } + else if (py + HB_Y0 < 16) { room -= 4; py = 224; } + else if (py + HB_Y1 > 239) { room += 4; py = 16; } + else return; + enter_room(); +} + +/* ------------------------------------------------------------- player */ +static void open_door(void) +{ + if (!keys) { say("LOCKED. YOU NEED A KEY."); return; } + keys--; + opened[room] |= 1 << door_index(hit_tx, hit_ty); + map[hit_ty][hit_tx] = T_FLOOR; + draw_tile(hit_tx, hit_ty, T_FLOOR); + say("THE KEY TURNS. THE DOOR OPENS."); +} + +static void move_player(u8 j) +{ + i16 n; + u8 t, moved = 0; + if (j & (J_LEFT | J_RIGHT)) { + pdir = (j & J_LEFT) ? D_LEFT : D_RIGHT; + n = px + ((j & J_LEFT) ? -2 : 2); + t = blocked(n, py, 0); + if (!t) { px = n; moved = 1; } + else if (t == T_DOOR) open_door(); + } + if (j & (J_UP | J_DOWN)) { + if (!(j & (J_LEFT | J_RIGHT))) pdir = (j & J_UP) ? D_UP : D_DOWN; + n = py + ((j & J_UP) ? -2 : 2); + t = blocked(px, n, 0); + if (!t) { py = n; moved = 1; } + else if (t == T_DOOR) open_door(); + } + if (moved) panim++; +} + +static void fire(u8 j) +{ + u8 i; + if (!(j & J_FIRE)) { fire_held = 0; return; } + if (fire_held || fire_cool) return; + fire_held = 1; + if (!ammo) { say("OUT OF AMMUNITION!"); return; } + for (i = 0; i < NPS; i++) + if (!pson[i]) { + pson[i] = 1; psd[i] = pdir; + psx[i] = px + 8 + dir_dx[pdir] * 6; + psy[i] = py + 8 + dir_dy[pdir] * 6; + ammo--; fire_cool = 8; status_dirty = 1; + spr_show(SP_PSHOT + i, S_SHOT, 1); + return; + } +} + +static void player_hit(void) +{ + u8 i; + if (inv || over) return; + puff = 30; puff_x = px; puff_y = py; + if (!--lives) { over = 1; won = 0; return; } + say("YOU ARE HIT!"); + px = ex; py = ey; inv = 120; + for (i = 0; i < NGS; i++) { gson[i] = 0; spr_off(SP_GSHOT + i); } +} + +static u8 overlap(i16 ax, i16 ay, i16 bx, i16 by) +{ + return ax + HB_X0 <= bx + HB_X1 && bx + HB_X0 <= ax + HB_X1 && + ay + HB_Y0 <= by + HB_Y1 && by + HB_Y0 <= ay + HB_Y1; +} + +static void pick_up(void) +{ + u8 i; + for (i = 0; i < NI; i++) { + if (!ion[i] || !overlap(px, py, ix[i], iy[i])) continue; + ion[i] = 0; + gone[room] |= 1 << iobj[i]; + spr_off(SP_ITEM + i); + switch (itype[i]) { + case 'K': keys++; say("A KEY!"); break; + case 'G': gold += 100; say("GOLD! 100 CROWNS."); break; + case 'A': ammo += 5; say("FIVE MORE SHOTS."); break; + case 'C': crown = 1; say("THE CROWN! NOW FIND THE STAIRS."); break; + } + } + if (tile_at(px + 8, py + 8) == T_STAIRS) { + if (crown) { over = 1; won = 1; } + else if (msg_time < 120) say("NOT WITHOUT THE CROWN."); + } +} + +/* -------------------------------------------------------------- guards */ +/* Can guard i see the player along a row or a column? Returns the direction + to look in, plus 1, or 0. */ +static u8 sees(u8 i) +{ + i16 gcx = gx[i] + 8, gcy = gy[i] + 8, pcx = px + 8, pcy = py + 8, d; + u8 a, b, t, k; + d = gcy - pcy; + if (d > -8 && d < 8) { + k = (u8)((gcy - 16) >> 4); + a = (u8)(gcx >> 4); b = (u8)(pcx >> 4); + if (a > b) { t = a; a = b; b = t; } + for (; a <= b; a++) if (map[k][a] == T_WALL || map[k][a] == T_DOOR) return 0; + return (pcx < gcx ? D_LEFT : D_RIGHT) + 1; + } + d = gcx - pcx; + if (d > -8 && d < 8) { + k = (u8)(gcx >> 4); + a = (u8)((gcy - 16) >> 4); b = (u8)((pcy - 16) >> 4); + if (a > b) { t = a; a = b; b = t; } + for (; a <= b; a++) if (map[a][k] == T_WALL || map[a][k] == T_DOOR) return 0; + return (pcy < gcy ? D_UP : D_DOWN) + 1; + } + return 0; +} + +static void guard_shoots(u8 i) +{ + u8 k; + for (k = 0; k < NGS; k++) + if (!gson[k]) { + gson[k] = 1; gsd[k] = gdir[i]; + gsx[k] = gx[i] + 8 + dir_dx[gdir[i]] * 6; + gsy[k] = gy[i] + 8 + dir_dy[gdir[i]] * 6; + spr_show(SP_GSHOT + k, S_GSHOT, 1); + gcool[i] = 45 + (rnd() & 63); + return; + } +} + +static void guards(void) +{ + u8 i, s, d; + i16 nx, ny; + for (i = 0; i < NG; i++) { + if (!gon[i]) continue; + if (gcool[i]) gcool[i]--; + s = inv ? 0 : sees(i); + if (s) { + gdir[i] = s - 1; + if (!gsee[i]) { gsee[i] = 1; if (gcool[i] < 25) gcool[i] = 25; } + if (!gcool[i]) guard_shoots(i); + if (gkind[i] != 'c') goto shown; /* the others stand and shoot */ + } else + gsee[i] = 0; + d = gdir[i]; + nx = gx[i] + dir_dx[d]; + ny = gy[i] + dir_dy[d]; + if (blocked(nx, ny, 1)) { + /* turn round, or for a chaser, try the other way across */ + if (gkind[i] == 'c' && !s) gdir[i] = (rnd() & 3); + else if (!s) gdir[i] = d ^ 1; + } else { + gx[i] = nx; gy[i] = ny; + } + if (overlap(gx[i], gy[i], px, py)) player_hit(); +shown: + d = gdir[i]; + spr_at(SP_GUARD + i, gx[i], gy[i]); + spr_show(SP_GUARD + i, + (d == D_DOWN ? S_GDOWN : d == D_UP ? S_GUP : S_GSIDE) + (((gx[i] + gy[i]) >> 3) & 1), + d == D_LEFT ? 3 : 1); + } +} + +/* ------------------------------------------------------------- bullets */ +static void shots(void) +{ + u8 i, k; + for (i = 0; i < NPS; i++) { + if (!pson[i]) continue; + psx[i] += dir_dx[psd[i]] * 5; + psy[i] += dir_dy[psd[i]] * 5; + k = tile_at(psx[i], psy[i]); + if (k == T_WALL || k == T_DOOR || k == T_OUT) { pson[i] = 0; spr_off(SP_PSHOT + i); continue; } + for (k = 0; k < NG; k++) + if (gon[k] && psx[i] >= gx[k] + HB_X0 && psx[i] <= gx[k] + HB_X1 && + psy[i] >= gy[k] + HB_Y0 && psy[i] <= gy[k] + HB_Y1) { + gon[k] = 0; + gone[room] |= 1 << gobj[k]; + spr_off(SP_GUARD + k); + pson[i] = 0; spr_off(SP_PSHOT + i); + puff = 20; puff_x = gx[k]; puff_y = gy[k]; + kills++; + break; + } + if (pson[i]) spr_at(SP_PSHOT + i, psx[i] - 8, psy[i] - 8); + } + for (i = 0; i < NGS; i++) { + if (!gson[i]) continue; + gsx[i] += dir_dx[gsd[i]] * 3; + gsy[i] += dir_dy[gsd[i]] * 3; + k = tile_at(gsx[i], gsy[i]); + if (k == T_WALL || k == T_DOOR || k == T_OUT) { gson[i] = 0; spr_off(SP_GSHOT + i); continue; } + if (gsx[i] >= px + HB_X0 && gsx[i] <= px + HB_X1 && gsy[i] >= py + HB_Y0 && gsy[i] <= py + HB_Y1) { + gson[i] = 0; spr_off(SP_GSHOT + i); + player_hit(); + continue; + } + spr_at(SP_GSHOT + i, gsx[i] - 8, gsy[i] - 8); + } +} + +static void draw_player(void) +{ + u8 s = pdir == D_DOWN ? S_PDOWN : pdir == D_UP ? S_PUP : S_PSIDE; + spr_at(SP_PLAYER, px, py); + spr_show(SP_PLAYER, s + ((panim >> 3) & 1), + (inv & 4) ? 0 : pdir == D_LEFT ? 3 : 1); + if (puff) { + spr_at(SP_PUFF, puff_x, puff_y); + spr_show(SP_PUFF, S_PUFF, --puff ? 1 : 0); + } +} + +/* -------------------------------------------------------------- screens */ +static u8 wait_fire(void) +{ + u8 j; + while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); } + for (;;) { + wait_frame(); drain_keys(); rnd(); + j = joy; + if (j & J_ESC) return 0; + if (j & (J_FIRE | J_ENTER)) return 1; + } +} + +static u8 title(void) +{ + u8 i; + clear_gfx(); + puts_("\033[0m\033[2J"); + for (i = 0; i < 20; i++) { draw_tile(i, 0, T_WALL); draw_tile(i, 13, T_WALL); } + for (i = 1; i < 13; i++) { draw_tile(0, i, T_WALL); draw_tile(19, i, T_WALL); } + draw_tile(9, 13, T_DOOR); draw_tile(10, 13, T_DOOR); + spr_at(0, 120, 168); spr_show(0, S_PDOWN, 1); + spr_at(1, 152, 168); spr_show(1, S_CROWN, 1); + spr_at(2, 184, 168); spr_show(2, S_GSIDE, 3); + spr_at(3, 72, 168); spr_show(3, S_GSIDE, 1); + ink("1;93"); centre(7, "T H E I R O N K E E P"); + ink("0;37"); + centre(10, "You are a prisoner in the Iron Keep. Steal the king's crown"); + centre(11, "from the throne room, and escape down the stairs."); + centre(14, "ARROWS or W A S D move SPACE or CTRL shoot"); + centre(15, "Keys open locked doors. Chests hold gold, crates hold shots."); + centre(16, "Guards see along rows and columns - and they shoot."); + centre(17, "P pauses. ESC gives up."); + ink("1;96"); centre(25, "PRESS SPACE TO BEGIN"); + ink("0"); + return wait_fire(); +} + +static u8 end_screen(void) +{ + u16 score = gold + kills * 50; + u8 j; + if (won) score += 1000 + 500 + lives * 200; + else if (crown) score += 1000; + clear_gfx(); /* a clean box: no walls or figures behind it */ + ink("0;44;97"); + centre(12, " "); + centre(13, won ? " YOU ESCAPED WITH THE CROWN! " : + " THE GUARDS HAVE TAKEN YOU. "); + centre(14, " "); + at(15, 21); puts_(" SCORE "); putn(score); + for (j = 10 + (score > 9) + (score > 99) + (score > 999) + (score > 9999); j < 40; j++) putch(' '); + centre(16, " "); + centre(17, " SPACE TO PLAY AGAIN, ESC TO STOP "); + centre(18, " "); + ink("0"); + return wait_fire(); +} + +/* ----------------------------------------------------------------- game */ +static void play(void) +{ + u8 j, i; + const u8 *o = room_objs[0]; + for (i = 0; i < 12; i++) { gone[i] = 0; opened[i] = 0; } + lives = 3; keys = 0; ammo = 10; gold = 0; kills = 0; crown = 0; + over = 0; won = 0; inv = 0; fire_cool = 0; fire_held = 1; panim = 0; + msg = 0; msg_time = 0; pdir = D_DOWN; + room = 0; + for (; *o; o += 3) + if (o[0] == 'P') { px = o[1] << 4; py = 16 + (o[2] << 4); } + puts_("\033[2J"); + enter_room(); + say("FIND THE CROWN. MIND THE GUARDS."); + while (!over) { + wait_frame(); + if (drain_keys()) { /* P: pause until P again */ + at(1, 40); ink("0;96"); puts_("PAUSED - P TO GO ON\033[K"); ink("0"); + for (;;) { + wait_frame(); + if (joy & J_ESC) { quit = 1; return; } + if (drain_keys()) break; + } + status_dirty = 1; + } + j = joy; + if (j & J_ESC) { over = 1; won = 0; break; } + move_player(j); + edges(); + fire(j); + shots(); + guards(); + pick_up(); + draw_player(); + if (inv) inv--; + if (fire_cool) fire_cool--; + if (msg_time && !--msg_time) status_dirty = 1; + if (status_dirty) status(); + } + status(); + for (i = 0; i < 60; i++) { wait_frame(); drain_keys(); draw_player(); } +} + +int main(void) +{ + rnd_state = 0xACE1 ^ frame_ctr; + last_frame = frame_ctr; + puts_("\033[?3l\033[?25l"); /* 80 columns (this clears), no cursor */ + load_shapes(); + quit = 0; + while (!quit) { + if (!title()) break; + play(); + if (quit) break; + if (!end_screen()) break; + } + clear_gfx(); + puts_("\033[0m\033[2J\033[H\033[?25h"); + while (con_stat & 1) (void)con_data; +} diff --git a/games/keep/keep.ihx b/games/keep/keep.ihx new file mode 100644 index 0000000..8c7a8e5 --- /dev/null +++ b/games/keep/keep.ihx @@ -0,0 +1,989 @@ +:10A2000097420000938282DA17430000130343FB56 +:10A2100063F8620023A00200938242006FF05FFFA8 +:10A2200017130000670083E5834700F093F72700CA +:10A23000E38C07FEA300A0F067800000130101FF7C +:10A240002324810023261100130405000345040084 +:10A25000631A05008320C10003248100130101015A +:10A26000678000001304140097000000E78000FCE2 +:10A270006FF0DFFD130101FE232C8100232E11005E +:10A28000130400009306A000130690003377D50254 +:10A290009307040093870701B38727001304140072 +:10A2A0001374F40F13070703238CE7FE93070500CD +:10A2B0003355D502E36CF6FC631A04008320C10118 +:10A2C0000324810113010102678000001304F4FFDD +:10A2D0001374F40F93070401B387270003C587FFA6 +:10A2E00097000000E78080F46FF01FFD130101FF6D +:10A2F00023229100930405001305B00123261100C9 +:10A30000232481001384050097000000E78000F2F9 +:10A310001305B00597000000E78040F113850400A5 +:10A3200097000000E78040F51305B0039700000098 +:10A33000E780C0EF1305040097000000E780C0F33A +:10A34000032481008320C10083244100130580047D +:10A350001301010117030000670043ED130101FF22 +:10A3600023248100130405001305B00123261100E6 +:10A3700097000000E78080EB1305B0059700000010 +:10A38000E780C0EA1305040097000000E78040EB77 +:10A39000032481008320C1001305D00613010101AD +:10A3A00017030000670083E8130101FF23248100E5 +:10A3B0002326110013840500930700003307F400DF +:10A3C00003470700631A070293D71700930590020B +:10A3D000B385F54093F5F50F97000000E78040F155 +:10A3E00013050400032481008320C100130101012F +:10A3F000170300006700C3E49387170093F7F70F74 +:10A400006FF0DFFBB7E7000003D5A7FA131775005D +:10A410003345E50013150501135505011357950044 +:10A420003345E500131785003345E5001315050195 +:10A43000135505012395A7FA67800000B7E70000D0 +:10A4400003C757FB834680F7E38EE6FE034780F79A +:10A45000A38AE7FA67800000130500009306000551 +:10A46000834700F093F717006394070067800000AC +:10A47000034710F01377F70D6304D7009307050027 +:10A48000138507006FF0DFFD230A00F2834740F3D6 +:10A4900093F71700E39C07FE67800000B7D7000022 +:10A4A0009387872213168600939545001315450060 +:10A4B0003306F600938505011377F50F93F5F50F35 +:10A4C00013558500930706102308E0F2A308A0F2B5 +:10A4D0002309B0F29306060103480600130616008E +:10A4E000A30900F3E31AD6FE9385150093F5F50F43 +:10A4F000E39CC7FC678000002308A0F693F7F50FE4 +:10A5000093D58540A308F0F693F515002309B0F61E +:10A510001376F60FA309C0F66780000093160501B5 +:10A5200093D606019307F0131307050063E2D704DF +:10A53000938505FF9396050193D606019307F00DC9 +:10A540001305F00F63E8D7029306400193D5454009 +:10A55000B385D502B7E700009387470A13574740F2 +:10A56000B387B700B387E70003C507006780000023 +:10A570001305F00F67800000130101FD232861011E +:10A580002326710137DB0000B7DB00002322910294 +:10A59000232E3101232C4101232A5101232481013F +:10A5A000232291012320A1012326110223248102C9 +:10A5B00023202103130A0500938A05009304060053 +:10A5C00093090000130B0B91938BCB90930C10000D +:10A5D000130DF00F130C4000B387690103C9070086 +:10A5E000B387790103C40700330949011315090131 +:10A5F000330454019315040193D5054113550541C6 +:10A6000097000000E780C0F19307F5FF93F7F70F7D +:10A6100063E0FC06B7E7000013594940130404FF48 +:10A62000A38427FB13544440B7E70000238487FA30 +:10A63000930405008320C10203248102032901023F +:10A640008329C101032A8101832A4101032B0101CE +:10A65000832BC100032C8100832C4100032D0100BA +:10A660001385040083244102130101036780000065 +:10A670006314A501E39004FC93891900E39E89F516 +:10A68000930400006FF01FFBB7E70000130740FBC7 +:10A6900023A6A7FAB7E700002389E7FAB7E7000087 +:10A6A00013071000A389E7FA67800000130101FE79 +:10A6B000B7E700009305100013051000232E1100CA +:10A6C000A38907FA232C8100232A91002328210142 +:10A6D0002326310123244101B7C90000970000005F +:10A6E000E78000C11385C94A97000000E78040C792 +:10A6F00037C500001305454B97000000E78040B4C4 +:10A7000037C400001305444C97000000E78040C5A3 +:10A7100037CA00001305CA4C97000000E78040B21A +:10A7200037E700000347070AB7D700009387C791B0 +:10A7300013172700B387E70003A5070037C90000F8 +:10A7400097000000E780C0AF1305094D9700000097 +:10A75000E78000AFB7E7000083A4C7FA638E040266 +:10A76000B7E7000083C727FB6388070293058002D1 +:10A770001305100097000000E78080B737C5000080 +:10A780001305454D97000000E78080BD1385040048 +:10A7900097000000E780C0AA930510001305200071 +:10A7A00097000000E780C0B41305444C97000000F8 +:10A7B000E78000BB37C500001305C54DB7C40000D6 +:10A7C00097000000E780C0A71385444E9700000063 +:10A7D000E78000B9B7E7000003C5B706970000009F +:10A7E000E78080A91305444C97000000E78040B73C +:10A7F00037C500001305C54E97000000E78040A450 +:10A800001385444E97000000E78080B5B7E700004D +:10A8100003C5A70697000000E78000A61305444C77 +:10A8200097000000E780C0B337C500001305854FCF +:10A8300097000000E780C0A01385444E97000000F9 +:10A84000E78000B2B7E7000003C597069700000055 +:10A85000E78080A21305444C97000000E78040B0D9 +:10A8600037C500001305455097000000E780409D64 +:10A870001385444E97000000E78080AEB7E70000E4 +:10A8800003D5670697000000E780009F1305444C3E +:10A8900097000000E780C0ACB7E7000083C78706D9 +:10A8A000638607021305CA4C97000000E7804099B1 +:10A8B0001385C94A97000000E78080AA37C50000C9 +:10A8C0001305055197000000E78080971305094D97 +:10A8D00097000000E780C096032481018320C10116 +:10A8E00083244101032901018329C100032A810036 +:10A8F00037C500001305855113010102170300003D +:10A90000670003A6130101FB232E3103B7E9000002 +:10A910002324810403C4090A9307C00837D7000021 +:10A92000B307F402130787B9232861032326110410 +:10A930002322910423202105232C4103232A5103A0 +:10A940002326710323248103B387E7001307100331 +:10A950003304E40237D700001307C7942326F1001D +:10A96000232291032320A103232EB1013304E40009 +:10A9700097000000E78080B18327C10037E700001F +:10A98000130B470A1385C7081307470A93060700E6 +:10A990009385A70003C607009387170093862600B8 +:10A9A0001378F60013564600238F06FFA38FC6FECA +:10A9B000E392B7FE13074701E39AA7FCB7EB000049 +:10A9C000930A000013090000130C2000938BCB079F +:10A9D000930C4001130DE000130A0B0093040000D8 +:10A9E00003460A006314861383C7090A13871A00F3 +:10A9F0001377F70FB387FB0083C70700B3D757411F +:10AA000093F717006380071223000A00930A0700D8 +:10AA10009384140093F4F40F130A1A00E39294FD44 +:10AA2000130919001379F90F130B4B01E316A9FB56 +:10AA3000B7E400009387C40337E9000023920700BE +:10AA400037EA00009307C9FEB7EA000037EB0000C1 +:10AA5000B7EB000023AE040223A0070023A20700E7 +:10AA6000930D0000130D0000930C00009384C403A9 +:10AA70001309C9FE130A8A08938ACA00130BCBFF75 +:10AA8000938B4BFF034C040063120C0AB7E70000E2 +:10AA9000239207FCB7E7000023AE07FAB7E70000F0 +:10AAA000238D07FAB7E7000003D78707B7E7000051 +:10AAB0008320C104239AE706B7E7000003D767079E +:10AAC00003248104B7E700002399E706B7E70000F5 +:10AAD00013071000A389E7FA832441040329010422 +:10AAE0008329C103032A8103832A4103032B010322 +:10AAF000832BC102032C8102832C4102032D01020E +:10AB0000832DC1011301010567800000E30206F0F7 +:10AB1000930509001385040097000000E780409822 +:10AB20006FF01FEF930A07006FF09FFE83C7090ABB +:10AB300093971700B307FA0083D70700B3D7B7413D +:10AB400093F717006396070E930700056302FC0E48 +:10AB50001307DCF91377F70F9307300183451400CF +:10AB60000346240063EEE70CB7070800938717023B +:10AB7000B3D7E70093F717006384070CB7E700002B +:10AB800013971C0093878705B387E70093954500CB +:10AB90002390B700B7E700009387C7041316460059 +:10ABA000B387E700130606012390C700B7E700004C +:10ABB00093874703B387970123808701130710000A +:10ABC000B38794012380E700B7E70000938747022B +:10ABD000B387970123800700B7E700009387C70179 +:10ABE000B38797012380B7019307600713073000ED +:10ABF0006314FC0013070000B7E7000093874704C5 +:10AC0000B38797012380E70097F0FFFFE780C07FBD +:10AC1000B7E700009387C7021375F501B387970163 +:10AC20001305E501938C1C002380A70093FCFC0F07 +:10AC3000938D1D001304340093FDFD0F6FF09FE40E +:10AC4000131646001306060193171D009395450041 +:10AC5000131606013387FA0013560641B307FB00AB +:10AC6000939505012390C70093D50541B387AB01A8 +:10AC7000238087012310B700B307A9011307100031 +:10AC80002380E700B7E70000938747FE1305DD0048 +:10AC9000B387A7011375F50F2380B7012326A10001 +:10ACA000130CFCFB97000000E7804085137CFC0F31 +:10ACB0001307A0000325C10093071001636A8701F1 +:10ACC000B7D7000093870790B387870183C7070032 +:10ACD0002308A0F6230AF0F6130D1D0093071000B9 +:10ACE000A30AF0F6137DFD0F6FF09FF437E7000025 +:10ACF0008347A706639A070037C500001305C551AF +:10AD000017030000670083989387F7FF130101FF83 +:10AD10002305F706B7E7000003C597FAB7E7000079 +:10AD200083C587FA13074001B7E7000003C3070A8A +:10AD30003387E5021308C008B7D8000023261100A6 +:10AD40009307000093060000938888B9130F200032 +:10AD5000330803033307E5001317070113570701EF +:10AD60006310F706B7E700009387C707B38767004C +:10AD7000130710003317D70083C60700130600001F +:10AD80003367D7002380E700130740013387E502CC +:10AD9000B7E700009387470AB387E700B387A700A8 +:10ADA0002380070097F0FFFFE780806F37C5000022 +:10ADB0008320C10013054553130101016FF05FF4B7 +:10ADC00013D617003306C80033061601834E06005B +:10ADD00013F6170013FEFE006304060013DE4E0098 +:10ADE0006316EE019386160093F6F60F938717000D +:10ADF0009397070193D707016FF09FF6130101FFA7 +:10AE0000B7E700002322910083C4070723248100B1 +:10AE10002326110013040000638A04009307100026 +:10AE2000130440006394F40013042000B7E700000B +:10AE300003966707B7E700008395870713050000AF +:10AE400097F0FFFFE780806BB7E7000083C7F70646 +:10AE500093D7370093F717003304F400B7E70000E7 +:10AE600003C7C7069307000013774700631A07005C +:10AE700013072000930710006394E4009307300049 +:10AE8000230800F6230A80F6A30AF0F6B7E40000D0 +:10AE900003C4A4FB63020404B7E70000039667FB46 +:10AEA000B7E70000839587FB130550011304F4FFF7 +:10AEB00097F0FFFFE78080641374F40F238D84FA0A +:10AEC000930750012308F0F69307200133348000E4 +:10AED000230AF0F6A30A80F68320C1000324810030 +:10AEE000832441001301010167800000130101FF69 +:10AEF0002326110023248100034480F81374040BDB +:10AF00006318040497F0FFFFE780805397F0FFFF7A +:10AF1000E780C05497F0FFFFE780004F834780F839 +:10AF200013F7F70F9397870193D7874163C80700FB +:10AF300093770703E38807FC130410008320C10004 +:10AF40001305040003248100130101016780000040 +:10AF500097F0FFFFE780C04E97F0FFFFE7800050BB +:10AF60006FF09FF9130101FF2324810037E70000F0 +:10AF700037E400008347C406834617FB23261100ED +:10AF80002322910023202101B3E7D700639C07040B +:10AF9000B7E700009306E00137E90000238DD7FAF8 +:10AFA00083568907B7E70000B7E40000239CD7FA6F +:10AFB00083D66407B7E70000239BD7FAB7E6000003 +:10AFC00083C7B6069387F7FF93F7F70FA385F606B7 +:10AFD0006396070293071000A308F7FAB7E700008B +:10AFE000238807FA8320C1000324810083244100C1 +:10AFF00003290100130101016780000037C500002B +:10B000001305455597F0FFFFE7804068B7E700005C +:10B0100083D7470713079000231CF906B7E7000002 +:10B0200083D72707239BF406930780072306F4069C +:10B03000B7E70000238E07FA2308E0F6A30A00F61C +:10B040009387C7FBA38007001307A0002308E0F63F +:10B05000A30A00F6238107001307B0002308E0F6D7 +:10B06000A30A00F6A38107009307C0002308F0F6A7 +:10B07000A30A00F66FF01FF7130101F9232611064A +:10B08000232481062322910623202107232E310524 +:10B09000232C4105232A5105232861052326710508 +:10B0A00023248105232291052320A105232EB1030A +:10B0B0002326010023280100834780F737B7FFFFCD +:10B0C000130717CEB3C7E70037E700002315F7FAD9 +:10B0D000034780F737C50000B7E700001305C55BDD +:10B0E000A38AE7FA97F0FFFFE7808015B7D7000043 +:10B0F000938787621307000093063001230BE0F665 +:10B100001386070883C5070093871700A30BB0F6C3 +:10B11000E39AC7FE130717001377F70FE310D7FE64 +:10B12000B7E70000238A07FAB7D700009387879113 +:10B1300037D400002324F10013044491B7E7000042 +:10B1400083C447FB6394043C97F0FFFFE78000341F +:10B1500037C500001305855C97F0FFFFE780400EC0 +:10B160001309400113850400130610009305000025 +:10B1700097F0FFFFE780C03213850400938414002A +:10B18000130610009305D00093F4F40F97F0FFFF1F +:10B19000E7800031E39824FD930410001309D000E8 +:10B1A00093850400130610001305000097F0FFFFBD +:10B1B000E780002F93850400938414001306100089 +:10B1C0001305300193F4F40F97F0FFFFE780402D53 +:10B1D000E39824FD130620009305D000130590008A +:10B1E00097F0FFFFE780C02B130620009305D000E7 +:10B1F0001305A00097F0FFFFE780802A93078007E0 +:10B20000230800F6A308F0F6230900F6930780FA56 +:10B21000A309F0F6230800F6230A00F693041000B1 +:10B22000A30A90F6230890F6130780F9A308E0F626 +:10B23000230900F6A309F0F6230890F6130710017E +:10B24000230AE0F6A30A90F6130720002308E0F68D +:10B25000930680FBA308D0F6230900F6A309F0F6B5 +:10B260002308E0F6130AA000230A40F71309300070 +:10B27000A30A20F713078004230820F7A308E0F6A9 +:10B28000230900F6A309F0F6230820F7230A40F764 +:10B2900037C500001305455DA30A90F697F0FFFF40 +:10B2A000E780000CB7C500009385C55D13057000ED +:10B2B00097F0FFFFE780800F37C500001305454C6E +:10B2C00097F0FFFFE780C009B7C500009385855F51 +:10B2D0001305A00097F0FFFFE780400DB7C5000001 +:10B2E000938545631305B00097F0FFFFE780000CDE +:10B2F000B7C50000938585661305E00097F0FFFF52 +:10B30000E780C00AB7C500009385C5691305F00042 +:10B3100097F0FFFFE7808009B7C500009385C56DF2 +:10B320001305000197F0FFFFE7804008B7C5000054 +:10B33000938505711305100197F0FFFFE780000763 +:10B3400037C500001305C57297F0FFFFE780400185 +:10B35000B7C50000938545731305900197F0FFFF73 +:10B36000E780C004B7C700001385875197F0FFFF3F +:10B37000E78000FF97000000E78080B763080518AA +:10B38000B7E70000130680011385870893050000C6 +:10B3900097100000E7800010B7E700009387C70709 +:10B3A00023A0070023A2070023A40700B7E700009B +:10B3B000A3852707B7E7000023850706B7E7000046 +:10B3C00023930706B7E7000023920706B7E70000BC +:10B3D00023840706B7E70000A38807FAB7E7000051 +:10B3E000238807FAB7E7000023860706B7E70000BF +:10B3F00023870706B7E70000A3869706B7E7000094 +:10B40000A3870706B7E7000023A607FAB7E70000FF +:10B41000238907FAB7E7000023880706B7E700008B +:10B42000B7E900002380070AB7D70000A3844907C3 +:10B43000130700009387C7941306000583C607000F +:10B4400063980612630E07000327C100B7E70000E8 +:10B45000239BE70603270101B7E70000239CE706CB +:10B4600037C500001305C55C97F0FFFFE78040DD9E +:10B4700097F0FFFFE780404937C500001305C5740A +:10B4800097F0FFFFE7808020B7E7000083C717FB36 +:10B49000639A071497F0FFFFE78080FA97F0FFFFA9 +:10B4A000E780C0FB630C05109305800213051000B4 +:10B4B00097F0FFFFE780C0E337C500001305454D57 +:10B4C00097F0FFFFE780C0E937C500001305057757 +:10B4D00097F0FFFFE780C0D6B7C7000013858751FC +:10B4E00097F0FFFFE780C0E797F0FFFFE78040F5A8 +:10B4F000834780F89397870193D7874163D4070ADE +:10B500009307100037E70000230AF7FA97F0FFFFD0 +:10B51000E780C0F737D500001305058797F0FFFFD8 +:10B52000E78000D2834700F093F71700E39E07748B +:10B530008320C106032481068324410603290106D2 +:10B540008329C105032A8105832A4105032B0105AF +:10B55000832BC104032C8104832C4104032D01049B +:10B56000832DC1031305000013010107678000004C +:10B570006396C60203C71700131747002328E1008C +:10B5800003C7270013174700130707011317070105 +:10B59000135707412326E100130710009387370054 +:10B5A0006FF0DFE997F0FFFFE78040EBE30E05F275 +:10B5B000B7E7000013071000A389E7FA834780F874 +:10B5C00013FAF70F9397870193D7874163D6071C28 +:10B5D0009307100037E70000A308F7FAB7E7000069 +:10B5E000238807FA97F0FFFFE780800C9304C003DD +:10B5F00097F0FFFFE780C0E49384F4FF97F0FFFF2C +:10B60000E780C0E593F4F40F97F0FFFFE780407FF9 +:10B61000E39004FEB7E7000083C747FBE39807EE1B +:10B62000B7E7000083D4470693072003B7E900007B +:10B63000B384F402B7E7000083D76706B384F4004D +:10B6400083C709FB9394040193D40401E38C07603E +:10B65000B7E7000083C7B7061307800CB387E7027C +:10B66000B387F4009387C75D9394070193D40401D3 +:10B6700097F0FFFFE78080E137D500001305458094 +:10B6800097F0FFFFE780C0CD37D900009305C98050 +:10B690001305C00097F0FFFFE78040D183C709FB87 +:10B6A000E38E075CB7C50000938545561305D000AF +:10B6B00097F0FFFFE78080CF9305C9801305E00076 +:10B6C00097F0FFFFE78080CE930550011305F0004F +:10B6D00097F0FFFFE780C0C137D5000013058583D1 +:10B6E00097F0FFFFE780C0B51385040097F0FFFFD8 +:10B6F000E78080B813B7440693B6843E93B616002D +:10B70000133717003307D700B726000093079000C0 +:10B710009386F670B3B79700B3B496009387A700EB +:10B72000B384E400B38497009309800293841400E7 +:10B730001305000293F4F40F97F0FFFFE78000AFCA +:10B74000E39634FF9305C9801305000197F0FFFFCE +:10B75000E780C0C5B7D50000938545841305100167 +:10B7600097F0FFFFE78080C49305C980130520018F +:10B7700097F0FFFFE78080C3B7C7000013858751AC +:10B7800097F0FFFFE780C0BD97F0FFFFE7804076AE +:10B79000E316059A6FF09FD7937ACA00B7E40000CA +:10B7A000638C0A0C13774A0093371700938727009E +:10B7B000B7E600002388F60693072000630607001B +:10B7C000B70701009387E7FF03D78407130600003C +:10B7D000B387E70013990701B7E700008395670770 +:10B7E000135909411305090097F0FFFFE78000D9BD +:10B7F000631C0506239C24071309100093773A0065 +:10B800006388070893771A0063960A0037E70000F9 +:10B810002308F7069305200063860700B70501009B +:10B820009385E5FF37EB000083576B07039584078B +:10B8300013060000B385F500939A050193DA0A41D7 +:10B8400093850A0097F0FFFFE78040D3631A050253 +:10B85000231B5B0737E700008347F7069387170032 +:10B86000A307F7066F000003930720006316F50097 +:10B8700097F0FFFFE780C047130900006FF01FF843 +:10B88000930720006316F50097F0FFFFE78040461E +:10B89000E31209FC839784071307D0FF63D4E732D0 +:10B8A00037E700008347070A9387F7FF2300F70A6B +:10B8B00093070013239CF40697F0FFFFE780C00472 +:10B8C00037E90000B7ED000037EC0000B7EB0000EF +:10B8D000137A0A01834749FC37E70000130949FC42 +:10B8E000938D8DFC130C0CFE938BCBFD63120A34ED +:10B8F000A3060706130B1000930A5000130A10004A +:10B90000834709006380070883C70D000327810070 +:10B910003387E700B3878700830C0700038D070098 +:10B9200003570C00B38C5C0383D70B00330D5D030E +:10B93000B38CEC00939C0C0193DC0C4123109C0114 +:10B9400013850C00330DFD00131D0D01135D0D411A +:10B950002390AB0193050D0097F0FFFFE78040BCFB +:10B960009307F5FF93F7F70F6376FA009307F00F4D +:10B97000631EF53A230009009377FB0F2308F0F6C6 +:10B98000A30A00F613091900130C2C00938B2B004B +:10B99000938D1D0063084B3937E50000B7E50000C3 +:10B9A0009307C5FB37E60000232AF100938745FD86 +:10B9B000B7E60000232CF100930706FC232EF100CC +:10B9C0009387C6FC130CC5FB138A45FD930A06FC3E +:10B9D0001389C6FC930B90002320F102130B300057 +:10B9E000930CF00F83460C00638E060883278100BA +:10B9F00083C60A003386F600B38686000305060078 +:10BA0000038D060003560A003305650383560900BB +:10BA1000330D6D033305C500931D05011318050192 +:10BA200093DD0D41135808012310BA0113850D0051 +:10BA300023240103330DDD0013160D01131D0D0129 +:10BA4000135D0D41135606012310A90193050D0046 +:10BA50002322C10297F0FFFFE78080AC9306F5FF39 +:10BA600093F6F60F9307100063F8D7000326410200 +:10BA7000032881026310954123000C00230870F70E +:10BA8000A30A00F693871B0093FBF70F9307D000E0 +:10BA9000130C1C00130A2A00938A1A0013092900A8 +:10BAA000E392FBF4B7EC0000B7EA000037EA0000CD +:10BAB00037E9000037EC0000B7EB0000B7E4000006 +:10BAC000938CCC03938A4A04130A8A051309C90488 +:10BAD000130C4C03938B4B029384C402130B300062 +:10BAE000B7ED000083C70C00638A074C83C70400CE +:10BAF000638607009387F7FF2380F400B7E7000011 +:10BB000083C7C70683160A0003170900639A077CD8 +:10BB100083D86D071317070113037000135707012C +:10BB2000330E1341939606019307870093D60601BF +:10BB30003307C70113858600131707011316050184 +:10BB400093950701131505019397070137E8000046 +:10BB500013570701130EE000035888071356060118 +:10BB60001355054193D5050193D707416366EE62EE +:10BB700013088800131808011358084193564540CC +:10BB800013574840938707FF93F6F60F1377F70F85 +:10BB900093D747406368D7009308070013870600D0 +:10BBA000938608001303400193F7F70FB3876702EA +:10BBB000B7E800009388480A13031000B387F80021 +:10BBC0006F00C03313073013635EF70037E70000E0 +:10BBD0008347070A239C0406938717002300F70A6C +:10BBE0006FF09FCDB7E70000039767079306D0007B +:10BBF00063C0E602B7E6000003C7060A1307C7FFE3 +:10BC00002380E60A1307000E239BE7066FF0DFCAC6 +:10BC10009306100EE3D6E6CAB7E6000003C7060A8D +:10BC2000130747002380E60A130700016FF0DFFDCA +:10BC3000B7E500008346D70603C6E506B3E6C600AF +:10BC4000E39A06CA03C5990693061000A306D70611 +:10BC5000630E05006386070283471900E39C07C84B +:10BC600093071000930610006F00C00137C5000055 +:10BC70001305857897F0FFFFE78040A16FF09FC71D +:10BC80009306000033872601130610002300C70027 +:10BC900037E70000034707073388B60193086000C1 +:10BCA0002300E800139816008326810003D384073D +:10BCB000330E8801B306D70083860600330787005A +:10BCC00003070700B3861603130383009387170047 +:10BCD00093F7F70F33071703B38666002310DE00D0 +:10BCE000B306780137E80000035868071308880096 +:10BCF000330707012390E6001307F5FFA384E90645 +:10BD0000130780002387E50637E70000A309C7FA79 +:10BD10002308F0F69307C000230AF0F6A30AC0F642 +:10BD20006FF05FBD130B20006FF09FBD37E7000081 +:10BD300037E60000B7E80000130887051305C604BE +:10BD400093070000130787051306C6049388C803EA +:10BD5000130E6000338317018345030063820510CF +:10BD600083150800938E250063DC9E0F9385C50024 +:10BD700063C8950F83150500938E150063D2AE0F2F +:10BD80009385E50063CEA50DB7E6000083C5060ADE +:10BD9000B7E6000013858608939515003305B500B6 +:10BDA000B7E500009385C501B385F50003C805001C +:10BDB0009305100023000300B39505010358050007 +:10BDC000B3E505012310B5009385370093F5F50F12 +:10BDD0002308B0F6A30A00F6230009009375FB0FB1 +:10BDE0002308B0F693971700A30A00F63307F7006D +:10BDF000B7E5000013054001238DA5FA8355070020 +:10BE0000B307F60037E70000231CB7FA03D7070093 +:10BE1000B7E70000239BE7FA37E7000083574706A0 +:10BE2000938717002312F70683470900E38C07B4B2 +:10BE300003D60B0083550C0013050B00130686FF79 +:10BE4000938585FF13160601939505011356064148 +:10BE500093D5054197E0FFFFE780406A6FF09FB2FE +:10BE6000938717001308280013052500E394C7EFF4 +:10BE70006FF01FFC839684079385260063DEB5036D +:10BE80009386C60063CAB603B7E6000083966607CA +:10BE90009385160063D2A5039386E60063CEA601C0 +:10BEA00023000C00230870F7A30A00F697F0FFFFA9 +:10BEB000E780800B6FF01FBD930588FF130686FF98 +:10BEC00013160601939505011356064193D50541B6 +:10BED00013850B0097E0FFFFE78040626FF09FBA89 +:10BEE000B388E70083C808009388F8FF93F8F80F39 +:10BEF0006378133F130717001377F70FE3F2E6FE9B +:10BF0000130D40006354A800130D30001308FDFF0B +:10BF100083C60B001378F80F23800A0103C70400BF +:10BF200063980630930610002380DB00930680019F +:10BF300063E6E600130790012380E40083460C00CB +:10BF4000130730066382E63A03C70A0083150A0026 +:10BF50000316090013050B002326E1022324C10266 +:10BF60002322B10297E0FFFFE78040590327C10277 +:10BF7000832541020326810293076000630A0700BC +:10BF8000930610009307A0006314D7009307800066 +:10BF9000B385C50093D5354093F5150013062000F1 +:10BFA000B387B700930610006314C70093063000F0 +:10BFB000230860F7230AF0F6A30AD0F6130B1B0040 +:10BFC000137BFB0F93079000938C1C00938A1A003D +:10BFD000130A2A0013092900130C1C00938B1B0061 +:10BFE00093841400E310FBB037E90000B7EA0000C7 +:10BFF00037EA0000B7E7000037EB0000B7EB0000BE +:10C000001309C9FE938ACA00130ACAFF93040000E9 +:10C0100037EC0000B7EC000037ED0000938D870887 +:10C02000130B4BFE938B4BFF83470900638A070872 +:10C0300003970A0083178C079306970063C2F608DC +:10C040009387970063CEE70603170A0083976C0770 +:10C050009306C70063C6F6069387C70063C2E70668 +:10C0600083470D0A3387640103470700939717003E +:10C07000B387FD0003D60700930610003397E60050 +:10C080003367C7002390E7009387D400230009009B +:10C0900093F7F70F2308F0F6A30A00F6B3877401AD +:10C0A00083C70700130770046386E734636EF730B5 +:10C0B00013071004638EE734130730046386E736F2 +:10C0C000938414009307800013091900938A2A00AF +:10C0D000130A2A00E39AF4F4B7E7000083D5670750 +:10C0E000B7E7000003D58707938585009395050181 +:10C0F000130585001315050193D505411355054119 +:10C1000097E0FFFFE780C04193073000B7E40000ED +:10C110006314F502B7E7000083C7870603C724FB53 +:10C12000638E07309307100037E70000A308F7FA83 +:10C1300037E700002308F7FA97F0FFFFE78040CCCD +:10C1400037E700008347C706638607009387F7FF3A +:10C150002306F70637E700008347E70663860700F4 +:10C160009387F7FF2307F70683C724FB37E7000011 +:10C170006384072E9387F7FF93F7F70F2389F4FA69 +:10C18000639C072C93071000A309F7FA97E0FFFFC1 +:10C19000E78000526FF04FAF3303034133876600EF +:10C1A0001317070113570701636CEE129388880079 +:10C1B0009398080193D80841138307FF138708FF5A +:10C1C0001353434013574740135545401373F30F20 +:10C1D0001377F70F1375F50F636867009306070071 +:10C1E000130703001383060037E800001308480A0A +:10C1F000130E4001930E10006F008002B306C703B8 +:10C20000B306D800B386A60083C606009386F6FF61 +:10C2100093F6F60F63F6DE0C130717001377F70F8C +:10C22000E37EE3FC33ADF800130D1D006FF01FCE6D +:10C23000E31607D013050000930640008327410151 +:10C240003387A70083480700639608088327C10146 +:10C2500093081000230017013387A700832781016B +:10C260009316150023000701338ED7008327810022 +:10C27000130360003307F800030707003308880042 +:10C280008327010233076702B386D7003307E6002E +:10C290002310EE0003070800330767023387E50029 +:10C2A0002390E600130795001377F70F2308E0F6B5 +:10C2B0001307D000230AE0F6A30A10F797E0FFFF68 +:10C2C000E78080141375F5031305D5022380A400BD +:10C2D0006FF0DFC613051500E312D5F66FF01FC629 +:10C2E00023800B00130D000083C60A008327810002 +:10C2F000835509002326D1023387F6000306070081 +:10C3000003570A003307C70033868600030606007A +:10C310001317070113570741B385C500939505010E +:10C3200093D5054113050700130610002324B1021D +:10C330002322E10297E0FFFFE78040240327410228 +:10C3400083258102630C050603460C0013073006A3 +:10C350008326C102631CE604631A0D0097E0FFFF09 +:10C36000E780800A137535002380AA0037E60000B5 +:10C370000316860703170A00831709009305960022 +:10C3800083966D07E3C2E5BC13079700E34EC7BA77 +:10C390001387C600E34AF7BA9387C700E3C6D7BA44 +:10C3A00097F0FFFFE78040BC6FF01FBAE3100DFC71 +:10C3B00093C716002380FA006FF05FFB2310EA009A +:10C3C0002310B9006FF09FFA1307B004E39AE7CE89 +:10C3D00037E700008347A70637C500001305C57976 +:10C3E000938717002305F70697E0FFFFE780002AF1 +:10C3F0006FF01FCD37E700008357670637C5000091 +:10C400001305457A938747062313F7066FF0DFFD80 +:10C4100083C7990637C500001305857B93875700AE +:10C42000A384F9066FF05FFCB7E7000037C5000092 +:10C430002384D7061305C57C6FF01FFB9307700795 +:10C44000E3ECE7CE37C500001305C57E97E0FFFF9C +:10C45000E780C0236FF05FCE834737FB6386078298 +:10C460006FF0DFD2B7E7000083C78706638207A0BB +:10C470009384843E939404016FF04F9FB7C50000EE +:10C48000938505596FF08FA2834710F06FF08F8965 +:10C490003306C500930705006394C700678000005A +:10C4A00093871700A38FB7FE6FF01FFF303B393320 +:10C4B000000000005448452049524F4E204B45454E +:10C4C00050000000303B33370000000020202000E7 +:10C4D0001B5B4B00303B3936000000004C49564591 +:10C4E00053200000303B3937000000002020204B53 +:10C4F0004559532000000000202020414D4D4F2081 +:10C5000000000000202020474F4C44200000000085 +:10C5100043524F574E000000300000004C4F434B39 +:10C5200045442E20594F55204E4545442041204B2F +:10C5300045592E00544845204B4559205455524EDC +:10C54000532E2054484520444F4F52204F50454EC3 +:10C55000532E0000594F552041524520484954213F +:10C5600000000000202020594F55204553434150E2 +:10C5700045442057495448205448452043524F577A +:10C580004E212020202020202020202000000000FC +:10C5900020202054484520475541524453204841CB +:10C5A00056452054414B454E20594F552E202020B2 +:10C5B0002020202020202020000000001B5B3F3393 +:10C5C0006C1B5B3F32356C001B5B306D1B5B324A72 +:10C5D00000000000313B39330000000054204820A7 +:10C5E00045202020492052204F204E2020204B2043 +:10C5F0004520452050000000596F7520617265206C +:10C600006120707269736F6E657220696E20746844 +:10C61000652049726F6E204B6565702E20537465DE +:10C62000616C20746865206B696E67277320637284 +:10C630006F776E0066726F6D207468652074687223 +:10C640006F6E6520726F6F6D2C20616E6420657354 +:10C650006361706520646F776E2074686520737401 +:10C66000616972732E0000004152524F5753206F80 +:10C6700072205720412053204420206D6F76652082 +:10C68000202020202020205350414345206F72203D +:10C690004354524C202073686F6F74004B6579735C +:10C6A000206F70656E206C6F636B656420646F6FC4 +:10C6B00072732E2043686573747320686F6C6420F6 +:10C6C000676F6C642C2063726174657320686F6C93 +:10C6D000642073686F74732E0000000047756172E8 +:10C6E00064732073656520616C6F6E6720726F776D +:10C6F0007320616E6420636F6C756D6E73202D20E6 +:10C70000616E6420746865792073686F6F742E00A1 +:10C7100050207061757365732E2020455343206748 +:10C72000697665732075702E00000000313B393644 +:10C7300000000000505245535320535041434520C0 +:10C74000544F20424547494E0000000046494E44A0 +:10C75000205448452043524F574E2E204D494E44B9 +:10C7600020544845204755415244532E00000000B4 +:10C77000504155534544202D205020544F20474FC1 +:10C78000204F4E1B5B4B00004F5554204F4620411D +:10C790004D4D554E4954494F4E21000041204B45C7 +:10C7A00059210000474F4C44212031303020435262 +:10C7B0004F574E532E00000046495645204D4F52CC +:10C7C000452053484F54532E000000005448452044 +:10C7D00043524F574E21204E4F572046494E44203A +:10C7E000544845205354414952532E004E4F542033 +:10C7F000574954484F5554205448452043524F57A9 +:10C800004E2E0000303B34343B39370020202020AE +:10C810002020202020202020202020202020202018 +:10C820002020202020202020202020202020202008 +:10C83000202020200000000020202053434F52459C +:10C8400020000000202020535041434520544F2019 +:10C85000504C415920414741494E2C2045534320DB +:10C86000544F2053544F502020202020000000001F +:10C870001B5B306D1B5B324A1B5B481B5B3F3235D9 +:10C880006800000047415445484F5553450000009B +:10C89000475541524420524F4F4D000043484150AC +:10C8A000454C000041524D4F55525900434F525292 +:10C8B00049444F520000000047524541542048412E +:10C8C0004C4C000043454C4C415253004C494252A1 +:10C8D00041525900535441495257454C4C000000B5 +:10C8E00044554E47454F4E005452454153555259B9 +:10C8F000000000005448524F4E4520524F4F4D000B +:10C900001011111111110F1111110E0002020E0E52 +:10C91000030C030C01FF00000000FF0184C80000AD +:10C9200090C800009CC80000A4C80000ACC800006B +:10C93000B8C80000C4C80000CCC80000D4C80000BB +:10C94000E0C80000E8C80000F4C80000500302413D +:10C9500009060000000000000000000000000000C8 +:10C9600000000000000000000000000000000000C7 +:10C97000000000000000000000000000006802024B +:10C980004B0906680C0A00000000000000000000CF +:10C990000000000000000000000000000000000097 +:10C9A000000000000000000000000000000076020F +:10C9B00002760D02470805470A0568050A000000CF +:10C9C0000000000000000000000000000000000067 +:10C9D0000000000000000000000000000000004116 +:10C9E000030241100268090663080B000000000002 +:10C9F0000000000000000000000000000000000037 +:10CA00000000000000000000000000000000000026 +:10CA1000760202680F0441030A760F0B0000000043 +:10CA20000000000000000000000000000000000006 +:10CA300000000000000000000000000000000000F6 +:10CA400000470302471002680905680A0963020BE0 +:10CA5000760E0B0000000000000000000000000047 +:10CA600000000000000000000000000000000000C6 +:10CA70000000410B0668100B0000000000000000E1 +:10CA800000000000000000000000000000000000A6 +:10CA90000000000000000000000000000000000096 +:10CAA000000000680B054B090A76040B000000002B +:10CAB0000000000000000000000000000000000076 +:10CAC0000000000000000000000000000000000066 +:10CAD0000000000068050A000000000000000000DF +:10CAE0000000000000000000000000000000000046 +:10CAF0000000000000000000000000000000000036 +:10CB000000000000007609064B030A470D0A0000EA +:10CB10000000000000000000000000000000000015 +:10CB20000000000000000000000000000000000005 +:10CB3000000000000000680302470705470A054798 +:10CB40000E05760A0A000000000000000000000048 +:10CB500000000000000000000000000000000000D5 +:10CB60000000000000000063020363110343090793 +:10CB700076020B76110B00000000000000000000A0 +:10CB800000000000000000000000000000000000A5 +:10CB9000000000000000000011111111111111110D +:10CBA0001111010000000000000000100100000051 +:10CBB0000000000000100100000000000000001054 +:10CBC00001001011010010110110010010000000FF +:10CBD0000000011001001000000000000100010031 +:10CBE00010000000000001000100101101001011F0 +:10CBF0000110010000000000000000100100000012 +:10CC00000000000000100100000000000000001003 +:10CC100001000000000000000010111111110011AE +:10CC20001111111111111111111111111111010015 +:10CC300000000000000000100100000000000000E3 +:10CC400000100100000000000000001001101100A1 +:10CC50000000101100100110000000000010001072 +:10CC60000010000000000010000000100000000094 +:10CC70000010000001101100000010110010010050 +:10CC80000000000000000010010000000000000093 +:10CC90000010010000000000000000100100000072 +:10CCA00000000000001011111111111111111111CA +:10CCB00011111111111111111111010000000000C9 +:10CCC0000000001001000000000000000010010042 +:10CCD0000000000000000010010000101111010010 +:10CCE00000100100001000100000001000000010F3 +:10CCF00000200000000000000010111100000000E2 +:10CD00000100000000000000001001000000000011 +:10CD100000000010010000000000000000100100F1 +:10CD200000000000000000100100000000000000F2 +:10CD300000101111111111111111111111111111F5 +:10CD4000111111111111010000000000000000106C +:10CD500001000000000000000010010000000000C1 +:10CD6000000000100111110000001011011001005D +:10CD700000000000000000100000000000000000A3 +:10CD80000010000000000000000000100111110060 +:10CD90000000101101100100000000000000001050 +:10CDA0000100000000000000001001000000000071 +:10CDB0000000001001000000000000000010111130 +:10CDC0001111001111111111111111110011111175 +:10CDD000111101000000000000000010010000001F +:10CDE00000111100001001000000000100000010FF +:10CDF00001000000000100000010111111110001DC +:10CE00000000001001000000000000000000010010 +:10CE1000000000000000000011111111001111119B +:10CE200011100100000000010000001001000000CE +:10CE300000010000001001000000000100000010CF +:10CE4000010000000000000000101111111100117C +:10CE500011111111111111111111111111110100E3 +:10CE600000000000000000100100000000000000B1 +:10CE7000001001000000000000000010010010017F +:10CE8000000010010010010010010000100100104E +:10CE90000000000000000000000000000000000092 +:10CEA000000000000100100100001001001001004E +:10CEB000100100001001001001000000000000003F +:10CEC0000010010000000000000000100100000040 +:10CED00000000000001011111111001111111111A9 +:10CEE0001111111111111111111101000100000096 +:10CEF00001000010010001111101011111100100C8 +:10CF000001010000010010100100000111111101C8 +:10CF1000101011111101010000011010000000009B +:10CF200001000001000000111111010000110100B9 +:10CF30000101000000110100001001011111110197 +:10CF40000111111001010000000001010010011188 +:10CF50001101111101010010010000000100000089 +:10CF600001101111111111111111111111111111C2 +:10CF7000001111111111010000000000000000104B +:10CF8000011110011110011110100100000000002A +:10CF9000000000100111100111100111101001000A +:10CFA0000000000000000010000000000000000071 +:10CFB00000100011100111100111101001000000EB +:10CFC00000000000001001111001111001111010DB +:10CFD000010000000000000000100100000000003F +:10CFE00000000010010000000000000000101111FE +:10CFF0001111001111111111111111110011111143 +:10D0000011110100000000000000001001000000EC +:10D010000000000000100110111101101111011089 +:10D02000011000000000000001100110000030039A +:10D030000000011001100000300300000100011089 +:10D040000000000000000100011011110110111179 +:10D0500001100100000000000000001001000000AD +:10D06000000000000010010000000000000000109F +:10D070000100000000000000001011111111111139 +:10D0800011111111111111110011111111110101C1 +:10D09000100001100001101001011000011000012A +:10D0A00010100101100001100001101001111011E9 +:10D0B000011011011110010000000000000000101B +:10D0C0000000000000000000000000000000000060 +:10D0D00000000000011110110110110111100101D7 +:10D0E00010000110000110100101100001100001DA +:10D0F00010100101100001100001101001000000CB +:10D100000000000000101111111111111111111165 +:10D110001111111111111111111101000000000064 +:10D1200000000010010000000000000000100100DD +:10D130000000000000000010010000111111111189 +:10D1400000100100000100000010001000000001AC +:10D150000000001000100000001111111211001049 +:10D1600001000000000000000010010000000000AD +:10D17000000000100100000000000000001001008D +:10D18000000000000000001001000000000000008E +:10D190000010111111111111111111111111111191 +:10D1A000001111111111111111111211111111117F +:10D1B000010000000000000000100100000000005D +:10D1C000000000100100000000000000001001003D +:10D1D00011110000111100100100010000000010E9 +:10D1E000001001000100000000100010010001000B +:10D1F00000000010001001001111000011110010BA +:10D20000010000000000000000100100000000000C +:10D2100000000010010000000000000000101111CB +:10D220001111111111111111000000000000000076 +:10D2300000000000000000000000000000000000EE +:10D2400000000000000000000000000000000000DE +:10D2500000000000000000000000000000000000CE +:10D2600000000000000000000000000000000000BE +:10D2700000000000000000000000000000000000AE +:10D28000000000000000000000000000000000009E +:10D29000000000000000000000000000000000008E +:10D2A000000000000000000000000000000000007E +:10D2B000000000000000000000000000000000006E +:10D2C000000000000000000000000000000000005E +:10D2D000000000000000000000000000000000004E +:10D2E000000000000000000000000000000000003E +:10D2F000000000000000000000000000000000002E +:10D30000000000000000000000000000000000001D +:10D31000000000000000000000000000000000000D +:10D3200000000000000000000808080808080808BD +:10D330000808080808080808070707070707070874 +:10D34000070707070707070807070707070707086B +:10D35000070707070707070807070707070707085B +:10D360000707070707070708080808080808080844 +:10D370000808080808080808070707080707070734 +:10D38000070707080707070707070708070707072B +:10D39000070707080707070707070708070707071B +:10D3A0000707070807070707080808080808080804 +:10D3B00008080808080808080707070707070708F4 +:10D3C00007070707070707080707070707070708EB +:10D3D00007070707070707080707070707070708DB +:10D3E00007070707070707080808080808080808C4 +:10D3F00008080808080808080707070807070707B4 +:10D4000007070708070707070707070807070707AA +:10D41000070707080707070707070708070707079A +:10D420000707070807070707080808080808080883 +:10D43000080808080808080808030303080303038A +:10D440000803030308030308080303030803030393 +:10D450000803030308030308080303030803030383 +:10D460000803030308030308080303030803030373 +:10D470000803030308030308080303030803030363 +:10D480000803030308030308080303030803030353 +:10D490000803030308030308080303030803030B3B +:10D4A0000B03030308030308080303030803030B28 +:10D4B0000B03030308030308080303030803030320 +:10D4C0000803030308030308080303030803030313 +:10D4D0000803030308030308080303030803030303 +:10D4E00008030303080303080803030308030303F3 +:10D4F00008030303080303080803030308030303E3 +:10D5000008030303080303080803030308030303D2 +:10D5100008030303080303080808080808080808A4 +:10D5200008080808080808080E0E0E0E0E0E0E0E4B +:10D530000E0E0E0E0E0E0E0E06060606060606064B +:10D54000060606060606060608080808080808086B +:10D55000080808080808080800000000000000008B +:10D5600000000000000000000E0E0E0E0E0E0E0E4B +:10D570000E0E0E0E0E0E0E0E06060606060606060B +:10D58000060606060606060608080808080808082B +:10D59000080808080808080800000000000000004B +:10D5A00000000000000000000E0E0E0E0E0E0E0E0B +:10D5B0000E0E0E0E0E0E0E0E0606060606060606CB +:10D5C00006060606060606060808080808080808EB +:10D5D000080808080808080800000000000000000B +:10D5E00000000000000000000E0E0E0E0E0E0E0ECB +:10D5F0000E0E0E0E0E0E0E0E06060606060606068B +:10D6000006060606060606060808080808080808AA +:10D6100008080808080808080000000000000000CA +:10D620000000000000000000000003333330000061 +:10D630000000333333330000000039999993000020 +:10D6400000003909909300000000099999900000AA +:10D650000000000990000000000CCCCCCCCCC00035 +:10D6600000CCCCCCCCCCCC00009CCCCCCCCCC9005D +:10D67000009CCCCCCCCCC9000000CCCCCCCC0000E5 +:10D6800000004444444400000000444004440000BE +:10D690000000444004440000000077700777000059 +:10D6A00000000000000000000000033333300000E1 +:10D6B00000003333333300000000399999930000A0 +:10D6C000000039099093000000000999999000002A +:10D6D0000000000990000000000CCCCCCCCCC000B5 +:10D6E00000CCCCCCCCCCCC00009CCCCCCCCCC900DD +:10D6F000009CCCCCCCCCC9000000CCCCCCCC000065 +:10D700000000444444440000000004400440000081 +:10D710000000044004400000000007700770000093 +:10D720000000000000000000000003333330000060 +:10D730000000333333330000000033333333000051 +:10D740000000333333330000000003333330000074 +:10D750000000000990000000000CCCCCCCCCC00034 +:10D7600000CCCCCCCCCCCC00009CCCCCCCCCC9005C +:10D77000009CCCCCCCCCC9000000CCCCCCCC0000E4 +:10D7800000004444444400000000444004440000BD +:10D790000000444004440000000077700777000058 +:10D7A00000000000000000000000033333300000E0 +:10D7B00000003333333300000000333333330000D1 +:10D7C00000003333333300000000033333300000F4 +:10D7D0000000000990000000000CCCCCCCCCC000B4 +:10D7E00000CCCCCCCCCCCC00009CCCCCCCCCC900DC +:10D7F000009CCCCCCCCCC9000000CCCCCCCC000064 +:10D800000000444444440000000004400440000080 +:10D810000000044004400000000007700770000092 +:10D82000000000000000000000000333333000005F +:10D830000000333333330000000033339999000084 +:10D8400000003339909900000000033999990000D5 +:10D85000000000099900000000000CCCCCC00000C2 +:10D860000000CCCCCCCC00000000CCCCC99900008E +:10D870000000CCCCCC00000000000CCCCC000000A0 +:10D880000000044444400000000004400440000044 +:10D890000000444000440000000077700077000062 +:10D8A00000000000000000000000033333300000DF +:10D8B0000000333333330000000033339999000004 +:10D8C0000000333990990000000003399999000055 +:10D8D000000000099900000000000CCCCCC0000042 +:10D8E0000000CCCCCCCC00000000CCCCC99900000E +:10D8F0000000CCCCCC00000000000CCCCC00000020 +:10D9000000000444444000000000004444000000C3 +:10D910000000004444000000000000777700000091 +:10D920000000000000000000000007777770000092 +:10D9300000007777777700000000799999970000C9 +:10D940000000790990970000000009999990000063 +:10D950000000000990000000000222222222200084 +:10D9600000222222222222000092222222222900A8 +:10D9700000922222222229000000222222220000DC +:10D9800000008888888800000000888008880000DF +:10D990000000888008880000000033300333000056 +:10D9A0000000000000000000000007777770000012 +:10D9B0000000777777770000000079999997000049 +:10D9C00000007909909700000000099999900000E3 +:10D9D0000000000990000000000222222222200004 +:10D9E0000022222222222200009222222222290028 +:10D9F000009222222222290000002222222200005C +:10DA000000008888888800000000088008800000E6 +:10DA10000000088008800000000003300330000090 +:10DA20000000000000000000000007777770000091 +:10DA3000000077777777000000007777777700002E +:10DA40000000777777770000000007777770000095 +:10DA50000000000990000000000222222222200083 +:10DA600000222222222222000092222222222900A7 +:10DA700000922222222229000000222222220000DB +:10DA800000008888888800000000888008880000DE +:10DA90000000888008880000000033300333000055 +:10DAA0000000000000000000000007777770000011 +:10DAB00000007777777700000000777777770000AE +:10DAC0000000777777770000000007777770000015 +:10DAD0000000000990000000000222222222200003 +:10DAE0000022222222222200009222222222290027 +:10DAF000009222222222290000002222222200005B +:10DB000000008888888800000000088008800000E5 +:10DB1000000008800880000000000330033000008F +:10DB20000000000000000000000007777770000090 +:10DB300000007777777700000000777799990000E9 +:10DB4000000077799099000000000779999900000A +:10DB500000000009990000000000022222200000BD +:10DB60000000222222220000000022222999000027 +:10DB700000002222220000000000022222000000F9 +:10DB800000000888888000000000088008800000ED +:10DB9000000088800088000000003330003300005F +:10DBA0000000000000000000000007777770000010 +:10DBB0000000777777770000000077779999000069 +:10DBC000000077799099000000000779999900008A +:10DBD000000000099900000000000222222000003D +:10DBE00000002222222200000000222229990000A7 +:10DBF0000000222222000000000002222200000079 +:10DC0000000008888880000000000088880000006C +:10DC1000000000888800000000000033330000008E +:10DC200000000000000000000000000000000000F4 +:10DC300000000000000000000000000000000000E4 +:10DC400000000000000000000000000000000000D4 +:10DC50000000000000000000000000BBBB0000004E +:10DC6000000000BBBB000000000000BBBB000000C8 +:10DC7000000000BBBB00000000000000000000002E +:10DC80000000000000000000000000000000000094 +:10DC90000000000000000000000000000000000084 +:10DCA0000000000000000000000000000000000074 +:10DCB0000000000000000000000000000000000064 +:10DCC0000000000000000000000000000000000054 +:10DCD0000000000000000000000000999900000012 +:10DCE00000000099990000000000009999000000D0 +:10DCF00000000099990000000000000000000000F2 +:10DD00000000000000000000000000000000000013 +:10DD10000000000000000000000000000000000003 +:10DD200000000000000000000000000000000000F3 +:10DD300000000000000000000000000000000000E3 +:10DD4000000BBB000000000000B000B000000000AD +:10DD500000B000BBBBBBBBB000B000B0000B0B0001 +:10DD6000000BBB00000B0B000000000000000000D7 +:10DD700000000000000000000000000000000000A3 +:10DD80000000000000000000000000000000000093 +:10DD90000000000000000000000000000000000083 +:10DDA0000000000000000000000000000000000073 +:10DDB0000000000000000000000000000000000063 +:10DDC0000003333333333000003333333333330022 +:10DDD000003BBBBBBBBBB3000033333BB3333300AF +:10DDE0000033333BB3333300003333333333330047 +:10DDF0000033333333333300003BBBBBBBBBB30017 +:10DE000000333333333333000000000000000000E0 +:10DE10000000000000000000000000000000000002 +:10DE200000000000000000000000000000000000F2 +:10DE300000000000000000000000000000000000E2 +:10DE4000002222222222220000288888888882003C +:10DE50000028BB8BB8BB82000028BB8BB8BB8200FC +:10DE60000028BB8BB8BB8200002888888888820085 +:10DE700000222222222222000000000000000000D6 +:10DE80000000000000000000000000000000000092 +:10DE90000000000000000000000000000000000082 +:10DEA0000000000000000000000000000000000072 +:10DEB0000000000000000000000000000000000062 +:10DEC000000B000BB000B000000BB0BBBB0BB000F0 +:10DED000000BBBBBBBBBB000000BB9BBBB9BB00016 +:10DEE000000BBBBCCBBBB000000BBBBBBBBBB000D3 +:10DEF0000000000000000000000BBBBBBBBBB0007B +:10DF00000000000000000000000000000000000011 +:10DF10000000000000000000000000000000000001 +:10DF200000000000000000000000000000000000F1 +:10DF3000000F00000000F0000000F00BB00F000028 +:10DF400000000F0BB0F00000000000BFFB0000005D +:10DF50000BBB0BFFFFB0BBB0000000BFFB0000001D +:10DF600000000F0BB0F000000000F00BB00F00003D +:10DF7000000F00000000F0000000000000000000A2 +:10DF80000000000000000000000000000000000091 +:10DF90000000000000000000000000000000000081 +:08DFA000000000000000000079 +:040000030000A20057 +:00000001FF diff --git a/games/keep/test-keep.py b/games/keep/test-keep.py new file mode 100644 index 0000000..0517fa1 --- /dev/null +++ b/games/keep/test-keep.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python3 +"""Run The Iron Keep in tools/rv32emu.py on a model of the board's game ports +(graphics, sprites, frame counter, held keys, terminal) and take screenshots. + + python3 test-keep.py [--shots DIR] [--fuzz FRAMES] + +The scripted run starts a game, walks east into the next room, fires, and +checks what the status line says; --fuzz then plays random keys for a while +and checks the program never leaves its code or wrecks the stack. Screenshots +need pyte and Pillow (text is drawn with the board's font). +""" +import argparse +import os +import random +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "tools")) +from boardemu import Board, load_ihx, load_font, load_syms # noqa: E402 + +UP, DOWN, LEFT, RIGHT, FIRE, ENTER, ESC = 1, 2, 4, 8, 16, 32, 128 + + +def play_through(b, a, check, font): + """Walk the castle by breadth-first search over gen.py's map: both keys + nearest the throne room, the crown behind its locked door, then the + stairs. The bot can't be seen or hurt (it keeps inv set), so this tests + the castle and the game's rules, not the bot's skill.""" + sys.path.insert(0, HERE) + import gen + from collections import deque + sym = {"_" + n: a for n, a in load_syms(os.path.join(HERE, "out", "keep.sym")).items()} + big = gen.BIG + W, H = len(big[0]), len(big) + where = {ch: [(x, y) for y in range(H) for x in range(W) if big[y][x] == ch] for ch in "KCX"} + def room_of(p): return (p[1] // 14) * 4 + p[0] // 20 + keys = sorted(where["K"], key=lambda p: room_of(p) not in (1, 7))[:2] + targets = keys + where["C"] + where["X"][:1] + names = ["key", "key", "crown", "stairs"] + + def i16(addr): + v = b.m[addr] | b.m[addr + 1] << 8 + return v - 65536 if v & 0x8000 else v + + def path(s, g): + prev = {s: None} + q = deque([s]) + while q: + p = q.popleft() + if p == g: + break + for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): + n = (p[0] + dx, p[1] + dy) + if 0 <= n[0] < W and 0 <= n[1] < H and n not in prev and big[n[1]][n[0]] != "#": + prev[n] = p; q.append(n) + out = [g] + while prev[out[-1]] is not None: + out.append(prev[out[-1]]) + return out[::-1] + + t = 0 + joy = 0 + for frame in range(30000): + b.m[sym["_inv"]] = 2 + if b.m[sym["_over"]]: + break + px, py, room = i16(sym["_px"]), i16(sym["_py"]), b.m[sym["_room"]] + if px % 16 == 0 and (py - 16) % 16 == 0: + here = ((room % 4) * 20 + px // 16, (room // 4) * 14 + (py - 16) // 16) + while t < len(targets) and here == targets[t]: + print("bot reached the %s at frame %d" % (names[t], frame)) + t += 1 + if t == len(targets): + joy = 0 + else: + p = path(here, targets[t]) + n = p[1] + joy = RIGHT if n[0] > here[0] else LEFT if n[0] < here[0] else DOWN if n[1] > here[1] else UP + elif joy == 0: # between tiles: line up with one + joy = LEFT if px % 16 else UP + if frame % 2000 == 0: + print("frame %d: room %d at %d,%d, heading for the %s" % (frame, room, px, py, names[min(t, 3)])) + b.run_frames(1, joy) + check("bot collected %d keys and the crown" % b.m[sym["_keys"]], b.m[sym["_crown"]] == 1) + check("taking the crown down the stairs wins", b.m[sym["_over"]] == 1 and b.m[sym["_won"]] == 1) + b.run_frames(80) + check("end screen", "YOU ESCAPED WITH THE CROWN" in "\n".join(b.screen_text().display)) + if a.shots: b.shot(os.path.join(a.shots, "5-escaped.png"), font) + b.run_frames(10, ESC) + b.run_frames(5) + check("Esc returns to BASIC", b.pc == 0) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--shots", help="write PNG screenshots here") + ap.add_argument("--fuzz", type=int, default=0, help="random frames to play") + ap.add_argument("--play", action="store_true", + help="then let a bot play the game through: keys, door, crown, stairs") + a = ap.parse_args() + mem, hi = load_ihx(os.path.join(HERE, "keep.ihx")) + b = Board(mem, code_end=hi) + font = None + if a.shots: + os.makedirs(a.shots, exist_ok=True) + font = load_font() + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def status(): + return "\n".join(b.screen_text().display[:2]) + + b.run_frames(20) + check("title screen", "T H E I R O N K E E P" in "\n".join(b.screen_text().display)) + if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font) + b.run_frames(5, FIRE) + b.run_frames(10) + check("game starts in the gatehouse", "GATEHOUSE" in status() and "LIVES 3" in status()) + check("player sprite shown", b.spr[0][3] & 1 == 1) + if a.shots: b.shot(os.path.join(a.shots, "2-gatehouse.png"), font) + # east along the top, down to the east doorway's rows, then through it + x0, y0 = b.spr[0][0], b.spr[0][1] + b.run_frames(30, DOWN) + check("moving down moves the player", b.spr[0][1] == (y0 + 60) & 255) + b.run_frames(30, UP) + b.run_frames(8, FIRE) + check("a shot uses ammunition", "AMMO 9" in status()) + b.run_frames(130, RIGHT) + check("walls stop the player", b.spr[0][0] == 290) + b.run_frames(32, DOWN) + b.run_frames(30, RIGHT) + check("east doorway leads to the guard room", "GUARD ROOM" in status()) + if a.shots: b.shot(os.path.join(a.shots, "3-guardroom.png"), font) + b.run_frames(60) + print(status()) + if a.play: + play_through(b, a, check, font) + if a.fuzz: + rnd = random.Random(1) + j = 0 + for f in range(a.fuzz): + if f % 10 == 0: + j = rnd.choice([UP, DOWN, LEFT, RIGHT, UP | FIRE, DOWN | FIRE, LEFT | FIRE, + RIGHT | FIRE, FIRE, 0, UP | LEFT, DOWN | RIGHT]) + b.run_frames(1, j) + if b.pc == 0: + break + if f % 500 == 499: + print("frame", f + 1, "-", b.screen_text().display[0].strip()) + check("random play for %d frames without a crash" % a.fuzz, True) + if a.shots: b.shot(os.path.join(a.shots, "4-fuzz.png"), font) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/games/raid/gen.py b/games/raid/gen.py new file mode 100644 index 0000000..c695573 --- /dev/null +++ b/games/raid/gen.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python3 +"""Make data.h for raid.c: the sprite shapes (drawn here from polygons and +ellipses, in the isometric directions the game uses) and the level. + +The world is a 2:1 isometric grid of tiles 32 pixels wide and 16 high. The +ship flies along the rows, towards the top right of the screen; a level is a +list of rows, numbered from where it starts. Each row is space or fortress +floor, and a fortress row can end in a wall across the flight path: a low wall +to fly over, or a tall one with a doorway to fly through. Ground objects stand +on tiles: turrets that fire at you, fuel tanks to shoot for fuel, radar dishes +for points, and the reactor core at the end of the level. +""" +import math +import random +import sys + +# ------------------------------------------------------------- drawing +def blank(): + return [[0] * 16 for _ in range(16)] + + +def poly(img, pts, c): + """Fill a polygon given in pixel coordinates (centres at +0.5).""" + n = len(pts) + for y in range(16): + for x in range(16): + px, py = x + 0.5, y + 0.5 + inside = False + for k in range(n): + (x1, y1), (x2, y2) = pts[k], pts[(k + 1) % n] + if (y1 > py) != (y2 > py): + if px < x1 + (py - y1) * (x2 - x1) / (y2 - y1): + inside = not inside + if inside: + img[y][x] = c + + +def ellipse(img, cx, cy, rx, ry, c): + for y in range(16): + for x in range(16): + if ((x + 0.5 - cx) / rx) ** 2 + ((y + 0.5 - cy) / ry) ** 2 <= 1: + img[y][x] = c + + +def rect(img, x0, y0, x1, y1, c): + for y in range(y0, y1): + for x in range(x0, x1): + img[y][x] = c + + +# the flight direction on screen (2, -1), and across the flight path, which in +# the 2:1 isometric view is (2, 1) - the direction the tiles' other edges run +F = (2 / math.sqrt(5), -1 / math.sqrt(5)) +G = (2 / math.sqrt(5), 1 / math.sqrt(5)) + + +def iso(pts, cx=8, cy=8, fwd=F): + """Points given as (along, across) in the flight frame -> pixels.""" + side = G + return [(cx + a * fwd[0] + b * side[0], cy + a * fwd[1] + b * side[1]) for a, b in pts] + + +def ship(body, wing, canopy, fwd=F): + img = blank() + poly(img, iso([(-2, -7.5), (1.5, -1.2), (1.5, 1.2), (-2, 7.5), (-4, 6.5), (-3, 0), (-4, -6.5)], fwd=fwd), wing) + poly(img, iso([(7.5, 0), (2, -2.2), (-6.5, -1.8), (-6.5, 1.8), (2, 2.2)], fwd=fwd), body) + poly(img, iso([(-6.5, -3.5), (-4, -0.5), (-4, 0.5), (-6.5, 3.5), (-7.5, 3), (-7.5, -3)], fwd=fwd), wing) + ellipse(img, *iso([(2.5, 0)], fwd=fwd)[0], 1.6, 1.3, canopy) + return img + + +SHIP = ship(15, 12, 6) +SHADOW = [[4 if c else 0 for c in row] for row in ship(1, 1, 1)] +FIGHTER = ship(13, 1, 11, fwd=(-F[0], -F[1])) + +TURRET = blank() +ellipse(TURRET, 8, 11.5, 6.5, 3.5, 8) +ellipse(TURRET, 8, 9.5, 5, 3.5, 2) +ellipse(TURRET, 7, 8.5, 2, 1.3, 10) +poly(TURRET, [(6.5, 10), (8.5, 11), (3.5, 14.5), (2, 13.5)], 7) + +TANK = blank() +rect(TANK, 3, 4, 13, 12, 9) +ellipse(TANK, 8, 12, 5, 2.5, 1) +rect(TANK, 3, 4, 13, 12, 9) +ellipse(TANK, 8, 4, 5, 2.5, 11) +for y in range(6, 11): + TANK[y][5] = 15 +rect(TANK, 7, 6, 9, 11, 1) +rect(TANK, 7, 6, 11, 7, 1) +rect(TANK, 7, 8, 10, 9, 1) + +RADAR = blank() +rect(RADAR, 7, 7, 9, 14, 7) +ellipse(RADAR, 8, 14, 4, 1.6, 8) +poly(RADAR, [(2, 2), (13, 5), (12, 8), (3, 6)], 14) +poly(RADAR, [(4, 3.5), (11, 5.5), (10.5, 6.8), (4.5, 5)], 6) + +CORE = blank() +poly(CORE, [(8, 0.5), (15, 7), (8, 14.5), (1, 7)], 5) +poly(CORE, [(8, 3), (12.5, 7), (8, 11.5), (3.5, 7)], 13) +ellipse(CORE, 8, 7, 2.2, 2.2, 15) + +def burst(seed, cols): + r = random.Random(seed) + img = blank() + for k in range(70): + a = r.uniform(0, 2 * math.pi) + d = r.uniform(0, 7) ** 0.9 + x, y = int(8 + d * math.cos(a)), int(8 + d * math.sin(a) * 0.8) + if 0 <= x < 16 and 0 <= y < 16: + img[y][x] = cols[0] if d < 2.5 else cols[1] if d < 5 else cols[2] + return img + + +BOOM1 = burst(3, (15, 11, 9)) +BOOM2 = burst(5, (11, 9, 1)) + +SHOT = blank() +ellipse(SHOT, 8, 8, 1.6, 1.2, 15) +SHOT[8][8] = 11 +SHELL = blank() +ellipse(SHELL, 8, 8, 1.8, 1.8, 9) +SHELL[8][8] = 15 + +SHAPES = [("S_SHIP", SHIP), ("S_SHADOW", SHADOW), ("S_FIGHTER", FIGHTER), ("S_TURRET", TURRET), + ("S_TANK", TANK), ("S_RADAR", RADAR), ("S_CORE", CORE), ("S_BOOM1", BOOM1), + ("S_BOOM2", BOOM2), ("S_SHOT", SHOT), ("S_SHELL", SHELL)] + +# --------------------------------------------------------------- level +BW = 10 # fortress width in tiles +LOW_H, TALL_H, DOOR_H = 20, 56, 30 +# row byte: bit 0 fortress floor; bits 2:1 wall at the far edge of the row +# (0 none, 1 low, 2 tall with a door); bits 6:3 the door's first tile; +# bit 7 fighters attack (space) +FORT, WALL_LOW, WALL_DOOR, FIGHTERS = 1, 2, 4, 128 +O_TURRET, O_TANK, O_RADAR, O_CORE = 1, 2, 3, 4 + + +def level(): + rnd = random.Random(1983) + rows = [] + objs = [] + def space(n, fighters): + rows.extend([FIGHTERS if fighters else 0] * n) + + def fortress(n, walls, turrets, tanks, radars, core=False): + start = len(rows) + rows.extend([FORT] * n) + wall_rows = [] + r = start + 10 + k = 0 + while r < start + n - 6 and k < len(walls): + if walls[k] == "L": + rows[r] |= WALL_LOW + else: + rows[r] |= WALL_DOOR | (rnd.randrange(0, BW - 1) << 3) + wall_rows.append(r) + r += rnd.randrange(9, 14) + k += 1 + # objects: not on the rows just behind a wall, where its face hides them + hidden = {w + d for w in wall_rows for d in range(0, 4)} + free = [(rr, i) for rr in range(start + 4, start + n - 3) for i in range(1, BW - 1) + if rr not in hidden] + rnd.shuffle(free) + used = set() + def place(t, count): + nonlocal free + for _ in range(count): + while free: + rr, i = free.pop() + if all(abs(rr - a) > 1 or abs(i - b) > 1 for a, b in used): + used.add((rr, i)); objs.append((rr, t, i)); break + place(O_TURRET, turrets) + place(O_TANK, tanks) + place(O_RADAR, radars) + if core: + objs.append((start + n - 3, O_CORE, BW // 2)) + space(14, False) + fortress(120, "LDLDDLDD", 10, 7, 3) + space(60, True) + fortress(140, "DLDDLDDLD", 13, 7, 3, core=True) + space(16, False) + objs.sort() + return rows, objs + + +def main(out): + rows, objs = level() + L = ["/* made by gen.py - edit that instead */", ""] + for i, (n, _) in enumerate(SHAPES): + L.append("#define %s %d" % (n, i)) + L.append("#define N_SHAPES %d" % len(SHAPES)) + L.append("#define BW %d" % BW) + L.append("#define LOW_H %d\n#define TALL_H %d\n#define DOOR_H %d" % (LOW_H, TALL_H, DOOR_H)) + L.append("#define R_FORT 1\n#define R_WALL 6\n#define R_LOW 2\n#define R_DOOR 4\n#define R_FIGHTERS 128") + L.append("#define O_TURRET %d\n#define O_TANK %d\n#define O_RADAR %d\n#define O_CORE %d" % + (O_TURRET, O_TANK, O_RADAR, O_CORE)) + L.append("static const u8 shape_data[N_SHAPES * 128] = {") + for n, img in SHAPES: + b = [img[y][x] << 4 | img[y][x + 1] for y in range(16) for x in range(0, 16, 2)] + L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % n) + L.append("};") + L.append("#define LEVEL_ROWS %d" % len(rows)) + L.append("static const u8 level_rows[LEVEL_ROWS] = {") + for k in range(0, len(rows), 20): + L.append(" " + ",".join(str(v) for v in rows[k:k + 20]) + ",") + L.append("};") + L.append("#define N_OBJS %d" % len(objs)) + L.append("/* row (2 bytes), type, tile across */") + L.append("static const u8 level_objs[N_OBJS * 4] = {") + for r, t, i in objs: + L.append(" %d,%d,%d,%d," % (r & 255, r >> 8, t, i)) + L.append("};") + open(out, "w").write("\n".join(L) + "\n") + walls = sum(1 for r in rows if r & 6) + print("data.h: %d shapes, %d rows, %d walls, %d objects" % (len(SHAPES), len(rows), walls, len(objs))) + + +if __name__ == "__main__": + if len(sys.argv) > 2 and sys.argv[2] == "--show": + for n, img in SHAPES: + print(n) + for row in img: + print("".join(" .:-=+*#%@ABCDEF"[c] if c else " " for c in row)) + main(sys.argv[1] if len(sys.argv) > 1 else "data.h") diff --git a/games/raid/raid.bas b/games/raid/raid.bas new file mode 100644 index 0000000..64a619d --- /dev/null +++ b/games/raid/raid.bas @@ -0,0 +1,4 @@ +10 REM BASTION RAID: LOAD THE GAME (MEMORY FILE RAIDGAME) AND PLAY IT +20 REM THE GAME RUNS AT A200H, PAST THIS PROGRAM, AND COMES BACK HERE +30 BLOAD "RAIDGAME": CALL 41472 +40 CLS diff --git a/games/raid/raid.c b/games/raid/raid.c new file mode 100644 index 0000000..6ff66ef --- /dev/null +++ b/games/raid/raid.c @@ -0,0 +1,696 @@ +/* Bastion Raid: an isometric scrolling shooter for the Basys 3 RISC-V computer. + + Fly over a fortress that scrolls diagonally towards you. Climb over low + walls, fly low through the doorways in tall ones, shoot turrets before they + shoot you, and shoot fuel tanks to fill up. Between fortresses, fighters + come at you through space. The reactor core waits at the far end. Your + shadow on the floor and the altimeter show how high you are. + + The world is drawn into the graphics layer, which the hardware scrolls + (ports 35h-37h): each frame the picture moves two pixels left and one + down, and only the two new columns and the new row are drawn, pixel by + pixel from the world's description (world()). Everything that moves is a + sprite. It runs at A200h, loaded by the RAID program in BASIC. + + World coordinates: a pixel (WX, WY) of the unscrolled world has + s = WX + 2 WY (across the flight path) and d = 2 WY - WX (along it, growing + towards the viewer). Tiles are 32 x 32 in (s, d): tile i = s >> 5, + j = d >> 5, and level row r = -j. The ship flies towards smaller d. */ + +typedef unsigned char u8; +typedef signed char i8; +typedef unsigned short u16; +typedef short i16; + +#include "basys3.h" + +#define con_stat IO8(0x00) +#define con_data IO8(0x01) +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) +#define gfill IO8(0x34) +#define scr_xlo IO8(0x35) +#define scr_xhi IO8(0x36) +#define scr_y IO8(0x37) +#define sp_sel IO8(0x70) +#define sp_xlo IO8(0x71) +#define sp_xhi IO8(0x72) +#define sp_y IO8(0x73) +#define sp_shape IO8(0x74) +#define sp_ctl IO8(0x75) +#define sp_load IO8(0x76) +#define sp_data IO8(0x77) +#define frame_ctr IO8(0x78) +#define joy IO8(0x88) + +#include "data.h" /* out/data.h, made by gen.py */ + +#define J_UP 1 +#define J_DOWN 2 +#define J_LEFT 4 +#define J_RIGHT 8 +#define J_FIRE 16 +#define J_ENTER 32 +#define J_ESC 128 + +/* sprites: lower numbers in front */ +#define SP_SHIP 0 +#define SP_SHOT 1 /* 3 */ +#define SP_FIGHT 4 /* 4 */ +#define SP_SHELL 8 /* 4 */ +#define SP_BOOM 12 /* 3 */ +#define SP_OBJ 15 /* 12 */ +#define SP_SHADOW 27 + +#define NSHOT 3 +#define NFIGHT 4 +#define NSHELL 4 +#define NBOOM 3 +#define NOBJ 12 + +#define SHIP_D 128 /* the ship's ground point is 4 tiles nearer than the screen centre */ +#define MAX_ALT 48 +#define BACK_H 24 /* the fortress's back wall */ +#define FRONT_H 20 /* and its front face, below the floor */ + +/* ---------------------------------------------------------------- state */ +static i16 cx, cy; /* world pixel at the screen's top left */ +static u16 fbx; /* the same, in the 320 x 240 buffer */ +static u8 fby; +i16 cam_d; /* d at the screen's centre */ + +i16 ship_s, ship_d; +u8 alt, lives, fuel, level, inv, dead; +u8 shield; /* tests only: shells, fighters and objects can't hit */ +static u8 fuel_tick, fire_held, dead_time; +static u16 score; + +static i16 shot_s[NSHOT], shot_d[NSHOT]; +static u8 shot_alt[NSHOT], shot_life[NSHOT]; +static i16 fight_s[NFIGHT], fight_d[NFIGHT]; +static u8 fight_alt[NFIGHT], fight_on[NFIGHT]; +static i16 shell_s[NSHELL], shell_d[NSHELL]; +static u8 shell_life[NSHELL]; +static i16 boom_s[NBOOM], boom_d[NBOOM]; +static u8 boom_alt[NBOOM], boom_t[NBOOM]; +static i16 obj_s[NOBJ], obj_d[NOBJ]; +static u8 obj_type[NOBJ], obj_on[NOBJ], obj_cool[NOBJ], obj_hits[NOBJ]; +static u16 next_obj; +static u8 fight_timer; + +static u8 last_frame, quit, hud_dirty; +static u8 shown_fuel, shown_alt; +static u16 rnd_state; +static const char *msg; +static u8 msg_time; + +/* ----------------------------------------------------------------- text */ +static void putch(char c) { while (!(con_stat & 2)); con_data = c; } +static void puts_(const char *s) { while (*s) putch(*s++); } +static void putn(u16 n, u8 width) +{ + char b[6]; + u8 i = 0; + do { b[i++] = '0' + n % 10; n /= 10; } while (n); + while (width > i) { putch('0'); width--; } + while (i) putch(b[--i]); +} +static void at(u8 r, u8 c) { putch(27); putch('['); putn(r, 0); putch(';'); putn(c, 0); putch('H'); } +static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); } +static void centre(u8 r, const char *s) +{ + u8 n = 0; + while (s[n]) n++; + at(r, 41 - n / 2); + puts_(s); +} + +static u16 rnd(void) +{ + rnd_state ^= rnd_state << 7; + rnd_state ^= rnd_state >> 9; + rnd_state ^= rnd_state << 8; + return rnd_state; +} + +static void wait_frame(void) +{ + while (frame_ctr == last_frame); + last_frame = frame_ctr; +} + +static u8 drain_keys(void) +{ + u8 c, p = 0; + while (con_stat & 1) { + c = con_data; + if (c == 'p' || c == 'P') p = 1; + } + return p; +} + +/* ---------------------------------------------------------------- world */ +static u8 row_info(i16 r) +{ + return (r >= 0 && r < LEVEL_ROWS) ? level_rows[r] : 0; +} + +/* The colour of world point (s, d). */ +static u8 world(i16 s, i16 d) +{ + i16 jw, jlo, k2, sb, db; + u8 ri, k, ib, g, h; + + /* walls across the path: the face of the wall at the far edge of row + -jw covers the 2H units of d in front of the line d = 32 jw. The + nearest wall is tried first. */ + jlo = (d >> 5) + 1; + for (jw = (d + 2 * TALL_H) >> 5; jw >= jlo; jw--) { + ri = row_info(-jw); + if (!(ri & R_WALL)) continue; + k2 = (jw << 5) - d; + h = (ri & R_DOOR) ? TALL_H : LOW_H; + k = (u8)(k2 >> 1); + if (k > h) continue; + sb = s + k2; + if (sb < 0 || sb >= 32 * BW) continue; + ib = (u8)(sb >> 5); + if (ri & R_DOOR) { + g = (ri >> 3) & 15; + if (ib >= g && ib < g + 2) { + if (k < DOOR_H) continue; /* the doorway */ + if (k < DOOR_H + 3) return 14; /* its lintel */ + } + } + if (k >= h - 1) return (ri & R_DOOR) ? 15 : 11; /* the top */ + if (!(k & 7) || ((sb + ((k & 8) << 1)) & 31) < 2) return 8; + return (ri & R_DOOR) ? 7 : 3; + } + + /* the fortress's back wall, rising from its far side (s = 0) */ + if (s < 0 && s >= -2 * BACK_H) { + db = d - s; + if (row_info(-(db >> 5)) & R_FORT) { + k = (u8)((-s) >> 1); + if (k >= BACK_H - 1) return 7; + return (k & 3) ? 8 : 0; + } + } + /* its front face, below the near side (s = 32 BW) */ + if (s >= 32 * BW && s < 32 * BW + 2 * FRONT_H) { + k2 = s - 32 * BW; + db = d - k2; + if (row_info(-(db >> 5)) & R_FORT) + return ((db & 31) < 2) ? 0 : 4; + } + /* the floor */ + if (s >= 0 && s < 32 * BW && (row_info(-(d >> 5)) & R_FORT)) { + if ((s & 31) < 2 || (d & 31) < 2) return 0; + if ((((s >> 5) + (d >> 5)) & 3) == 0 && (s & 31) > 13 && (s & 31) < 18 && + (d & 31) > 13 && (d & 31) < 18) return 7; + return 8; + } + /* space */ + if (((s * 5 + d * 3) & 255) == 7 && !((s ^ d) & 0x60)) + return (s & 16) ? 15 : 7; + return 0; +} + +/* Draw screen columns xs and xs + 1 (xs even) from the world. */ +static void draw_cols(u16 xs) +{ + i16 wx = cx + xs, s = wx + 2 * cy, d = 2 * cy - wx; + u16 fx = fbx + xs; + u8 y, fy = fby, c0, c1, flo, fhi; + if (fx >= 320) fx -= 320; + flo = (u8)fx; fhi = (u8)(fx >> 8); + for (y = 0; y < 240; y++) { + c0 = world(s, d); + c1 = world(s + 1, d - 1); + gx_lo = flo; gx_hi = fhi; gy_p = fy; + gpix = c0; gpix = c1; + s += 2; d += 2; + if (++fy == 240) fy = 0; + } +} + +/* Draw screen row ys from the world. */ +static void draw_row(u8 ys) +{ + i16 wy = cy + ys, s = cx + 2 * wy, d = 2 * wy - cx; + u16 x, fx = fbx; + u8 fy = fby + ys; + if (fy >= 240) fy -= 240; + gx_lo = (u8)fx; gx_hi = (u8)(fx >> 8); gy_p = fy; + for (x = 0; x < 320; x++) { + gpix = world(s, d); + s++; d--; + if (++fx == 320) { fx = 0; gx_lo = 0; gx_hi = 0; gy_p = fy; } + } +} + +/* Show the camera's view. The border bit hides the screen's edges, where + advance() draws the next columns and row while this frame is on screen. */ +static void set_scroll(void) +{ + scr_xlo = (u8)fbx; scr_xhi = (u8)(fbx >> 8) | 2; scr_y = fby; +} + +/* Put the camera at level row r (the screen centre), and draw it all. */ +static void camera_at(i16 r) +{ + u8 y; + /* centre: s = 16 BW (the fortress's middle), d = -32 r + 16 */ + i16 sc = 16 * BW, dc = -32 * r + 16; + /* WX = (s - d) / 2, WY = (s + d) / 4, both even-friendly */ + cx = ((sc - dc) >> 1) - 160; + cy = ((sc + dc) >> 2) - 120; + cx &= ~1; + cam_d = 2 * (cy + 120) - (cx + 160); + fbx = (u16)(cx % 320); if ((i16)fbx < 0) fbx += 320; + { i16 t = cy % 240; if (t < 0) t += 240; fby = (u8)t; } + for (y = 0; y < 240; y++) draw_row(y); +} + +/* Fly on: the camera moves 2 right and 1 up; draw what comes into view. */ +static void advance(void) +{ + cx += 2; cy -= 1; + cam_d -= 4; + fbx += 2; if (fbx >= 320) fbx -= 320; + fby = fby ? fby - 1 : 239; + draw_cols(318); + draw_row(0); +} + +/* ------------------------------------------------------------- sprites */ +static void spr_place(u8 n, i16 s, i16 d, u8 up, u8 shape, u8 ctl) +{ + i16 x = ((s - d) >> 1) - cx - 8, y = ((s + d) >> 2) - cy - 8 - up; + sp_sel = n; + if (x < -15 || x > 319 || y < -15 || y > 239) { sp_ctl = 0; return; } + sp_xlo = (u8)x; sp_xhi = (u8)(x >> 8) & 1; sp_y = (u8)y; + sp_shape = shape; sp_ctl = ctl; +} +static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; } +static void all_off(void) { u8 i; for (i = 0; i < 32; i++) spr_off(i); } + +static void load_shapes(void) +{ + const u8 *p = shape_data; + u8 s, i; + for (s = 0; s < N_SHAPES; s++) { + sp_load = s; + for (i = 0; i < 128; i++) sp_data = *p++; + } +} + +static i16 absd(i16 v) { return v < 0 ? -v : v; } + +static void boom(i16 s, i16 d, u8 up) +{ + u8 i, best = 0; + for (i = 0; i < NBOOM; i++) if (boom_t[i] < boom_t[best]) best = i; + boom_s[best] = s; boom_d[best] = d; boom_alt[best] = up; boom_t[best] = 24; +} + +static void say(const char *s) { msg = s; msg_time = 120; hud_dirty = 1; } + +/* ------------------------------------------------------------------ HUD */ +static void bar(u8 n, u8 of) +{ + u8 i; + putch('['); + for (i = 0; i < of; i++) putch(i < n ? '#' : '-'); + putch(']'); +} + +static void hud(void) +{ + hud_dirty = 0; + shown_fuel = fuel; shown_alt = alt / 6; + at(1, 1); ink("0;93"); puts_("BASTION RAID "); + ink("0;37"); puts_("SCORE "); ink("0;97"); putn(score, 6); + ink("0;37"); puts_(" LEVEL "); ink("0;97"); putn(level, 0); + ink("0;37"); puts_(" SHIPS "); ink("0;97"); putn(lives, 0); + puts_("\033[K"); + at(2, 1); ink(fuel < 25 ? "0;91" : "0;37"); puts_("FUEL "); bar((fuel + 9) / 10, 10); + ink("0;37"); puts_(" ALT "); ink("0;96"); bar(shown_alt + 1, 9); + if (msg && msg_time) { ink("0;93"); puts_(" "); puts_(msg); } + puts_("\033[K"); + ink("0"); +} + +/* ---------------------------------------------------------------- rules */ +/* Does the wall at the far edge of row r stop something at s, height a? */ +static u8 wall_stops(i16 r, i16 s, u8 a, u8 half) +{ + u8 ri = row_info(r), g; + if (!(ri & R_WALL) || s < -half || s >= 32 * BW + half) return 0; + if (ri & R_LOW) return a <= LOW_H + 2; + if (a > TALL_H) return 0; + g = (ri >> 3) & 15; + return !(s - half >= 32 * g && s + half < 32 * g + 64 && a + 8 < DOOR_H); +} + +static void crash(u8 wall) +{ + u8 i; + if (inv || dead || (shield && !wall)) return; + boom(ship_s, ship_d, alt); + spr_off(SP_SHIP); spr_off(SP_SHADOW); + dead = 1; dead_time = 90; + for (i = 0; i < NSHELL; i++) { shell_life[i] = 0; spr_off(SP_SHELL + i); } +} + +static void objects_in(void) +{ + const u8 *o; + i16 r, ahead = -((cam_d - 12 * 32) >> 5); + u8 k; + while (next_obj < N_OBJS) { + o = level_objs + next_obj * 4; + r = o[0] | o[1] << 8; + if (r > ahead) break; + for (k = 0; k < NOBJ && obj_on[k]; k++); + if (k == NOBJ) break; + obj_on[k] = 1; obj_type[k] = o[2]; + obj_s[k] = 32 * o[3] + 16; obj_d[k] = -32 * r + 16; + obj_cool[k] = 40 + (rnd() & 63); + obj_hits[k] = o[2] == O_CORE ? 4 : 1; + next_obj++; + } +} + +static void hit_object(u8 k) +{ + if (--obj_hits[k]) { boom(obj_s[k], obj_d[k], 4); return; } + obj_on[k] = 0; + spr_off(SP_OBJ + k); + boom(obj_s[k], obj_d[k], 0); + switch (obj_type[k]) { + case O_TURRET: score += 100; break; + case O_TANK: score += 150; fuel = fuel > 75 ? 100 : fuel + 25; say("FUEL"); break; + case O_RADAR: score += 300; break; + case O_CORE: score += 2000; say("REACTOR DESTROYED!"); break; + } + hud_dirty = 1; +} + +static void objects(void) +{ + static const u8 shapes[5] = { 0, S_TURRET, S_TANK, S_RADAR, S_CORE }; + u8 k, i; + for (k = 0; k < NOBJ; k++) { + if (!obj_on[k]) continue; + if (obj_d[k] > cam_d + 8 * 32) { obj_on[k] = 0; spr_off(SP_OBJ + k); continue; } + spr_place(SP_OBJ + k, obj_s[k], obj_d[k], 4, shapes[obj_type[k]], 1); + if (!dead && alt < 12 && absd(obj_s[k] - ship_s) < 16 && absd(obj_d[k] - ship_d) < 16) { + hit_object(k); crash(0); continue; + } + if (obj_type[k] == O_TURRET && !dead && obj_d[k] < ship_d && obj_d[k] > ship_d - 8 * 32) { + if (obj_cool[k]) obj_cool[k]--; + else { + for (i = 0; i < NSHELL && shell_life[i]; i++); + if (i < NSHELL) { + shell_s[i] = obj_s[k]; shell_d[i] = obj_d[k]; shell_life[i] = 70; + } + obj_cool[k] = (level > 3 ? 40 : 100 - 20 * level) + (rnd() & 63); + } + } + } +} + +static void shells(void) +{ + u8 i; + for (i = 0; i < NSHELL; i++) { + if (!shell_life[i]) continue; + shell_life[i]--; + shell_d[i] += 6; + if (shell_s[i] < ship_s) shell_s[i]++; else if (shell_s[i] > ship_s) shell_s[i]--; + /* moving towards the viewer, it crosses the far edge of row -(d >> 5) */ + if (!shell_life[i] || (((shell_d[i] - 6) >> 5) != (shell_d[i] >> 5) && + wall_stops(-(shell_d[i] >> 5), shell_s[i], 10, 2))) { + shell_life[i] = 0; spr_off(SP_SHELL + i); continue; + } + spr_place(SP_SHELL + i, shell_s[i], shell_d[i], 10, S_SHELL, 1); + if (!dead && absd(shell_s[i] - ship_s) < 12 && absd(shell_d[i] - ship_d) < 12 && alt < 22) { + shell_life[i] = 0; spr_off(SP_SHELL + i); + crash(0); + } + } +} + +static void fighters(void) +{ + u8 i, k; + if (!dead && (row_info(-(cam_d >> 5) + 4) & R_FIGHTERS) && !--fight_timer) { + fight_timer = (level > 3 ? 25 : 55 - 10 * level) + (rnd() & 31); + for (i = 0; i < NFIGHT && fight_on[i]; i++); + if (i < NFIGHT) { + fight_on[i] = 1; + fight_s[i] = 24 + (rnd() % (32 * BW - 48)); + fight_d[i] = cam_d - 7 * 32; + fight_alt[i] = 6 + (rnd() % 40); + } + } + for (i = 0; i < NFIGHT; i++) { + if (!fight_on[i]) continue; + fight_d[i] += 6; + if (!(last_frame & 3)) { + if (fight_alt[i] < alt) fight_alt[i]++; else if (fight_alt[i] > alt) fight_alt[i]--; + } + if (fight_d[i] > cam_d + 8 * 32) { fight_on[i] = 0; spr_off(SP_FIGHT + i); continue; } + spr_place(SP_FIGHT + i, fight_s[i], fight_d[i], fight_alt[i], S_FIGHTER, 1); + if (!dead && absd(fight_s[i] - ship_s) < 16 && absd(fight_d[i] - ship_d) < 16 && + absd(fight_alt[i] - alt) < 10) { + fight_on[i] = 0; spr_off(SP_FIGHT + i); + boom(fight_s[i], fight_d[i], fight_alt[i]); + crash(0); + } + for (k = 0; k < NSHOT; k++) + if (shot_life[k] && absd(shot_s[k] - fight_s[i]) < 16 && absd(shot_d[k] - fight_d[i]) < 20 && + absd(shot_alt[k] - fight_alt[i]) < 12) { + shot_life[k] = 0; spr_off(SP_SHOT + k); + fight_on[i] = 0; spr_off(SP_FIGHT + i); + boom(fight_s[i], fight_d[i], fight_alt[i]); + score += 200; hud_dirty = 1; + break; + } + } +} + +static void shots(u8 j) +{ + u8 i, k; + i16 od; + if (!(j & J_FIRE)) fire_held = 0; + else if (!fire_held && !dead) { + fire_held = 1; + for (i = 0; i < NSHOT && shot_life[i]; i++); + if (i < NSHOT) { + shot_s[i] = ship_s; shot_d[i] = ship_d - 12; shot_alt[i] = alt; shot_life[i] = 28; + } + } + for (i = 0; i < NSHOT; i++) { + if (!shot_life[i]) continue; + od = shot_d[i]; + shot_d[i] -= 12; + shot_life[i]--; + if ((od >> 5) != (shot_d[i] >> 5) && wall_stops(-(od >> 5), shot_s[i], shot_alt[i], 2)) { + shot_life[i] = 0; + boom(shot_s[i], (od >> 5) << 5, shot_alt[i]); + } + if (shot_alt[i] < 16) + for (k = 0; k < NOBJ && shot_life[i]; k++) + if (obj_on[k] && absd(obj_s[k] - shot_s[i]) < 16 && absd(obj_d[k] - shot_d[i]) < 16) { + shot_life[i] = 0; + hit_object(k); + } + if (!shot_life[i]) { spr_off(SP_SHOT + i); continue; } + spr_place(SP_SHOT + i, shot_s[i], shot_d[i], shot_alt[i], S_SHOT, 1); + } +} + +static void booms(void) +{ + u8 i; + for (i = 0; i < NBOOM; i++) { + if (!boom_t[i]) continue; + boom_t[i]--; + if (!boom_t[i]) { spr_off(SP_BOOM + i); continue; } + spr_place(SP_BOOM + i, boom_s[i], boom_d[i], boom_alt[i], (boom_t[i] & 4) ? S_BOOM1 : S_BOOM2, 1); + } +} + +static void fly(u8 j) +{ + i16 od = ship_d; + if (dead) return; + if (j & J_LEFT) ship_s -= 3; + if (j & J_RIGHT) ship_s += 3; + if (ship_s < 16) ship_s = 16; + if (ship_s > 32 * BW - 16) ship_s = 32 * BW - 16; + if ((j & J_UP) && alt < MAX_ALT) alt++; + if ((j & J_DOWN) && alt > 2) alt--; + ship_d = cam_d + SHIP_D; + if ((od >> 5) != (ship_d >> 5) && !inv && wall_stops(-(od >> 5), ship_s, alt, 10)) { + say("YOU HIT THE WALL"); + crash(1); + return; + } + if (++fuel_tick >= 24) { + fuel_tick = 0; + if (fuel) fuel--; + if (!fuel) { say("OUT OF FUEL"); crash(0); return; } + if (fuel != shown_fuel) hud_dirty = 1; + } + if (alt / 6 != shown_alt) hud_dirty = 1; + spr_place(SP_SHIP, ship_s, ship_d, alt, S_SHIP, (inv & 4) ? 0 : 1); + if ((row_info(-(ship_d >> 5)) & R_FORT) && ship_s >= 0 && ship_s < 32 * BW) + spr_place(SP_SHADOW, ship_s, ship_d, 0, S_SHADOW, 1); + else + spr_off(SP_SHADOW); +} + +/* ------------------------------------------------------------- screens */ +static void clear_all(void) +{ + gfill = 0; /* also sprites off, scroll to 0 */ + while (gfill & 1); + all_off(); +} + +static u8 wait_fire(void) +{ + u8 j; + while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); } + for (;;) { + wait_frame(); drain_keys(); rnd(); + j = joy; + if (j & J_ESC) return 0; + if (j & (J_FIRE | J_ENTER)) return 1; + } +} + +static u8 title(void) +{ + clear_all(); + puts_("\033[0m\033[2J"); + camera_at(12); + set_scroll(); + ship_s = 16 * BW; ship_d = cam_d + SHIP_D; alt = 24; + spr_place(SP_SHIP, ship_s, ship_d, alt, S_SHIP, 1); + ink("1;93"); centre(5, "B A S T I O N R A I D"); + ink("0;97"); + centre(8, "Fly over the fortress and destroy its reactor core."); + centre(10, "UP / DOWN climb and dive LEFT / RIGHT steer SPACE fire"); + centre(12, "Climb over low walls. Fly low through the doors in tall ones."); + centre(13, "Your shadow and the altimeter show your height."); + centre(14, "Shoot fuel tanks for fuel. Turrets and fighters shoot back."); + centre(16, "P pauses. ESC gives up."); + ink("1;96"); centre(28, "PRESS SPACE TO BEGIN"); + ink("0"); + return wait_fire(); +} + +static void reset_level(void) +{ + u8 i; + for (i = 0; i < NSHOT; i++) shot_life[i] = 0; + for (i = 0; i < NFIGHT; i++) fight_on[i] = 0; + for (i = 0; i < NSHELL; i++) shell_life[i] = 0; + for (i = 0; i < NBOOM; i++) boom_t[i] = 0; + for (i = 0; i < NOBJ; i++) obj_on[i] = 0; + next_obj = 0; + fight_timer = 30; + clear_all(); + camera_at(-6); + set_scroll(); + ship_s = 16 * BW; alt = 24; ship_d = cam_d + SHIP_D; + inv = 90; dead = 0; +} + +/* Play until the ships run out (or Esc); returns 1 to go on to the title. */ +static void play(void) +{ + u8 j, i; + lives = 3; score = 0; level = 1; + puts_("\033[2J"); + for (;;) { + fuel = 100; fuel_tick = 0; fire_held = 1; + reset_level(); + msg = 0; msg_time = 0; + say("LEVEL START"); + hud(); + for (;;) { + wait_frame(); + set_scroll(); + if (drain_keys()) { + at(2, 50); ink("0;93"); puts_("PAUSED - P TO GO ON\033[K"); ink("0"); + for (;;) { + wait_frame(); + if (joy & J_ESC) { quit = 1; return; } + if (drain_keys()) break; + } + hud_dirty = 1; + } + j = joy; + if (j & J_ESC) return; + fly(j); + objects_in(); + objects(); + shots(j); + shells(); + fighters(); + booms(); + if (inv) inv--; + if (msg_time && !--msg_time) hud_dirty = 1; + if (hud_dirty) hud(); + if (dead) { + if (!--dead_time) { + if (!--lives) { + hud(); + ink("0;44;97"); + centre(13, " "); + centre(14, " GAME OVER "); + centre(15, " "); + ink("0"); + for (i = 0; i < 120; i++) { wait_frame(); drain_keys(); } + return; + } + dead = 0; inv = 120; + if (fuel < 40) fuel = 40; + alt = 24; + hud_dirty = 1; + } + } + if (-(ship_d >> 5) >= LEVEL_ROWS) break; /* through the level */ + advance(); + } + score += 500; + level++; + say("LEVEL CLEARED"); + hud(); + for (i = 0; i < 90; i++) { wait_frame(); drain_keys(); } + } +} + +int main(void) +{ + rnd_state = 0xBEEF ^ frame_ctr; + last_frame = frame_ctr; + puts_("\033[?3l\033[?25l"); + load_shapes(); + quit = 0; + while (!quit) { + if (!title()) break; + play(); + } + clear_all(); + puts_("\033[0m\033[2J\033[H\033[?25h"); + while (con_stat & 1) (void)con_data; +} diff --git a/games/raid/raid.ihx b/games/raid/raid.ihx new file mode 100644 index 0000000..179b210 --- /dev/null +++ b/games/raid/raid.ihx @@ -0,0 +1,758 @@ +:10A20000973200009382C2F3173300001303C30197 +:10A2100063F8620023A00200938242006FF05FFFA8 +:10A2200017130000670003E0834700F093F727004F +:10A23000E38C07FEA300A0F067800000130101FF7C +:10A240002324810023261100130405000345040084 +:10A25000631A05008320C10003248100130101015A +:10A26000678000001304140097000000E78000FCE2 +:10A270006FF0DFFD130101FE232C8100232A9100E2 +:10A28000232E110093840500130400009306A00000 +:10A29000130690003377D5029307040093870701D4 +:10A2A000B3872700130414001374F40F1307070374 +:10A2B000238CE7FE930705003355D502E36CF6FCCB +:10A2C000636E9400631804028320C101032481019A +:10A2D000832441011301010267800000130500037C +:10A2E0009384F4FF97000000E78040F493F4F40FA8 +:10A2F0006FF01FFD1304F4FF1374F40F93070401B0 +:10A30000B387270003C587FF97000000E78000F2AE +:10A310006FF05FFB130101FF2322910093040500FE +:10A320001305B001232611002324810013840500A6 +:10A3300097000000E78080EF1305B005970000004C +:10A34000E780C0EE9305000013850400970000002D +:10A35000E78080F21305B00397000000E78000ED6E +:10A36000130504009305000097000000E780C0F08B +:10A37000032481008320C10083244100130580044D +:10A380001301010117030000670043EA130101FFF5 +:10A3900023248100130405001305B00123261100B6 +:10A3A00097000000E78080E81305B00597000000E3 +:10A3B000E780C0E71305040097000000E78040E84D +:10A3C000032481008320C1001305D006130101017D +:10A3D00017030000670083E5130101FF23248100B8 +:10A3E0002326110013840500930700003307F400AF +:10A3F00003470700631A070293D7170093059002DB +:10A40000B385F54093F5F50F97000000E780C0F0A5 +:10A4100013050400032481008320C10013010101FE +:10A42000170300006700C3E19387170093F7F70F46 +:10A430006FF0DFFBB7D7000003D547141317750083 +:10A440003345E50013150501135505011357950014 +:10A450003345E500131785003345E5001315050165 +:10A46000135505012392A71467800000B7D7000099 +:10A4700003C7A714834680F7E38EE6FE034780F701 +:10A480002385E7146780000013050000930600058C +:10A49000834700F093F7170063940700678000007C +:10A4A000034710F01377F70D6304D70093070500F7 +:10A4B000138507006FF0DFFDB7D7000003C7E72162 +:10A4C000A30AE0F283D7E72193D7870093E7270019 +:10A4D000230BF0F2B7D7000083C7C721A30BF0F21C +:10A4E00067800000B7D8000083D828223388C54091 +:10A4F000135818403308184113180801135808015D +:10A50000B7D80000839808222308A0F61305780026 +:10A5100013150501135505011303E014636EA3021F +:10A52000B385C500130680FF33061641B306D64037 +:10A5300093D52540B385D500139605019395050164 +:10A5400093D50541930610FF1356060163C6D50047 +:10A550009306F00E63D6B600A30A00F667800000EB +:10A56000930688FF93F5F60F93D68600A308B0F6FE +:10A5700093F616002309D0F69376F60FA309D0F6CA +:10A58000230AE0F6A30AF0F667800000B7D70000C0 +:10A590009386071B03C8160003C7071B9387071B77 +:10A5A0003337E800B308D70003C8260083C6080085 +:10A5B0006374D80013072000B7D6000013181700E3 +:10A5C0009386061CB38606012390A600B7D600002A +:10A5D0009386861BB38606012390B600B7D600008B +:10A5E0009386461BB306D700B387E70013078001A5 +:10A5F0002380C6002380E70067800000130101FF6D +:10A6000023202101130905001305B005232481002F +:10A6100023229100232611009384050013040000D7 +:10A6200097000000E78080C01305D0026374240106 +:10A6300013053002130414001374F40F9700000084 +:10A64000E780C0BEE39284FE032481008320C10022 +:10A6500083244100032901001305D00513010101E2 +:10A6600017030000670083BC130101FE23282101AA +:10A6700037D9000003473921B7D7000023840714D6 +:10A68000B7D70000A383E714B7D70000232C8100BD +:10A6900003C4572193076000930510003354F4025C +:10A6A00013051000B7D70000232E1100232A9100B4 +:10A6B000232631012324410137CA0000B7C400001A +:10A6C000B7C900002383871497000000E780C0C447 +:10A6D0001305CA6D97000000E78080CB37C50000E6 +:10A6E0001305456E97000000E78080B51385446D23 +:10A6F00097000000E780C0C937C500001305456F0B +:10A7000097000000E780C0B31385C96F9700000071 +:10A71000E78000C8B7D7000003D5A72093056000E5 +:10A7200097000000E78040B51385446D9700000056 +:10A73000E78000C637C5000013054570970000008C +:10A74000E78000B01385C96F97000000E78040C420 +:10A75000B7D7000003C5272193050000970000002C +:10A76000E78080B11385446D97000000E78040C208 +:10A7700037C500001305057197000000E78040AC65 +:10A780001385C96F97000000E78080C0B7D700002D +:10A7900003C5472193050000B7C9000097000000DA +:10A7A000E78080AD1385C97197000000E78040A95C +:10A7B000130520009305100097000000E780C0B546 +:10A7C00003473921930780011385446D63E6E70051 +:10A7D00037C500001305C56C97000000E78040BB3B +:10A7E00037C500001305057297000000E78040A5FB +:10A7F000034539219307A0009305A0001305950098 +:10A800003345F5021375F50F97000000E78040DF30 +:10A810001385446D97000000E78080B737C50000BE +:10A820001305857297000000E78080A137C50000FE +:10A830001305057397000000E78080B51305140029 +:10A84000930590001375F50F97000000E78040DB3B +:10A85000B7D7000003A40714630C0402B7D70000A5 +:10A8600083C7C713638607021305CA6D97000000EC +:10A87000E78000B237C5000013058573970000001C +:10A88000E780009C1305040097000000E780409BD0 +:10A890001385C97197000000E780809A0324810125 +:10A8A0008320C10183244101032901018329C100BF +:10A8B000032A810037C500001305C5731301010287 +:10A8C000170300006700C3AC230A00F2834740F37C +:10A8D00093F71700E39C07FE130700022308F0F626 +:10A8E00093871700A30A00F693F7F70FE398E7FEA4 +:10A8F00067800000130101FF23248100B7D7000007 +:10A9000037D4000083C717210347042123261100F1 +:10A91000B3E7E7006392070AB7D7000083C7F720C1 +:10A9200063840700630A0508B7D7000003C65721F0 +:10A93000B7D7000083956721B7D70000039587211B +:10A9400097000000E780C0C4230800F6A30A00F6C1 +:10A950009307B0012308F0F6A30A00F6930710004E +:10A960002308F4201307A005B7D700002386E720AB +:10A97000B7D700002384071C130780002308E0F6E4 +:10A98000A30A00F69387871CA38007001307900093 +:10A990002308E0F6A30A00F6238107001307A000AE +:10A9A0002308E0F6A30A00F6A38107009307B0008E +:10A9B0002308F0F6A30A00F68320C10003248100D7 +:10A9C0001301010167800000B7D7000093870715C6 +:10A9D000B387A70083C6070037D7000013070718FF +:10A9E0009386F6FF93F6F60F2380D700B7D70000C3 +:10A9F0001316150093878719638006023307C70073 +:10AA0000B387C700831507000395070013064000AE +:10AA1000170300006700C3B7B7D60000130101FF9A +:10AA2000938686162324810023261100B386A60070 +:10AA3000238006009306F50093F6F60F2308D0F660 +:10AA40003307C700B387C700A30A00F683150700C2 +:10AA5000130405000395070013060000970000008B +:10AA6000E78000B3B7D7000093874717B387870005 +:10AA700083C70700130730006380E70C6368F702A1 +:10AA8000130710006388E70413072000638EE704B0 +:10AA90008320C10003248100B7D7000013071000F2 +:10AAA0002384E714130101016780000013074000AD +:10AAB000E390E7FE37D700008357A7209387077DF1 +:10AAC0002315F720B7C7000037D700009387877496 +:10AAD0006F00400537D700008357A72093874706AC +:10AAE0002315F7206FF0DFFA37D700008357A72030 +:10AAF0001306B004938767092315F72037D70000A2 +:10AB000083463721938706006374D6009307B00409 +:10AB100093879701A309F720B7C7000037D7000034 +:10AB2000938707742320F714B7D700001307800713 +:10AB3000238EE7126FF0DFF537D700008357A72089 +:10AB40009387C7126FF0DFF9131705011357070139 +:10AB50009307D01563ECE706B7D700009387C7A526 +:10AB60003385A7008347050013F5670063020506D8 +:10AB70003307D0401305000063CCE5041387F613B8 +:10AB80006348B70413F52700630605001335760103 +:10AB90006780000013078003636CC7029397270048 +:10ABA00093F7071E3387D54013051000634CF70059 +:10ABB000B385D5009387070463D6F5001336660185 +:10ABC000133516001375F50F67800000130500009C +:10ABD000678000009386050793D6564013D65540EC +:10ABE0009396060193D6060113160601139E0501DE +:10ABF000B30ED04013560601135E0E019396560015 +:10AC0000130F1600B386C641130101FF131F0F0176 +:10AC1000939E0E0113930601B7D2000023268100F4 +:10AC2000232491002322210193070500135F0F4184 +:10AC300093DE0E01135303019303D0159382C2A533 +:10AC40001304F0139304D0013305D041131505010B +:10AC5000135505416350E5099396070193D6060104 +:10AC60001385060313150501135505011307F0029B +:10AC7000636EA7143307DE4013170701135707410C +:10AC8000135757403307E0401317070113570701C5 +:10AC90009306D01563EAE622B7D600009386C6A5D0 +:10ACA0003387E6000347070013771700630E07207A +:10ACB000B307F04093D717401307600113057000E6 +:10ACC0006346F70A93F73700B337F0001395370060 +:10ACD0006F00C00963EED30D3387D20183460700AE +:10ACE00013F766006306070C1315030193FF460074 +:10ACF000135505419308400163840F0093088003B6 +:10AD0000135515401377F50F63E4E80A3308F30091 +:10AD10001318080113580801636C0409131808017B +:10AD200013580841135558401379F50F63860F02E5 +:10AD300093D6360093F6F600636ED900938616001C +:10AD400063CAA60063F6E406930700021305E00059 +:10AD500063FEE700930F40009388F8FF63421703F8 +:10AD60001305F00063940F001305B0000324C10025 +:10AD70008324810003294100130101016780000041 +:10AD80009377770013058000E38207FE13171700FF +:10AD900013770701330707011377E701E30807FC7F +:10ADA00013057000E3940FFC130530006FF01FFCD7 +:10ADB000938E1E00930603FE939E0E0113930601CD +:10ADC00093DE0E01135303016FF01FE8138506ECA9 +:10ADD000131505011355050113077002636CA704D1 +:10ADE0003307AE4013150701131707011357074127 +:10ADF000135757403307E040131707011357070154 +:10AE00009306D0151355050163E0E60CB7D6000094 +:10AE10009386C6A53387E60003470700137717001C +:10AE20006304070A1375E5013335A00013152500E7 +:10AE30006FF0DFF31307F0136368D708B306C04061 +:10AE40009396060193D606011307D015636ED706B5 +:10AE500037D700001307C7A53307D70003470700FC +:10AE6000137717006302070613F7E70113050000C5 +:10AE7000E30E07EE13F7E501E30A07EE13D7574099 +:10AE80003306E6001376360013058000E31006EE65 +:10AE900093F7F701938727FF9397070193D707014C +:10AEA00013073000E364F7EC13F5F501130525FFF4 +:10AEB00013150501135505019307300033B5A7009D +:10AEC000130575006FF09FEA1307500093063000DA +:10AED000B386D502130500003387E7023307D70096 +:10AEE0001377F70F93067000E312D7E8B3C5F500A8 +:10AEF00093F50506E39C05E693F707011305F000BB +:10AF0000E39607E6130570006FF05FE6B7D7000021 +:10AF100083D7072237D7000003572722B307F5004E +:10AF20009397170093970701130101FE93D7070129 +:10AF300023244101338AE700B387E740232A9100A5 +:10AF400093940701B7D700002328210103D9E721F3 +:10AF5000B7D7000083C7C721232C8100131A0A0129 +:10AF60003305F500232E1100232631012322510140 +:10AF70001374F50F9307F00E135A0A0193D40401CA +:10AF800063F68700130404011374F40F9377F90F29 +:10AF90002308F0F293578900A308F0F2230980F206 +:10AFA00093090000930A0014B385344133053A0134 +:10AFB000939505011315050193D5054113550541D9 +:10AFC0001309190097000000E78000C11319090157 +:10AFD000A309A0F213590901631A5901230800F2C9 +:10AFE000A30800F2230980F21309000093891900D5 +:10AFF0009399090193D90901E39859FB8320C10171 +:10B000000324810183244101032901018329C10013 +:10B01000032A8100832A4100130101026780000096 +:10B02000130101F923261106232481062322910608 +:10B0300023202107232E3105232C4105232A5105E6 +:10B0400023286105232671052324810523229105E8 +:10B050002320A105232EB103834780F737C7FFFFC5 +:10B060001307F7EEB3C7E70037D700002312F71432 +:10B07000034780F737C50000B7D700001305C57533 +:10B080002385E71497F0FFFFE780801BB7D7000008 +:10B090009387C7BB130700009306B000230BE0F6AD +:10B0A0001386070883C5070093871700A30BB0F624 +:10B0B000E39AC7FE130717001377F70FE310D7FEC5 +:10B0C000B7D70000A3840714B7D7000093878790F1 +:10B0D0002322F102B7D700009387C79A2324F102F5 +:10B0E000B7D7000003C497146310041E97F0FFFF46 +:10B0F000E780C07D37C500001305857697F0FFFF18 +:10B10000E78000149307800637D700002311F72249 +:10B11000B7D60000130740F52390E622130700E995 +:10B12000B7D60000239DE62037D70000231FF72065 +:10B130009307400437D70000230EF7209304000F35 +:10B1400013050400130414001374F40F9700000097 +:10B15000E78000DCE31694FE97F0FFFFE7800036FF +:10B160009307000A37D40000231CF420B7D700004F +:10B1700003D6A721B7D70000B7D4000013060608EE +:10B180001316060113560641239BC720930780011F +:10B1900013070000930680019305000AA38AF42098 +:10B1A000130500009307100097F0FFFFE780C033FE +:10B1B00037C500001305457797F0FFFFE780401D76 +:10B1C000B7C500009385C5771305500097F0FFFFC2 +:10B1D000E780C02037C500001305C56F97F0FFFF5B +:10B1E000E780001BB7C500009385457913058000F3 +:10B1F00097F0FFFFE780801EB7C500009385857C30 +:10B200001305A00097F0FFFFE780401DB7D50000B1 +:10B210009385C5801305C00097F0FFFFE780001CF1 +:10B22000B7D500009385C5841305D00097F0FFFFC4 +:10B23000E780C01AB7D500009385C5871305E000E5 +:10B2400097F0FFFFE7808019B7D500009385858BC5 +:10B250001305000197F0FFFFE780401837D5000085 +:10B260001305458D97F0FFFFE7808012B7D50000EA +:10B270001305C0019385C58D97F0FFFFE780001689 +:10B28000B7C700001385C77397F0FFFFE780401032 +:10B29000834780F893F7070B639C070897F0FFFF3D +:10B2A000E780001D97F0FFFFE780401E97F0FFFF4B +:10B2B000E7808018834780F813F7F70F939787018B +:10B2C00093D7874163D0070897F0FFFFE7800060BE +:10B2D00037D500001305458F97F0FFFFE78040F654 +:10B2E000834700F093F71700638407006F10803ADC +:10B2F0008320C10603248106832441060329010615 +:10B300008329C105032A8105832A4105032B0105F1 +:10B31000832BC104032C8104832C4104032D0104DD +:10B32000832DC1031305000013010107678000008E +:10B3300097F0FFFFE780C01397F0FFFFE78000154D +:10B340006FF01FF593770703E38A07F4B7D7000080 +:10B3500013073000238AE72037C50000B7D7000065 +:10B360002395072037D70000930710001305C576F3 +:10B370002309F72097F0FFFFE78080ECB7D70000A4 +:10B3800093874717232EF100B7D700001307400615 +:10B39000A389E720B7D7000037DA0000238707200A +:10B3A00013071000B7D70000A386E72093074A1FB2 +:10B3B00023810700B7D70000B7D9000023AE071CD0 +:10B3C000B7D7000023A4071CB7DA00009387091B36 +:10B3D0002381070093878A1623A0070023A2070072 +:10B3E00023A40700B7D7000037D70000239607141F +:10B3F0009307E001A305F7142398091A231A0A1EDC +:10B4000097F0FFFFE780804C930780F437D7000068 +:10B410002311F722930740FE37D700002310F722AD +:10B420009307000D37D70000231DF72093078008EE +:10B4300037D70000231FF720930740FD37D70000C0 +:10B44000230EF72093074A1F2322F1009387091B3D +:10B450002320F10293878A16130900002326F100A6 +:10B460009309000F13050900130919001379F90F47 +:10B4700097000000E780C0A9E31639FF97F0FFFFAF +:10B48000E780C0039307000A231CF4209307800180 +:10B49000A38AF420B7D7000083D7A72137D70000AD +:10B4A00093870708231BF7209307A00537D70000D1 +:10B4B000A308F72003274102B7D7000023880720FD +:10B4C000B7D7000023A0E714B7D700001307800701 +:10B4D000238EE712B7D70000130710002384E71468 +:10B4E00097F0FFFFE7808018B7D700009387C7A5C4 +:10B4F000232CF10097F0FFFFE78080F797F0FFFF24 +:10B50000E780C0FB97F0FFFFE78040F86302050883 +:10B51000930520031305200097F0FFFFE780C0DFAD +:10B5200037C500001305C56D97F0FFFFE78040E6C3 +:10B5300037D500001305459197F0FFFFE78040D015 +:10B54000B7C700001385C77397F0FFFFE78040E49B +:10B5500097F0FFFFE780C0F1834780F8939787015A +:10B5600093D7874163DA07009307100037D70000AD +:10B57000A304F7146FF0DFB697F0FFFFE78000F148 +:10B58000E30805FCB7D70000130710002384E71475 +:10B59000834780F813F9F70F9397870193D7874173 +:10B5A000E3C007B4B7D7000083C70721639807102B +:10B5B000B7D7000003956721937749006388070098 +:10B5C000835784219387D7FF231CF4209377890026 +:10B5D000638807008357842193873700231CF42056 +:10B5E000031784219307F00063C8E7009307000165 +:10B5F000231CF4206F00C00093070013E3CAE7FE8A +:10B6000093771900638C070083C754211307F00256 +:10B610006366F70093871700A38AF42093772900C5 +:10B62000638C070083C75421130720006376F7005B +:10B630009387F7FFA38AF420B7D7000083D9A72107 +:10B64000B7D700001355554093890908939909010C +:10B6500093D90941239B372193D759406302F516AB +:10B66000B7D7000083C71721639C071403C6542172 +:10B67000831584219306A0003305A04097F0FFFFB7 +:10B68000E780C04C630E0512B7D700009387C792BE +:10B6900037D700002320F714B7D70000130780071F +:10B6A000238EE712B7D70000130710002384E71496 +:10B6B0001305100097F0FFFFE7800024B7D70000C4 +:10B6C0008397A721B7DB000037DC0000938707E8EA +:10B6D00093D75740B307F0409399070193D9094195 +:10B6E000938B8B19130C0C18B7D7000003DBC7140E +:10B6F0009307B00263E0672383278102931A2B002C +:10B70000B38AFA0003D70A009317070193D70741BA +:10B7100063C2F920130A00001306C0008327C1008A +:10B72000B307FA0083C607006392061E9306100053 +:10B730002380D7008327C10183C62A00B38747012E +:10B740002380D70083C73A0093161A003386DB00A4 +:10B7500093975700938707012310F600930700FE85 +:10B760003307F702B306DC00130707012390E60056 +:10B7700097F0FFFFE78040CCB7D700009387C7154D +:10B780001375F50303C72A00B38747011305850224 +:10B790002380A700930740006304F70013071000FD +:10B7A000B7D7000093870715B38747012380E700C9 +:10B7B000130B1B00B7D70000239667156FF0DFF25D +:10B7C00037D700008347E72093067001938717005F +:10B7D00093F7F70F63EEF60A2307F72083C6542189 +:10B7E000B7D7000003C7671493076000B3D7F6020A +:10B7F0006308F700B7D70000130710002384E7148D +:10B80000B7D7000083C717218315842113070000D1 +:10B8100093D7270093C7170093F7170013860900E3 +:10B820001305000097F0FFFFE78000CCB7D70000BA +:10B83000039667211307D01593575640B307F0407E +:10B840009397070193D70701636AF70A03278101DA +:10B85000B307F70083C7070093F717006380070A51 +:10B86000831584219307F0131397050113570701DC +:10B8700063E6E70893071000130710009306000023 +:10B880001305B00197F0FFFFE78000C66FF01FE3DC +:10B890002307072037D70000834737216386070037 +:10B8A0009387F7FFA309F72083473721639A07029D +:10B8B000B7D700009387079437D700002320F714E9 +:10B8C000B7D7000013078007238EE712B7D7000011 +:10B8D000130710002384E714130500006FF09FDDA9 +:10B8E00037D7000003477714E30AF7EEB7D7000015 +:10B8F000130710002384E7146FF05FEE9307B00185 +:10B900002308F0F6A30A00F66FF05FDB130A1A00B3 +:10B91000E316CAE0832AC100B7DB0000B7D90000F4 +:10B9200037DA0000938BCB15130A0A18938989190B +:10B93000930C0000130BC00083C70A006388070242 +:10B94000B7D700008397A721031C0A0093FDFC0FC3 +:10B950001385FD00938707101375F50F63D08713C8 +:10B9600023800A002308A0F6A30A00F6938C1C008B +:10B97000938A1A00938B1B0093892900130A2A00CB +:10B98000E39C6CFBB7D600009386861FB7D70000F8 +:10B99000137909012328D10083C7471F37D7000037 +:10B9A00037D60000B7D9000063160922A306072086 +:10B9B000032B4100832B01019389C91F13094620E2 +:10B9C000930A1000130DF000930C400083470B0006 +:10B9D00063880736039C09009387F7FF2300FB0069 +:10B9E000130A4CFF83C70B00931D0A01131A0A01A7 +:10B9F000135A0A412324F1002390490113555C4056 +:10BA000093575A4093DD0D016300F5048317090035 +:10BA10000326810093062000938507003305A0408C +:10BA2000232AF10097F0FFFFE7804012630E050024 +:10BA3000032681000325410123000B0093750CFEB2 +:10BA400097F0FFFFE780C0B4832781006376FD2C69 +:10BA500083470B0013F5FA0F6380072E83268100BE +:10BA600083150900930710001307900013060A00BE +:10BA700097F0FFFFE78040A76F00802C8327C1016C +:10BA800037D700001307479AB387FC0003CD0700A0 +:10BA900083950900930710003307A70103470700A8 +:10BAA0009306400013060C002324B10097F0FFFF1B +:10BAB000E78080A3B7D7000083C70721E39807EA90 +:10BAC00003C754219307B00083258100E3E8E73CD6 +:10BAD000835784219306F000B387F540139707013D +:10BAE000135707411357F740B347F700B387E740B1 +:10BAF0009397070193D70741E3C2F63AB7D70000FF +:10BB000083D76721B307FC401397070113570741F9 +:10BB10001357F740B347F700B387E7409397070100 +:10BB200093D70741E3CCF63613850D0097F0FFFF5E +:10BB3000E780C0E91305000097F0FFFFE780C0DB56 +:10BB40006FF0DFE2938717006398A704B7D7000070 +:10BB500083C7272113073000130C8002636AF700A4 +:10BB60001307C0FEB387E7029387470613FCF70F5E +:10BB700097F0FFFFE780408C1375F503330CAC00A2 +:10BB800023808B016FF09FDE37D700009307000002 +:10BB90001307871C13054000B386E70003C60600A1 +:10BBA000E31206FA37D70000939717001307471DD3 +:10BBB0003307F7002310B70037D700001307C71C5F +:10BBC000B307F70023908701930760042380F600F2 +:10BBD0006FF0DFF7B7D500008346D72083C5052176 +:10BBE000B3E6B600E39606DC93061000A306D72062 +:10BBF000638007028327410083C717006386070617 +:10BC00008327410083C72700E39407DA93072000C6 +:10BC100083558421B7D600001397170093864620DA +:10BC2000B386E6002390B600B7D600009386C61F01 +:10BC30003387E600B7D6000083D66621938646FF99 +:10BC40002310D7000327010183C654213387E7005F +:10BC50002300D70003274100B387E7001307C00183 +:10BC60002380E7006FF0DFD4930710006FF05FFAD6 +:10BC70008327C100B307FC0083C707006380070860 +:10BC80000355090083570700B387A74013950701A1 +:10BC9000135505411355F540B347F500B387A74049 +:10BCA0009397070193D70741634AF60483D70600A9 +:10BCB000B387B74113950701135505411355F54057 +:10BCC000B347F500B387A7409397070193D7074180 +:10BCD0006346F60223000B001375FC0F2326D102E6 +:10BCE000232AE10097F0FFFFE78040CE8326C102C0 +:10BCF000032741019305C0001306F000130C1C003C +:10BD00001307270093862600E304BCD483470B0067 +:10BD1000E39007F66FF0DFD3B7D7000093860718DC +:10BD2000B7D7000013878719130C00001306F00023 +:10BD30009305C0006FF09FFD2308A0F6A30A00F64C +:10BD4000938A1A00130B1B001309290093892900F9 +:10BD5000938B1B00E39C9AC737DC0000B7DB000025 +:10BD600037DA0000130C8C1C938B4B1D130ACA1C72 +:10BD70001309800037DB0000930AC00003470C0062 +:10BD80006300070803560A001307F7FF83970B00A9 +:10BD900013066600131D0601831684211377F70F1F +:10BDA000135D0D41931906012300EC002310AA0135 +:10BDB00093D9090163D4D718938717002390FB0008 +:10BDC000630A07029307ADFF13555D4093D75740B1 +:10BDD000839C0B00638AA716930620001306A0001D +:10BDE00093850C003305A04097F0FFFFE78000D655 +:10BDF000630C051423000C00230820F7A30A00F6A7 +:10BE0000130919001379F90F130C1C00938B2B00E5 +:10BE1000130A2A00E31459F7B7D7000083C7072194 +:10BE2000B7D90000138DC91D6398071CB7D7000050 +:10BE30000397A7219307400013575740B387E74064 +:10BE40009397070193D707011307D0156366F71A75 +:10BE500003278101B307F7008387070063DE071814 +:10BE600037D700008347B7149387F7FF93F7F70F8F +:10BE7000A305F71463920718B7D7000083C72721DB +:10BE800013073000130A9001636AF700130760FF7D +:10BE9000B387E7029387770313FAF70F97E0FFFF63 +:10BEA000E78080591375F501330AAA00B7D700005F +:10BEB000A385471593064000130A0000B307AA01A3 +:10BEC00003C7070063160712130710002380E7005B +:10BED00097E0FFFFE7804056930600113375D502C7 +:10BEE00037D7000093171A001307C71E3307F70050 +:10BEF000130585012310A70037D700001307471E3D +:10BF00003307F700B7D7000083D7A721938707F23D +:10BF10002310F70097E0FFFFE7800052130780022D +:10BF20003375E502B7D700009387071EB307FA0001 +:10BF3000130565002380A7006F00000CE3D2F6E82C +:10BF40009387F7FF6FF09FE7930710001307A00098 +:10BF50009306A00013060D0093850C00130509003D +:10BF600097E0FFFFE780405883470B21E39A07E8FB +:10BF7000835784211307B000B385FC4093970501D4 +:10BF800093D7074193D7F740B3C5B700B385F540C2 +:10BF90009395050193D50541E344B7E6B7D7000073 +:10BFA00083D76721B389F9409397090193D7074154 +:10BFB00093D7F740B3C93701B389F9409399090181 +:10BFC00093D90941E34E37E303C754219307500146 +:10BFD000E3E8E7E223000C00230820F71305000044 +:10BFE000A30A00F697F0FFFFE78000916FF05FE192 +:10BFF000130A1A00E314DAECB7DC000037DC0000A7 +:10C00000B7DA0000938CCC1E130C4C1E938A0A1EC8 +:10C01000930B400037DA00009309800083470D003E +:10C02000638E070403560C008347AA1413066600A8 +:10C030001318060113160601135606412310CC00EF +:10C0400093F7370013580801639C070083C70A0061 +:10C0500003C7542163F4E70E938717002380FA0087 +:10C06000B7D700008397A7219387071063DEC70C1B +:10C0700023000D00230870F7A30A00F6938B1B0022 +:10C0800093FBFB0F130D1D00938C2C00130C2C0045 +:10C09000938A1A00E3943BF9032B0102B7DA0000FC +:10C0A00037DA0000B7D90000938A0A1C130A8A1BEA +:10C0B0009389491B130CF00083470B00638E070024 +:10C0C0009387F7FF93F7F70F2300FB006398072888 +:10C0D000230820F7A30A00F6130919001379F90FB2 +:10C0E000130B1B00938A2A00130A2A009389190054 +:10C0F000E31489FD37DA000083471A2163860700BD +:10C100009387F7FFA308FA2037D900008347C913A4 +:10C11000B7D90000638C07269387F7FF93F7F70FD3 +:10C12000230EF91263940726930710002384F91451 +:10C1300097E0FFFFE78080536F00C025E372F7F2BE +:10C140009387F7FF6FF09FF1839D0C0003CB0A00EC +:10C15000930710001307200093060B0093850D0032 +:10C1600013850B002324010197E0FFFFE780C03710 +:10C17000B7D7000083C70721639E070A835784212E +:10C180001307F000B38DFD4093970D0193D707413E +:10C1900093D7F740B3CDB701B38DFD40939D0D010B +:10C1A00093DD0D416348B709B7D7000083D76721F6 +:10C1B000032881003308F8409317080193D70741FB +:10C1C00093D7F74033C807013308F8401318080124 +:10C1D0001358084163400707B7D7000083C75721AA +:10C1E000330BFB4093170B0193D7074193D7F740CD +:10C1F00033CB6701330BFB40131B0B01135B0B01AC +:10C200009307900063E8670323000D00230870F78D +:10C21000A30A00F603950C0003C60A0083150C0060 +:10C2200097E0FFFFE780C0361305000097E0FFFFAF +:10C23000E780806CB7D700009386C71FB7D7000090 +:10C2400013864720930800001308F0001305300000 +:10C250008327410013871800B385F80083C70500C2 +:10C260006384070E03D30C0083570600B38767402F +:10C2700013930701135303411353F340B347F300E0 +:10C28000B38767409397070193D70741634EF80A36 +:10C2900003530C0083D70600B3876740139307014D +:10C2A000135303411353F340B347F300B38767407D +:10C2B0009397070193D70741130330016346F308AF +:10C2C00083270101B388F80083C7080083C80A00E8 +:10C2D000B38717419398070193D8084193D8F84042 +:10C2E000B3C7F800B38717419397070193D70701A6 +:10C2F0009308B00063EAF804238005001377F70F72 +:10C300002308E0F6A30A00F623000D00230870F7C7 +:10C31000A30A00F603C60A0083150C0003950C005F +:10C3200097E0FFFFE780C02637D700008357A7209C +:10C330009387870C2315F720B7D700001307100049 +:10C340002384E7146FF09FD3930807001306260099 +:10C3500093862600E31EA7EE6FF05FD293F74700A7 +:10C3600083950A0003160A0083C6090013870B0091 +:10C37000638407001307700093071000130509007A +:10C3800097E0FFFFE78040166FF01FD583C7891441 +:10C39000E39007DA37D70000834707216388070E49 +:10C3A000B7D6000083C7C6209387F7FF93F7F70F30 +:10C3B0002386F620639C070CB7D6000083C746216E +:10C3C0009387F7FF93F7F70F238AF6206394070804 +:10C3D00097E0FFFFE780802937D500001305C5945B +:10C3E00097E0FFFFE780C0FA37D40000930544953B +:10C3F0001305D00097E0FFFFE78040FEB7D50000AF +:10C40000938545971305E00097E0FFFFE78000FD67 +:10C41000930544951305F00097E0FFFFE78000FCCB +:10C4200037C500001305C57397E0FFFFE78040F6AE +:10C43000130480071304F4FF97E0FFFFE780400335 +:10C440001374F40F97E0FFFFE7804004E31404FE49 +:10C450006FE01FC993078007A308FA20B7D7000031 +:10C4600083C6372123080720130770026366D700AD +:10C4700013078002A389E720B7D7000013078001C4 +:10C48000A38AE720930710002384F914B7D700008C +:10C4900083976721130730EA93D7574063CAE71899 +:10C4A00037D700008357272237D600009305F013B3 +:10C4B000938627002311D72237D70000035907227C +:10C4C000B7D600001309F9FF13190901135909011F +:10C4D0002310272303D7A6211307C7FF239DE62098 +:10C4E0008356E62113872600131707011357070108 +:10C4F00063F8E500938626EC1397060113570701AE +:10C50000B7D60000231FE62003C7C621130AF00E8A +:10C51000630607001307F7FF137AF70F0357E621A7 +:10C520009387071413191900939707011319090129 +:10C5300093D7070113590901B38927013309F9403A +:10C540009307E71393970701139B0901238E462155 +:10C55000939909011319090193D707019306F01361 +:10C56000135B0B0193D909411359094163F8F60094 +:10C570001307E7FF9317070193D70701130B0B1E50 +:10C58000131B0B0193FBF70F93DA8700135B0B016F +:10C59000130C000F930509001385090013190901F5 +:10C5A0009399090197E0FFFFE780006393D90901A0 +:10C5B00013590901930C05009305F9FF1385190020 +:10C5C000939505011315050193D5054113550541B3 +:10C5D00097E0FFFFE7804060230870F3A30850F363 +:10C5E000230940F393892900A30990F31309290033 +:10C5F000130A1A0093970901131909019399090164 +:10C60000A309A0F2137AFA0F93D7070193D909412E +:10C610001359094163148A01130A0000E39C67F768 +:10C620001305000097F0FFFFE780808E6FE09FEC1E +:10C6300037D700008357A7209387471F2315F7207C +:10C6400037D7000083472721938717002309F72056 +:10C65000B7D700009387479937D700002320F714F6 +:10C6600093078007230EF91297E0FFFFE780000091 +:10C670001309A0051309F9FF97E0FFFFE78040DFEA +:10C680001379F90F97E0FFFFE78040E0E31409FE1C +:10C690006FE09FCF834710F06FE09FC493071000B7 +:10C6A0006316FDACB7D70000839767216350FCACDD +:10C6B000938717F0634CFCAA83C70B00638607CCF3 +:10C6C0009387F7FF2380FB006FF04FAA303B39318F +:10C6D00000000000303B333700000000303B3933AE +:10C6E0000000000042415354494F4E2052414944FA +:10C6F0002020200053434F5245200000303B393763 +:10C70000000000002020204C4556454C2000000031 +:10C710002020205348495053200000001B5B4B0051 +:10C720004655454C20000000202020414C5420005C +:10C73000303B39360000000020202000300000008F +:10C740004655454C0000000052454143544F52208D +:10C7500044455354524F5945442100001B5B3F331D +:10C760006C1B5B3F32356C001B5B306D1B5B324AD0 +:10C7700000000000313B393300000000422041201E +:10C780005320542049204F204E2020205220412069 +:10C7900049204400466C79206F7665722074686584 +:10C7A00020666F72747265737320616E64206465B5 +:10C7B0007374726F79206974732072656163746F2A +:10C7C0007220636F72652E005550202F20444F5702 +:10C7D0004E20636C696D6220616E642064697665C9 +:10C7E0002020202020204C454654202F205249470D +:10C7F00048542073746565722020202020205350F7 +:10C80000414345206669726500000000436C696D14 +:10C8100062206F766572206C6F772077616C6C7325 +:10C820002E20466C79206C6F77207468726F756764 +:10C83000682074686520646F6F727320696E20745D +:10C84000616C6C206F6E65732E000000596F7572FD +:10C8500020736861646F7720616E6420746865205E +:10C86000616C74696D657465722073686F77207987 +:10C870006F7572206865696768742E0053686F6F02 +:10C8800074206675656C2074616E6B7320666F72C0 +:10C89000206675656C2E2054757272657473206104 +:10C8A0006E642066696768746572732073686F6F61 +:10C8B00074206261636B2E00502070617573657324 +:10C8C0002E20204553432067697665732075702EAE +:10C8D00000000000313B3936000000005052455343 +:10C8E0005320535041434520544F20424547494E21 +:10C8F000000000001B5B306D1B5B324A1B5B481B5A +:10C900005B3F3235680000004C4556454C2053547F +:10C9100041525400504155534544202D205020543D +:10C920004F20474F204F4E1B5B4B0000594F552067 +:10C93000484954205448452057414C4C00000000C1 +:10C940004F5554204F46204655454C00303B34341B +:10C950003B393700202020202020202020202020AC +:10C9600020202020202020202020202020202020C7 +:10C9700020200000202020202020202020204741AF +:10C980004D45204F56455220202020202020202099 +:10C99000202000004C4556454C20434C4541524513 +:10C9A0004400000000030405060000001E0001070B +:10C9B0002A0001043000020731000105340001059E +:10C9C0004000030743000203480003084B00010630 +:10C9D0004B0002014F0002025F00010560000301ED +:10C9E0006500020565000208720002047900010674 +:10C9F0007E0001047E00010781000105CB000107D4 +:10CA0000E1000304E8000301EB000204F300010667 +:10CA1000F700020104010101070101010F010108F2 +:10CA20001001010216010302190101071B01010394 +:10CA30001B01020724010103250102052601020151 +:10CA4000280101062F010105300101083A01010406 +:10CA500040010208440102024B01040500000000ED +:10CA600000000000000000000000010101010101C0 +:10CA700001010101030101010101010101050101A0 +:10CA80000101010101010103010101010101010194 +:10CA90000101012D0101010101010101010101015A +:10CAA0002D01010101010101010101010103010148 +:10CAB0000101010101012D0101010101010101013A +:10CAC0000101250101010101010101010101010132 +:10CAD0000101010101010101010101010101010146 +:10CAE0000101808080808080808080808080808044 +:10CAF0008080808080808080808080808080808036 +:10CB00008080808080808080808080808080808025 +:10CB10008080808080808080808080808080010113 +:10CB200001010101010101013D01010101010101B9 +:10CB300001010103010101010101010101012D01B7 +:10CB400001010101010101010101011501010101C1 +:10CB500001010101010101010301010101010101C3 +:10CB6000010101010145010101010101010145012D +:10CB700001010101010101010101010301010101A3 +:10CB80000101010101011501010101010101010181 +:10CB90000101010101010101010101010101010185 +:10CBA000010101010101010101010000000000007B +:10CBB0000000000000000000000000000000000075 +:10CBC0000000000000000000000000000000000065 +:10CBD0000000000000000000000000000000000055 +:10CBE0000000000000000000000FFF00CCCCCC0FC4 +:10CBF000F666F000CCCCCFFFF6660000000FFFFF1A +:10CC0000FFF00000CCCFFFFFFCC00000CCCCCF0C6D +:10CC1000CCCC000000CCC000CCCC00000000C00098 +:10CC200000C0000000000000000000000000000044 +:10CC300000000000000000000000000000000000F4 +:10CC400000000000000000000000000000000000E4 +:10CC500000000000000000000000000000000000D4 +:10CC600000000000000000000004440044444404AC +:10CC700044444000444444444444000000044444C8 +:10CC800044400000444444444440000044444404BC +:10CC900044440000004440004444000000004000C0 +:10CCA0000040000000000000000000000000000044 +:10CCB0000000000000000000000000000000000074 +:10CCC0000000000000000000000000000000000064 +:10CCD0000000000000000100000100000000111130 +:10CCE000000111000000111110D111110000011DEF +:10CCF000DDDDD11100000DDDDDDDD0000000BBBDAC +:10CD0000DDD11111000DBBBDD011111100DDD0001E +:10CD10000000000000000000000000000000000013 +:10CD20000000000000000000000000000000000003 +:10CD300000000000000000000000000000000000F3 +:10CD400000000000000000000000000000000000E3 +:10CD500000000000000000000000000000000000D3 +:10CD6000000000000000000000000000000002229F +:10CD700022200000000022AA2222000000022AAA8B +:10CD8000A2222000000222AA222220000082227277 +:10CD9000222228000888277722228880008777228D +:10CDA000222888000077788888888000000008881A +:10CDB000888000000000000000000000000000006B +:10CDC0000000000000000000000000000000BBBBED +:10CDD000BBBB0000000BBBBBBBBBB000000BBBBBB5 +:10CDE000BBBBB0000009BBBBBBBB900000099F915F +:10CDF0001119900000099F911999900000099F91C5 +:10CE00001199900000099F911999900000099F9134 +:10CE100019999000000999999999900000011111B0 +:10CE2000111110000000111111110000000000008C +:10CE300000000000000000000000000000000000F2 +:10CE400000000000000000000000000000EE0000F4 +:10CE50000000000000EEEEE000000000000E666E34 +:10CE6000EEE00000000EEE66666EE00000000EEEE2 +:10CE7000E66E00000000000770EE000000000007F2 +:10CE800070000000000000077000000000000007B4 +:10CE900070000000000000077000000000000008A3 +:10CEA00080000000000088888888000000008888D2 +:10CEB00088880000000000088000000000000000DA +:10CEC00000000000000000055000000000000055B8 +:10CED000550000000000055DD5500000000055DD44 +:10CEE000DD55000000055DFFFFD550000055DDFF5A +:10CEF000FFDD55000555DDFFFFDD555000555DFF99 +:10CF0000FFD55500000555DDDD5550000000555D8D +:10CF1000D555000000000555555000000000005593 +:10CF20005500000000000005500000000000000057 +:10CF300000000000000000000000000000000000F1 +:10CF400000000000000000000000000000000000E1 +:10CF5000000000000000009900000000000099B0EF +:10CF60000009900000090B00BB0000000000BBFF9F +:10CF70000FB00000009B0FFFF0BB00000000B00FDF +:10CF8000F00BB0000090B0FFF00090000000BB0B71 +:10CF9000B0000000000000B0000000000000090028 +:10CFA0000000000000000000000000000000000081 +:10CFB0000000000000000000000000000000000071 +:10CFC0000000000000000000000000000000000061 +:10CFD0000000000000000101010000000000000945 +:10CFE000010000000009900009000000000000009E +:10CFF00000091000000990BBBB99910000090BBB10 +:10D00000BB909100000000B0B090010000000999B1 +:10D01000000900000001010009900000000000115B +:10D0200001100000000000000000000000000000EF +:10D0300000000000000000000000000000000000F0 +:10D0400000000000000000000000000000000000E0 +:10D0500000000000000000000000000000000000D0 +:10D0600000000000000000000000000000000000C0 +:10D07000000000000000000FF00000000000000FA2 +:10D08000B0000000000000000000000000000000F0 +:10D090000000000000000000000000000000000090 +:10D0A0000000000000000000000000000000000080 +:10D0B0000000000000000000000000000000000070 +:10D0C0000000000000000000000000000000000060 +:10D0D0000000000000000000000000000000000050 +:10D0E0000000000000000000000000000000000937 +:10D0F00090000000000000999900000000000099D5 +:10D10000F90000000000000990000000000000008D +:10D11000000000000000000000000000000000000F +:10D1200000000000000000000000000000000000FF +:0CD13000000000000000000000000000F3 +:040000030000A20057 +:00000001FF diff --git a/games/raid/test-raid.py b/games/raid/test-raid.py new file mode 100644 index 0000000..b3485bf --- /dev/null +++ b/games/raid/test-raid.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +"""Run Bastion Raid in tools/rv32emu.py on a model of the board (tools/boardemu.py) +and take screenshots. + + python3 test-raid.py [--shots DIR] [--play] + +It checks the title screen, measures the Z-80 instructions each frame takes +(a 60 Hz frame has about 550,000 at 90 MHz), flies into the fortress, and with +--play lets an autopilot fly the whole level: it steers through every doorway +at the right height, climbs over low walls and shoots ahead. The autopilot +can't be hit by shells or fighters (it keeps the ship invulnerable), so this +checks the level and the rules, not its skill. +""" +import argparse +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "tools")) +sys.path.insert(0, HERE) +from boardemu import Board, load_ihx, load_font, load_syms # noqa: E402 + +UP, DOWN, LEFT, RIGHT, FIRE, ENTER, ESC = 1, 2, 4, 8, 16, 32, 128 + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--shots", help="write PNG screenshots here") + ap.add_argument("--play", action="store_true", help="fly the level with the autopilot") + a = ap.parse_args() + mem, hi = load_ihx(os.path.join(HERE, "raid.ihx")) + b = Board(mem, code_end=hi) + font = load_font() if a.shots else None + if a.shots: + os.makedirs(a.shots, exist_ok=True) + sym = {"_" + n: a for n, a in load_syms(os.path.join(HERE, "out", "raid.sym")).items()} + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def i16(n): + v = b.m[sym[n]] | b.m[sym[n] + 1] << 8 + return v - 65536 if v & 0x8000 else v + + def hud(): + return "\n".join(b.screen_text().display[:2]) + + b.run_frames(5) + check("title screen", "B A S T I O N R A I D" in "\n".join(b.screen_text().display)) + if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font) + b.run_frames(3, FIRE) + b.run_frames(5) + check("game starts", "LEVEL 1" in hud() and "SHIPS 3" in hud()) + c0 = b.steps + b.run_frames(60) + per = (b.steps - c0) / 60 + print("%.0f instructions a frame (%.0f%% of a 60 Hz frame at 90 MHz)" % (per, per / 5500)) + check("a frame fits in a 60th of a second", per < 500000) + if a.shots: b.shot(os.path.join(a.shots, "2-approach.png"), font) + alt0 = b.m[sym["_alt"]] + b.run_frames(10, UP) + check("climbing raises the ship", b.m[sym["_alt"]] == alt0 + 10) + b.run_frames(60) + if a.shots: b.shot(os.path.join(a.shots, "3-fortress.png"), font) + print(hud()) + + if a.play: + sys.path.insert(0, HERE) + import gen + rows, objs = gen.level() + frame = 0 + best_row = 0 + worst = 0 + while frame < 6000 and b.pc != 0: + b.m[sym["_shield"]] = 1 + b.m[sym["_fuel"]] = 100 + if b.m[sym["_dead"]]: + r = -(i16("_ship_d") >> 5) + print("autopilot crashed at row %d: ship s %d, height %d; rows here %s" % + (r, i16("_ship_s"), b.m[sym["_alt"]], rows[r - 2:r + 3])) + break + ship_s, ship_d, alt = i16("_ship_s"), i16("_ship_d"), b.m[sym["_alt"]] + row = -(ship_d >> 5) + best_row = max(best_row, row) + # the next wall within 6 rows decides where to be + want_s, want_alt = 16 * gen.BW, 24 + for r in range(row, min(row + 6, len(rows))): + ri = rows[r] + if ri & 4: + g = (ri >> 3) & 15 + want_s, want_alt = 32 * g + 32, 10 + break + if ri & 2: + want_alt = 30 + break + j = 0 + if ship_s < want_s - 2: j |= RIGHT + elif ship_s > want_s + 2: j |= LEFT + if alt < want_alt: j |= UP + elif alt > want_alt: j |= DOWN + if frame % 6 == 0: j |= FIRE + c0 = b.steps + b.run_frames(1, j) + worst = max(worst, b.steps - c0) + frame += 1 + if frame == 700 and a.shots: b.shot(os.path.join(a.shots, "4-doorway.png"), font) + if "LEVEL 2" in hud(): + break + check("autopilot flew the level (got to row %d of %d)" % (best_row, len(rows)), + "LEVEL 2" in hud()) + print("slowest frame: %d instructions (%.0f%% of a 60 Hz frame)" % (worst, worst / 5500)) + check("every frame fits in a 60th of a second", worst < 550000) + print(hud()) + b.run_frames(120) # level 2 starts + b.run_frames(5, ESC) # give up: back to the title + b.run_frames(5) + check("Esc gives up the game", "PRESS SPACE TO BEGIN" in "\n".join(b.screen_text().display)) + b.run_frames(5, ESC) # Esc at the title: back to BASIC + b.run_frames(5) + check("Esc returns to BASIC", b.pc == 0) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/games/swarm/gen.py b/games/swarm/gen.py new file mode 100644 index 0000000..37989f3 --- /dev/null +++ b/games/swarm/gen.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +"""Make data.h for swarm.c: the sprite shapes (also drawn into the graphics +for the aliens waiting in formation) and a sine table for the dives. + +Shapes are 16 rows of 16 hex digits, one colour per pixel (0 is see-through). +""" +import math +import random +import sys + +Z = "0" * 16 + +DRONE_A = [Z, Z, + "000C00000000C000", + "0000C000000C0000", + "00000CCCCCC00000", + "0000CC4CC4CC0000", + "000CCCCCCCCCC000", + "0CCCCCCCCCCCCCC0", + "0C0CCCCCCCCCC0C0", + "0C0C00000000C0C0", + "0000CC0000CC0000", +] + [Z] * 5 +DRONE_B = [Z, Z, + "0000C000000C0000", + "0000C000000C0000", + "00000CCCCCC00000", + "0000CC4CC4CC0000", + "000CCCCCCCCCC000", + "00CCCCCCCCCCCC00", + "0CCCCCCCCCCCCCC0", + "C00C00000000C00C", + "000CC000000CC000", +] + [Z] * 5 +FLAG_A = [Z, + "0000000BB0000000", + "000000BBBB000000", + "00B00BB99BB00B00", + "00BB0BBBBBB0BB00", + "00BBBBBBBBBBBB00", + "000BB9BBBB9BB000", + "0000BBBBBBBB0000", + "00000B9BB9B00000", + "0000B000000B0000", + "000B00000000B000", +] + [Z] * 5 +FLAG_B = [Z, + "0000000BB0000000", + "000000BBBB000000", + "00000BB99BB00000", + "B0BB0BBBBBB0BB0B", + "0BBBBBBBBBBBBBB0", + "000BB9BBBB9BB000", + "0000BBBBBBBB0000", + "00000B9BB9B00000", + "00000B0000B00000", + "0000B000000B0000", +] + [Z] * 5 + + +def recolour(img, table): + return [row.translate(str.maketrans(table)) for row in img] + + +WARRIOR_A, WARRIOR_B = recolour(DRONE_A, {"C": "D", "4": "B"}), recolour(DRONE_B, {"C": "D", "4": "B"}) +ESCORT_A, ESCORT_B = recolour(DRONE_A, {"C": "9", "4": "F"}), recolour(DRONE_B, {"C": "9", "4": "F"}) + +SHIP = [Z, + "0000000FF0000000", + "0000000FF0000000", + "000000FFFF000000", + "000000F99F000000", + "00F00FFFFFF00F00", + "00F0FFFFFFFF0F00", + "00FFFFFFFFFFFF00", + "00FFF99FF99FFF00", + "00FF00FFFF00FF00", +] + [Z] * 6 +SHOT = [Z] * 5 + ["0000000BB0000000"] * 6 + [Z] * 5 +BULLET = [Z] * 6 + ["00000009F0000000", "0000000F90000000", "000000099000000" + "0"] + [Z] * 7 + + +def burst(seed, cols, size): + r = random.Random(seed) + img = [["0"] * 16 for _ in range(16)] + for _ in range(80): + a = r.uniform(0, 2 * math.pi) + d = r.uniform(0, size) + x, y = int(8 + d * math.cos(a)), int(8 + d * math.sin(a)) + if 0 <= x < 16 and 0 <= y < 16: + img[y][x] = cols[0] if d < size / 3 else cols[1] if d < 2 * size / 3 else cols[2] + return ["".join(row) for row in img] + + +BOOM1 = burst(21, "FB9", 5) +BOOM2 = burst(23, "B91", 7.5) +SHIPBOOM = burst(25, "FFB", 7.9) + + +def stars(seed): + r = random.Random(seed) + img = [["0"] * 16 for _ in range(16)] + for _ in range(2): + img[r.randrange(16)][r.randrange(16)] = r.choice("FE7BD6") + return ["".join(row) for row in img] + + +SHAPES = [("S_DRONE", DRONE_A), ("S_DRONE2", DRONE_B), ("S_WARRIOR", WARRIOR_A), ("S_WARRIOR2", WARRIOR_B), + ("S_ESCORT", ESCORT_A), ("S_ESCORT2", ESCORT_B), ("S_FLAG", FLAG_A), ("S_FLAG2", FLAG_B), + ("S_SHIP", SHIP), ("S_SHOT", SHOT), ("S_BULLET", BULLET), + ("S_BOOM1", BOOM1), ("S_BOOM2", BOOM2), ("S_SHIPBOOM", SHIPBOOM), + ("S_STARS1", stars(1)), ("S_STARS2", stars(2)), ("S_STARS3", stars(3))] + + +def main(out): + L = ["/* made by gen.py - edit that instead */", ""] + for i, (name, img) in enumerate(SHAPES): + assert len(img) == 16 and all(len(row) == 16 for row in img), name + L.append("#define %s %d" % (name, i)) + L.append("#define N_SHAPES %d" % len(SHAPES)) + L.append("static const u8 shape_data[N_SHAPES * 128] = {") + for name, img in SHAPES: + b = [int(row[x], 16) << 4 | int(row[x + 1], 16) for row in img for x in range(0, 16, 2)] + L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % name) + L.append("};") + # 64 steps round the circle, 0 = right, 16 = down; scaled by 64 + L.append("static const i8 sin64[64] = {") + L.append(" " + ",".join(str(int(round(64 * math.sin(2 * math.pi * k / 64)))) for k in range(64))) + L.append("};") + open(out, "w").write("\n".join(L) + "\n") + print("data.h: %d shapes" % len(SHAPES)) + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else "data.h") diff --git a/games/swarm/swarm.bas b/games/swarm/swarm.bas new file mode 100644 index 0000000..020a6e6 --- /dev/null +++ b/games/swarm/swarm.bas @@ -0,0 +1,4 @@ +10 REM STAR SWARM: LOAD THE GAME (MEMORY FILE SWARMGAM) AND PLAY IT +20 REM THE GAME RUNS AT A200H, PAST THIS PROGRAM, AND COMES BACK HERE +30 BLOAD "SWARMGAM": CALL 41472 +40 CLS diff --git a/games/swarm/swarm.c b/games/swarm/swarm.c new file mode 100644 index 0000000..27b9462 --- /dev/null +++ b/games/swarm/swarm.c @@ -0,0 +1,655 @@ +/* Star Swarm: a swooping alien shooter for the Basys 3 RISC-V computer. + + An alien swarm sways across the top of the screen in formation: drones, + warriors, escorts and two flagships. They peel off in looping dives, + firing as they come, and loop back into place if they miss. A flagship + brings its escorts; shoot the escorts first for a bonus. Your ship has one + shot in the air at a time. + + There are 46 aliens and only 32 sprites, so the formation is drawn into the + graphics layer and sways by the hardware X scroll (ports 35h-36h). An alien + that dives is wiped from the graphics and becomes a sprite; when it gets + back to its place it is drawn in again. The stars are sprites too, a couple + of dots each, falling down the screen. It runs at A200h, loaded by the + SWARM program in BASIC. */ + +typedef unsigned char u8; +typedef signed char i8; +typedef unsigned short u16; +typedef short i16; + +#include "basys3.h" + +#define con_stat IO8(0x00) +#define con_data IO8(0x01) +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) +#define gfill IO8(0x34) +#define scr_xlo IO8(0x35) +#define scr_xhi IO8(0x36) +#define scr_y IO8(0x37) +#define sp_sel IO8(0x70) +#define sp_xlo IO8(0x71) +#define sp_xhi IO8(0x72) +#define sp_y IO8(0x73) +#define sp_shape IO8(0x74) +#define sp_ctl IO8(0x75) +#define sp_load IO8(0x76) +#define sp_data IO8(0x77) +#define frame_ctr IO8(0x78) +#define joy IO8(0x88) + +#include "data.h" /* out/data.h, made by gen.py */ + +#define J_LEFT 4 +#define J_RIGHT 8 +#define J_FIRE 16 +#define J_ENTER 32 +#define J_ESC 128 + +#define COLS 10 +#define ROWS 6 +#define FX0 60 /* buffer x of column 0 */ +#define CW 20 +#define FY0 36 /* top row */ +#define RH 16 +#define SHIP_Y 214 + +/* sprites: lower numbers in front */ +#define SP_SHIP 0 +#define SP_SHOT 1 +#define SP_DIVER 2 /* 8 */ +#define SP_BUL 10 /* 6 */ +#define SP_BOOM 16 /* 4 */ +#define SP_STAR 20 /* 10 */ + +#define ND 8 +#define NB 6 +#define NX 4 +#define NST 10 + +#define C_EMPTY 0 +#define C_HOME 1 +#define C_AWAY 2 + +#define P_LOOP 0 +#define P_ATTACK 1 +#define P_RETURN 2 + +/* which alien is where: 0 none, else 1 drone, 2 warrior, 3 escort, 4 flagship */ +static const u8 layout[ROWS][COLS] = { + { 0, 0, 0, 4, 0, 0, 4, 0, 0, 0 }, + { 0, 0, 3, 3, 3, 3, 3, 3, 0, 0 }, + { 0, 2, 2, 2, 2, 2, 2, 2, 2, 0 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, +}; +static const u8 kind_shape[5] = { 0, S_DRONE, S_WARRIOR, S_ESCORT, S_FLAG }; +static const u8 home_score[5] = { 0, 30, 40, 50, 60 }; +static const u8 dive_score[5] = { 0, 60, 80, 100, 150 }; + +/* ---------------------------------------------------------------- state */ +/* not static: test-swarm.py reads these from the link map */ +u8 cell[ROWS][COLS]; +i16 ship_x; +u8 lives, wave, dead, shield; +u16 score; +u8 dv_on[ND]; +i16 dv_x[ND], dv_y[ND]; /* 1/16 pixels, screen */ + +static u8 dv_row[ND], dv_col[ND], dv_ang[ND], dv_spd[ND], dv_phase[ND], dv_cool[ND], dv_shots[ND]; +static i8 dv_turn[ND]; +static u8 dv_lead[ND]; /* escorts: the flagship's diver, else 255 */ +static u8 dv_escorts[ND], dv_esc_hit[ND]; + +static i16 shot_x, shot_y; +static u8 shot_on; +static i16 bx[NB], by[NB]; +static i8 bvx[NB]; +static u8 b_on[NB]; +static i16 xx[NX], xy[NX]; +static u8 xt[NX], xship[NX]; +static u8 st_x[NST], st_y[NST], st_v[NST]; + +static i16 sway; +static i8 sway_dir; +static u8 flap, flap_timer, dive_timer, attacks, dead_time, fire_held; +static u16 next_extra; +static u8 last_frame, quit, hud_dirty; +static u16 rnd_state; +static const char *msg; +static u8 msg_time; + +/* ----------------------------------------------------------------- text */ +static void putch(char c) { while (!(con_stat & 2)); con_data = c; } +static void puts_(const char *s) { while (*s) putch(*s++); } +static void putn(u16 n, u8 width) +{ + char b[6]; + u8 i = 0; + do { b[i++] = '0' + n % 10; n /= 10; } while (n); + while (width > i) { putch('0'); width--; } + while (i) putch(b[--i]); +} +static void at(u8 r, u8 c) { putch(27); putch('['); putn(r, 0); putch(';'); putn(c, 0); putch('H'); } +static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); } +static void centre(u8 r, const char *s) +{ + u8 n = 0; + while (s[n]) n++; + at(r, 41 - n / 2); + puts_(s); +} + +static u16 rnd(void) +{ + rnd_state ^= rnd_state << 7; + rnd_state ^= rnd_state >> 9; + rnd_state ^= rnd_state << 8; + return rnd_state; +} + +static void wait_frame(void) +{ + while (frame_ctr == last_frame); + last_frame = frame_ctr; +} + +static u8 drain_keys(void) +{ + u8 c, p = 0; + while (con_stat & 1) { + c = con_data; + if (c == 'p' || c == 'P') p = 1; + } + return p; +} + +static void say(const char *s) { msg = s; msg_time = 120; hud_dirty = 1; } +static i16 absd(i16 v) { return v < 0 ? -v : v; } + +/* ------------------------------------------------------------ graphics */ +/* Draw shape (or nothing) into the graphics with its top left at buffer (x, y). */ +static void blit(u16 x, u8 y, u8 shape, u8 erase) +{ + const u8 *p = shape_data + ((u16)shape << 7); + u8 r, i, b; + for (r = 0; r < 16; r++) { + gx_lo = (u8)x; gx_hi = (u8)(x >> 8); gy_p = y + r; + for (i = 0; i < 8; i++) { + b = erase ? 0 : *p++; + gpix = b >> 4; gpix = b & 15; + } + } +} + +static u16 cell_bx(u8 c) { return FX0 + c * CW + 2; } +static u8 cell_by(u8 r) { return FY0 + r * RH; } + +static void draw_cell(u8 r, u8 c) +{ + blit(cell_bx(c), cell_by(r), kind_shape[layout[r][c]] + flap, cell[r][c] != C_HOME); +} + +static void draw_formation(void) +{ + u8 r, c; + for (r = 0; r < ROWS; r++) + for (c = 0; c < COLS; c++) + if (layout[r][c]) draw_cell(r, c); +} + +static void set_scroll(void) +{ + /* the picture moves right by sway: show buffer column -sway at the left */ + i16 s = -sway; + if (s < 0) s += 320; + scr_xlo = (u8)s; scr_xhi = (u8)(s >> 8); scr_y = 0; +} + +/* -------------------------------------------------------------- sprites */ +static void spr_at(u8 n, i16 x, i16 y, u8 shape, u8 ctl) +{ + sp_sel = n; + if (x < -15 || x > 319 || y < -15 || y > 239) { sp_ctl = 0; return; } + sp_xlo = (u8)x; sp_xhi = (u8)(x >> 8) & 1; sp_y = (u8)y; + sp_shape = shape; sp_ctl = ctl; +} +static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; } +static void all_off(void) { u8 i; for (i = 0; i < 32; i++) spr_off(i); } + +static void load_shapes(void) +{ + const u8 *p = shape_data; + u8 s, i; + for (s = 0; s < N_SHAPES; s++) { + sp_load = s; + for (i = 0; i < 128; i++) sp_data = *p++; + } +} + +static void boom(i16 x, i16 y, u8 ship) +{ + u8 i, best = 0; + for (i = 0; i < NX; i++) if (xt[i] < xt[best]) best = i; + xx[best] = x; xy[best] = y; xt[best] = ship ? 60 : 18; xship[best] = ship; +} + +/* ------------------------------------------------------------------ HUD */ +static void hud(void) +{ + hud_dirty = 0; + at(1, 1); ink("0;93"); puts_("STAR SWARM "); + ink("0;37"); puts_("SCORE "); ink("0;97"); putn(score, 6); + ink("0;37"); puts_(" SHIPS "); ink("0;97"); putn(lives, 0); + ink("0;37"); puts_(" WAVE "); ink("0;97"); putn(wave, 0); + if (msg && msg_time) { ink("0;96"); puts_(" "); puts_(msg); } + puts_("\033[K"); + ink("0"); +} + +static void add_score(u16 n) +{ + score += n; + if (score >= next_extra) { next_extra += 7000; lives++; say("BONUS SHIP"); } + hud_dirty = 1; +} + +/* --------------------------------------------------------------- stars */ +static void stars(void) +{ + u8 i; + for (i = 0; i < NST; i++) { + st_y[i] += st_v[i]; + if (st_y[i] >= 240) { st_y[i] -= 240; st_x[i] = rnd() % 304; } + spr_at(SP_STAR + i, st_x[i], st_y[i], S_STARS1 + i % 3, 1); + } +} + +/* -------------------------------------------------------------- divers */ +static void dive(u8 r, u8 c, u8 lead, i8 turn) +{ + u8 d; + for (d = 0; d < ND && dv_on[d]; d++); + if (d == ND) return; + dv_on[d] = 1; dv_row[d] = r; dv_col[d] = c; + dv_x[d] = (i16)(cell_bx(c) + sway) << 4; + dv_y[d] = (i16)cell_by(r) << 4; + dv_ang[d] = 48; /* straight up */ + dv_turn[d] = turn; + dv_spd[d] = 22; + dv_phase[d] = P_LOOP; + dv_cool[d] = 20 + (rnd() & 31); + dv_shots[d] = wave < 3 ? 2 : 3; + dv_lead[d] = lead; + dv_escorts[d] = 0; dv_esc_hit[d] = 0; + if (lead != 255) dv_escorts[lead]++; + cell[r][c] = C_AWAY; + draw_cell(r, c); +} + +static u8 divers_out(void) +{ + u8 d, n = 0; + for (d = 0; d < ND; d++) if (dv_on[d]) n++; + return n; +} + +static void launch(void) +{ + u8 r, c, k, side, lead; + i8 turn; + u8 most = 2 + wave; if (most > ND) most = ND; + if (divers_out() >= most) return; + attacks++; + /* every fourth attack, a flagship with the escorts beside it */ + if ((attacks & 3) == 0) { + c = (rnd() & 1) ? 3 : 6; + if (cell[0][c] != C_HOME) c = 9 - c; + if (cell[0][c] == C_HOME) { + turn = c < 5 ? 1 : -1; + dive(0, c, 255, turn); + for (lead = 0; lead < ND; lead++) + if (dv_on[lead] && dv_row[lead] == 0 && dv_col[lead] == c) break; + if (lead < ND) + for (r = c - 1; r <= c + 1 && dv_escorts[lead] < 2; r++) + if (cell[1][r] == C_HOME) dive(1, r, lead, turn); + return; + } + } + /* otherwise one from the end of a row, from a random side */ + side = rnd() & 1; + for (k = 0; k < COLS; k++) { + c = side ? COLS - 1 - k : k; + for (r = ROWS; r-- > 1;) { + if (cell[r][c] == C_HOME && !(rnd() & 1)) { + dive(r, c, 255, c < 5 ? 1 : -1); + return; + } + } + } +} + +static void bullet_from(i16 x, i16 y) +{ + u8 b; + for (b = 0; b < NB && b_on[b]; b++); + if (b == NB) return; + b_on[b] = 1; bx[b] = x << 4; by[b] = y << 4; + bvx[b] = ship_x + 8 > x ? 6 : -6; + if (absd(ship_x + 8 - x) < 20) bvx[b] = 0; +} + +static void kill_diver(u8 d) +{ + u8 r = dv_row[d], c = dv_col[d], k = layout[r][c], lead = dv_lead[d]; + u16 pts = dive_score[k]; + if (k == 4) { + if (dv_escorts[d] && dv_esc_hit[d] == dv_escorts[d]) { pts = 800; say("FLAGSHIP AND ESCORTS: 800"); } + else if (dv_escorts[d]) pts = 300; + } + if (lead != 255 && dv_on[lead]) dv_esc_hit[lead]++; + add_score(pts); + boom((dv_x[d] >> 4), dv_y[d] >> 4, 0); + dv_on[d] = 0; + cell[r][c] = C_EMPTY; + spr_off(SP_DIVER + d); +} + +static void kill_ship(void) +{ + u8 d, b; + if (dead || shield) return; + dead = 1; dead_time = 130; + boom(ship_x, SHIP_Y, 1); + spr_off(SP_SHIP); + for (b = 0; b < NB; b++) { b_on[b] = 0; spr_off(SP_BUL + b); } + for (d = 0; d < ND; d++) + if (dv_on[d] && dv_phase[d] != P_RETURN) dv_phase[d] = P_ATTACK; +} + +static void divers(void) +{ + u8 d, r, c, s; + i16 x, y, tx; + for (d = 0; d < ND; d++) { + if (!dv_on[d]) continue; + r = dv_row[d]; c = dv_col[d]; + switch (dv_phase[d]) { + case P_LOOP: /* up and over, out to the side */ + dv_ang[d] = (dv_ang[d] - dv_turn[d]) & 63; + if (dv_ang[d] == 16) { dv_phase[d] = P_ATTACK; dv_spd[d] = 30 + 2 * (wave < 8 ? wave : 8); } + break; + case P_ATTACK: /* down at the ship, firing */ + if (!(last_frame & 3) && !dead) { + tx = ship_x + 8 - (dv_x[d] >> 4); + if (tx > 6 && dv_ang[d] > 9) dv_ang[d]--; + else if (tx < -6 && dv_ang[d] < 23) dv_ang[d]++; + } + y = dv_y[d] >> 4; + if (dv_cool[d]) dv_cool[d]--; + else if (dv_shots[d] && y > 70 && y < 170 && !dead) { + bullet_from((dv_x[d] >> 4) + 8, y + 12); + dv_shots[d]--; + dv_cool[d] = 16 + (rnd() & 15); + } + if (y > 244) { /* gone past: come back in at the top */ + dv_phase[d] = P_RETURN; + dv_y[d] = -16 << 4; + dv_spd[d] = 24; + } + break; + case P_RETURN: /* drop back into place */ + dv_x[d] = (i16)(cell_bx(c) + sway) << 4; + dv_y[d] += dv_spd[d]; + if (dv_y[d] >= (i16)cell_by(r) << 4) { + dv_on[d] = 0; + cell[r][c] = C_HOME; + draw_cell(r, c); + spr_off(SP_DIVER + d); + continue; + } + break; + } + if (dv_phase[d] != P_RETURN) { + dv_x[d] += (sin64[(dv_ang[d] + 16) & 63] * dv_spd[d]) >> 6; + dv_y[d] += (sin64[dv_ang[d]] * dv_spd[d]) >> 6; + } + x = dv_x[d] >> 4; y = dv_y[d] >> 4; + if (!dead && absd(x - ship_x) < 11 && absd(y - SHIP_Y) < 10) { + kill_diver(d); kill_ship(); continue; + } + if (shot_on && absd(shot_x - (x + 8)) < 8 && absd(shot_y - (y + 7)) < 8) { + shot_on = 0; spr_off(SP_SHOT); + kill_diver(d); + continue; + } + s = kind_shape[layout[r][c]] + ((last_frame >> 3) & 1); + spr_at(SP_DIVER + d, x, y, s, 1); + } +} + +static void bullets(void) +{ + u8 b; + i16 x, y; + for (b = 0; b < NB; b++) { + if (!b_on[b]) continue; + bx[b] += bvx[b]; + by[b] += 48; + x = bx[b] >> 4; y = by[b] >> 4; + if (y > 240) { b_on[b] = 0; spr_off(SP_BUL + b); continue; } + if (!dead && absd(x - (ship_x + 8)) < 7 && y > SHIP_Y + 2 && y < SHIP_Y + 13) { + b_on[b] = 0; spr_off(SP_BUL + b); + kill_ship(); + continue; + } + spr_at(SP_BUL + b, x - 8, y - 8, S_BULLET, 1); + } +} + +/* The ship's shot against the formation: which cell is it in? */ +static void shot_vs_formation(void) +{ + i16 bxp = shot_x - sway - FX0, byp = shot_y - FY0; + u8 r, c, ix, iy; + if (bxp < 0 || byp < 0) return; + c = (u8)(bxp / CW); ix = (u8)(bxp % CW); + r = (u8)(byp / RH); iy = (u8)(byp % RH); + if (c >= COLS || r >= ROWS || ix < 3 || ix > 16 || iy < 2 || iy > 11) return; + if (cell[r][c] != C_HOME) return; + cell[r][c] = C_EMPTY; + draw_cell(r, c); + add_score(home_score[layout[r][c]]); + boom(cell_bx(c) + sway, cell_by(r), 0); + shot_on = 0; spr_off(SP_SHOT); +} + +static void ship(u8 j) +{ + if (dead) return; + if ((j & J_LEFT) && ship_x > 6) ship_x -= 2; + if ((j & J_RIGHT) && ship_x < 298) ship_x += 2; + if (j & J_FIRE) { + if (!shot_on && !fire_held) { + shot_on = 1; shot_x = ship_x + 8; shot_y = SHIP_Y; + } + fire_held = 1; + } else fire_held = 0; + spr_at(SP_SHIP, ship_x, SHIP_Y, S_SHIP, 1); +} + +static void shot(void) +{ + if (!shot_on) return; + shot_y -= 6; + if (shot_y < 16) { shot_on = 0; spr_off(SP_SHOT); return; } + shot_vs_formation(); + if (shot_on) spr_at(SP_SHOT, shot_x - 8, shot_y - 8, S_SHOT, 1); +} + +static void booms(void) +{ + u8 i; + for (i = 0; i < NX; i++) { + if (!xt[i]) { spr_off(SP_BOOM + i); continue; } + xt[i]--; + spr_at(SP_BOOM + i, xx[i], xy[i], + xship[i] ? S_SHIPBOOM : (xt[i] & 4) ? S_BOOM1 : S_BOOM2, xt[i] ? 1 : 0); + } +} + +static u8 aliens_left(void) +{ + u8 r, c, n = 0; + for (r = 0; r < ROWS; r++) for (c = 0; c < COLS; c++) if (cell[r][c]) n++; + return n; +} + +static void new_wave(void) +{ + u8 r, c, i; + for (r = 0; r < ROWS; r++) + for (c = 0; c < COLS; c++) cell[r][c] = layout[r][c] ? C_HOME : C_EMPTY; + for (i = 0; i < ND; i++) { dv_on[i] = 0; spr_off(SP_DIVER + i); } + for (i = 0; i < NB; i++) { b_on[i] = 0; spr_off(SP_BUL + i); } + shot_on = 0; spr_off(SP_SHOT); + sway = 0; sway_dir = 1; flap = 0; flap_timer = 24; + dive_timer = 120; attacks = 0; + draw_formation(); +} + +/* ------------------------------------------------------------- screens */ +static void clear_all(void) +{ + gfill = 0; + while (gfill & 1); + all_off(); +} + +static u8 wait_fire(void) +{ + u8 j; + while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); stars(); } + for (;;) { + wait_frame(); drain_keys(); rnd(); stars(); + j = joy; + if (j & J_ESC) return 0; + if (j & (J_FIRE | J_ENTER)) return 1; + } +} + +static u8 title(void) +{ + clear_all(); + puts_("\033[0m\033[2J"); + sway = 0; + set_scroll(); + blit(112, 150, S_FLAG, 0); blit(136, 150, S_ESCORT, 0); + blit(160, 150, S_WARRIOR, 0); blit(184, 150, S_DRONE, 0); + spr_at(SP_SHIP, 152, 200, S_SHIP, 1); + ink("1;93"); centre(7, "S T A R S W A R M"); + ink("0;97"); + centre(10, "The swarm sways overhead, and peels off to dive at you."); + centre(11, "A flagship dives with its escorts: shoot them first for a bonus."); + centre(13, "LEFT / RIGHT move SPACE fire P pause ESC give up"); + ink("0;37"); + centre(16, " 60 / 150 50 / 100 40 / 80 30 / 60 "); + centre(17, " IN FORMATION / DIVING"); + ink("1;96"); centre(28, "PRESS SPACE TO BEGIN"); + ink("0"); + return wait_fire(); +} + +static void play(void) +{ + u8 j, i; + lives = 3; score = 0; wave = 1; next_extra = 7000; + ship_x = 152; dead = 0; fire_held = 1; + for (i = 0; i < NX; i++) xt[i] = 0; + clear_all(); + puts_("\033[2J"); + new_wave(); + msg = 0; say("HERE THEY COME"); + hud(); + for (;;) { + wait_frame(); + set_scroll(); + if (drain_keys()) { + at(1, 60); ink("0;93"); puts_("PAUSED - P TO GO ON\033[K"); ink("0"); + for (;;) { + wait_frame(); + if (joy & J_ESC) { quit = 1; return; } + if (drain_keys()) break; + } + hud_dirty = 1; + } + j = joy; + if (j & J_ESC) return; + /* sway: a pixel every other frame, turning at the ends */ + if (last_frame & 1) { + sway += sway_dir; + if (sway >= 44 || sway <= -44) sway_dir = -sway_dir; + } + if (!--flap_timer) { + flap_timer = 24; flap ^= 1; + draw_formation(); + } + if (!dead && !--dive_timer) { + i = aliens_left(); + dive_timer = (i < 8 ? 30 : 100 - (wave < 6 ? wave * 10 : 60)) + (rnd() & 31); + launch(); + } + ship(j); + shot(); + divers(); + bullets(); + booms(); + stars(); + if (msg_time && !--msg_time) hud_dirty = 1; + if (hud_dirty) hud(); + if (dead && !--dead_time) { + if (!--lives) { + hud(); + ink("0;44;97"); + centre(14, " "); + centre(15, " GAME OVER "); + centre(16, " "); + ink("0"); + for (i = 0; i < 150; i++) { wait_frame(); drain_keys(); stars(); } + return; + } + dead = 0; ship_x = 152; fire_held = 1; + hud_dirty = 1; + } + if (!aliens_left() && !dead) { + say("SWARM DESTROYED"); + hud(); + for (i = 0; i < 120; i++) { wait_frame(); drain_keys(); stars(); booms(); } + wave++; + new_wave(); + hud_dirty = 1; + } + } +} + +int main(void) +{ + u8 i; + rnd_state = 0x1979 ^ frame_ctr; + last_frame = frame_ctr; + puts_("\033[?3l\033[?25l"); + load_shapes(); + for (i = 0; i < NST; i++) { st_x[i] = rnd() % 304; st_y[i] = rnd() % 240; st_v[i] = 1 + (i & 1); } + quit = 0; + while (!quit) { + if (!title()) break; + play(); + } + clear_all(); + puts_("\033[0m\033[2J\033[H\033[?25h"); + while (con_stat & 1) (void)con_data; +} diff --git a/games/swarm/swarm.ihx b/games/swarm/swarm.ihx new file mode 100644 index 0000000..b969355 --- /dev/null +++ b/games/swarm/swarm.ihx @@ -0,0 +1,720 @@ +:10A2000097320000938242CD17330000130383E19D +:10A2100063F8620023A00200938242006FF05FFFA8 +:10A2200017130000670083EA834700F093F72700C5 +:10A23000E38C07FEA300A0F067800000130101FF7C +:10A240002324810023261100130405000345040084 +:10A25000631A05008320C10003248100130101015A +:10A26000678000001304140097000000E78000FCE2 +:10A270006FF0DFFD130101FE232C8100232A9100E2 +:10A28000232E110093840500130400009306A00000 +:10A29000130690003377D5029307040093870701D4 +:10A2A000B3872700130414001374F40F1307070374 +:10A2B000238CE7FE930705003355D502E36CF6FCCB +:10A2C000636E9400631804028320C101032481019A +:10A2D000832441011301010267800000130500037C +:10A2E0009384F4FF97000000E78040F493F4F40FA8 +:10A2F0006FF01FFD1304F4FF1374F40F93070401B0 +:10A30000B387270003C587FF97000000E78000F2AE +:10A310006FF05FFB130101FF2322910093040500FE +:10A320001305B001232611002324810013840500A6 +:10A3300097000000E78080EF1305B005970000004C +:10A34000E780C0EE9305000013850400970000002D +:10A35000E78080F21305B00397000000E78000ED6E +:10A36000130504009305000097000000E780C0F08B +:10A37000032481008320C10083244100130580044D +:10A380001301010117030000670043EA130101FFF5 +:10A3900023248100130405001305B00123261100B6 +:10A3A00097000000E78080E81305B00597000000E3 +:10A3B000E780C0E71305040097000000E78040E84D +:10A3C000032481008320C1001305D006130101017D +:10A3D00017030000670083E5130101FF23248100B8 +:10A3E0002326110013840500930700003307F400AF +:10A3F00003470700631A070293D7170093059002DB +:10A40000B385F54093F5F50F97000000E780C0F0A5 +:10A4100013050400032481008320C10013010101FE +:10A42000170300006700C3E19387170093F7F70F46 +:10A430006FF0DFFBB7D7000003D5C7ED131775002A +:10A440003345E50013150501135505011357950014 +:10A450003345E500131785003345E5001315050165 +:10A4600013550501239EA7EC67800000B7D70000B5 +:10A4700003C707EE834680F7E38EE6FE034780F7C7 +:10A480002380E7EE678000001305000093060005B7 +:10A49000834700F093F7170063940700678000007C +:10A4A000034710F01377F70D6304D70093070500F7 +:10A4B000138507006FF0DFFDB7C70000938747657E +:10A4C000131676003306F600135385009307000039 +:10A4D0001375F50F930800012308A0F23387F500E8 +:10A4E0001377F70FA30860F22309E0F21307800047 +:10A4F00013080000639606000348060013061600C2 +:10A50000135E4800A309C0F31378F8001307F7FFA0 +:10A51000A30900F31377F70FE31C07FC93871700D9 +:10A5200093F7F70FE39A17FB678000001306A0006C +:10A530003306C502B7D70000938747FE37C7000030 +:10A5400013154500B387C700B387B70083C607005C +:10A55000B7C700009387875DB387C700B387B7008D +:10A5600003C607009307075D13074001B387C700C1 +:10A5700003C60700B7D7000083C797EE9386F6FFA0 +:10A58000B336D0003306F600930745023385E50263 +:10A590001376F60F93F5C70F1305E50313150501A1 +:10A5A0001355050117030000670043F1130101FE75 +:10A5B0002328210137C90000232C810023263101E3 +:10A5C00023244101232E1100232A91001309895DC0 +:10A5D000130400009309A000130A60009304000014 +:10A5E000B307990083C70700638A070093F5F40F48 +:10A5F0001305040097000000E78080F393841400A3 +:10A60000E39034FF130414001374F40F1309A9002A +:10A61000E31644FD8320C101032481018324410109 +:10A62000032901018329C100032A810013010102CA +:10A6300067800000B7D7000003D7C7EEB307E0403C +:10A640009397070193D7074163DA07009307001434 +:10A65000B387E7409397070193D7074113F7F70FA5 +:10A6600093D78740A30AE0F293F7F70F230BF0F29A +:10A67000A30B00F267800000B7D70000930600002C +:10A6800013070000938787F113034000B388F60097 +:10A690003308F70083C808000348080063F4080182 +:10A6A00013F7F60F93861600E39266FEB7D6000006 +:10A6B00013181700938646F2B38606012390A6006E +:10A6C000B7D600009386C6F1B38606012390B60084 +:10A6D00093062001630406009306C003B387E700D6 +:10A6E0002380D700B7D70000938747F1B387E700EF +:10A6F0002380C70067800000130101FFB7D7000067 +:10A70000930510001305100023261100238F07EC7A +:10A71000232481002322910097000000E780C0BF1E +:10A7200037C500001305453497000000E78040C698 +:10A7300037C500001305C53497000000E78040B01E +:10A74000B7C400001385C43597000000E78040C4FB +:10A7500037C500001305453697000000E78040AE7E +:10A7600037C400001305C43697000000E78040C2DC +:10A77000B7D7000003D5C7FD930560009700000020 +:10A78000E78080AF1385C43597000000E78040C0A4 +:10A7900037C500001305453797000000E78040AA41 +:10A7A0001305C43697000000E78080BEB7D70000CD +:10A7B00003C517FE9305000097000000E780C0ABBB +:10A7C0001385C43597000000E78080BC37C50000C2 +:10A7D0001305053897000000E78080A61305C436EE +:10A7E00097000000E780C0BAB7D7000003C507FE96 +:10A7F0009305000097000000E78000A8B7D700008D +:10A8000003A487ED630E0402B7D7000083C747EDAA +:10A810006388070237C500001305C538970000009C +:10A82000E78000B737C500001305453997000000E1 +:10A83000E78000A11305040097000000E78040A016 +:10A8400037C500001305853997000000E780409F59 +:10A85000032481008320C1008324410037C5000008 +:10A860001305053C1301010117030000670043B203 +:10A87000B7D7000003D7C7FDB7D600003305E50002 +:10A880001315050113550501239EA7FC83D726EE5A +:10A890006360F50437270000130787B5B387E70027 +:10A8A00037D700002391F6EE834717FE93871700F2 +:10A8B000A300F7FEB7C7000037D700009387C7395A +:10A8C000232CF7ECB7D7000013078007238AE7ECA7 +:10A8D000B7D7000013071000238FE7EC6780000054 +:10A8E000130101FEB7D70000232C8100232A910019 +:10A8F0002328210193040500232E110013090600CB +:10A9000013040000938747FD130580003307F4000C +:10A9100003460700631C0618930710002300F70086 +:10A9200013064001B7D700003386C5029387C7FAE4 +:10A93000B387870023809700B7D70000938747FA33 +:10A94000B38787002380B700B7D7000083D7C7EE4F +:10A9500037D70000131514009387E703B387C700A8 +:10A96000130747FC3307A700939747002310F7000E +:10A970009397440037D7000093874702130747FB9C +:10A9800093F7F70F3307A700939747002310F700BB +:10A99000B7D700009387C7F9B38787001307000371 +:10A9A0002380E700B7D70000938747F7B387870076 +:10A9B0002380D700B7D70000938747F913076001BA +:10A9C000B38787002380E700B7D700009387C7F8D5 +:10A9D000B38787002326B10023800700970000007B +:10A9E000E78080A5B7D70000938747F81375F50176 +:10A9F000B3878700130545012380A700B7D7000060 +:10AA000003C707FE930720008325C10033B7E70083 +:10AA1000B7D700009387C7F713072700B3878700CE +:10AA20002380E700B7D700009387C7F6B387870076 +:10AA300023802701B7D70000938747F63387870025 +:10AA40002300070037D700001307C7F53307870037 +:10AA5000230007001307F00F630AE900B3872701FB +:10AA600003C70700130717002380E7001307A000A0 +:10AA70003387E402B7D70000938747FE13850400AD +:10AA8000B387E700B387B700130720002380E700F0 +:10AA9000032481018320C101832441010329010191 +:10AAA0001301010217030000670083A813041400B8 +:10AAB000E31EA4E48320C101032481018324410116 +:10AAC000032901011301010267800000B7D70000CC +:10AAD000938747FE9386C703130500001306A00063 +:10AAE00013070000B385E70083C5050063860500F2 +:10AAF000130515001375F50F13071700E314C7FEB0 +:10AB00009387A700E39ED7FC6780000037D600003C +:10AB1000B7C5000093060000130646FE9385855DC9 +:10AB20001308C003138706009307A0003305B7007E +:10AB300003450500B308C7009387F7FF3335A0002E +:10AB40002380A80093F7F70F13071700E39007FE81 +:10AB50009386A600E39806FD37D70000130747FD4C +:10AB6000930720009306A000230007002308F0F6B7 +:10AB700093871700A30A00F693F7F70F1307170040 +:10AB8000E394D7FE37D700001307C7F293060001FE +:10AB9000230007002308F0F693871700A30A00F6A6 +:10ABA00093F7F70F13071700E394D7FEB7D700000A +:10ABB000238A07F4930710002308F0F6A30A00F68F +:10ABC00037D70000231607EE37D700002305F7EE2E +:10ABD000B7D7000013078001A38407EEB7D70000A2 +:10ABE0002384E7EEB7D7000013078007A383E7EEBF +:10ABF000B7D70000238307EE170300006700439BCD +:10AC0000230A00F2834740F393F71700E39C07FE03 +:10AC1000130700022308F0F693871700A30A00F633 +:10AC200093F7F70FE398E7FE678000009387F5003E +:10AC3000939707012308A0F693D707011305E014A3 +:10AC4000636CF5009307F6009397070193D707010C +:10AC50001305E00F6376F500A30A00F66780000095 +:10AC600093F7F50F93D58540A308F0F693F51500FB +:10AC70002309B0F61376F60FA309C0F6230AD0F61F +:10AC8000A30AE0F667800000130101FD232481027E +:10AC900023229102232E310137D40000B7D40000C3 +:10ACA000B7D9000023202103232C4101232A51017D +:10ACB0002328610123267101232611022324810107 +:10ACC0001304C4EF938484F013090000938909EFFF +:10ACD000130BF00E930B0013930A3000130AA0001D +:10ACE000B307390183C7070003470400137CF90F3A +:10ACF000B387E70093F7F70F6366FB062300F400C2 +:10AD0000B3765C030346040083C5040013054C01BD +:10AD1000130710001375F50F13091900130414001D +:10AD2000938414009386E60097000000E78040F0CB +:10AD3000E31849FB8320C1020324810283244102DA +:10AD4000032901028329C101032A8101832A4101C8 +:10AD5000032B0101832BC100032C8100130101038C +:10AD600067800000938707012300F40097F0FFFF3E +:10AD7000E780806C337575032380A4006FF05FF863 +:10AD8000130101FE232A91002328210123263101EA +:10AD900023244101B7D4000037DA0000B7D90000FE +:10ADA00037D90000232C810023225101232E1100CA +:10ADB000938484F1130A4AF29389C9F1130949F182 +:10ADC00013040001930A400103C70400631607043B +:10ADD000230880F6A30A00F6130414001374F40F7A +:10ADE00093841400130A2A00938929001309190077 +:10ADF000E31C54FD8320C10103248101832441010C +:10AE0000032901018329C100032A8100832A41000B +:10AE100013010102678000001307F7FF8347090051 +:10AE20001377F70F2380E40083150A0003960900C7 +:10AE30009306D000639807009376470093B61600F8 +:10AE40009386B6003337E000130504009700000036 +:10AE5000E78000DE6FF05FF837D70000B7D600005C +:10AE60008347F7FD83C6E6FDB3E7D700639E070A75 +:10AE700093071000130101FFA30FF7FC130720F83D +:10AE8000B7D70000A382E7EEB7D70000039527FEEF +:10AE9000130610009305600D2326110097F0FFFFA5 +:10AEA000E780C07D37D70000230800F6A30A00F62C +:10AEB0001307C7F29307A0009306000123000700C1 +:10AEC0002308F0F693871700A30A00F693F7F70F0D +:10AED00013071700E394D7FEB7D70000B7D60000DA +:10AEE0009387C7F813070000938646FD930520005B +:10AEF00013051000130680003308D700034808002C +:10AF00006308080003C807006304B8002380A70093 +:10AF10001307170093871700E310C7FE8320C100B3 +:10AF2000130101016780000067800000B7D70000AF +:10AF3000130101FE9387C7FA232C8100232E1100F1 +:10AF4000232A91002328210123263101B387A7005A +:10AF500083C907001307A000B7D700003387E902B1 +:10AF6000938747FAB387A70003C90700B7C7000054 +:10AF70009387875D13040500B387E700B387270134 +:10AF800083C60700B7D700009387C7F6B387A7002B +:10AF900003C70700B7C700009387075CB387D700D4 +:10AFA00003C5070093074000639EF604B7D700006F +:10AFB000938747F6B387870083C607006384060438 +:10AFC000B7D700009387C7F5B387870083C707000B +:10AFD0001305C0126398D702B7C70000B7D60000A8 +:10AFE0009387873A23ACF6ECB7D700009306800727 +:10AFF000238AD7ECB7D7000093061000238FD7EC35 +:10B0000013050032B7D400009307F00F938444FD7A +:10B010006304F702B387E40083C70700638E070069 +:10B02000B7D700009387C7F5B387E70003C70700CA +:10B03000130717002380E70097000000E780808354 +:10B04000B7D7000013171400938747FBB387E700B7 +:10B0500083950700B7D70000938747FCB387E700C5 +:10B06000039507001306000093D54540135545404E +:10B0700097F0FFFFE78080601307A000B389E90223 +:10B08000B7D70000938747FEB384840013042400DD +:10B09000238004001374F40FB3873701B3872701AB +:10B0A00023800700230880F6A30A00F68320C1014D +:10B0B0000324810183244101032901018329C10063 +:10B0C0001301010267800000130101F92326110614 +:10B0D000232481062322910623202107232E3105D4 +:10B0E000232C4105232A51052328610523267105B8 +:10B0F00023248105232291052320A105232EB103BA +:10B10000834780F73727000013079797B3C7E700F7 +:10B1100037D70000231EF7EC834780F737C50000C0 +:10B1200037D700001305453C2300F7EE97F0FFFFEB +:10B13000E7800011B7C70000938747651307000039 +:10B1400093061001230BE0F61386070883C507005A +:10B1500093871700A30BB0F6E39AC7FE13071700F7 +:10B160001377F70FE310D7FEB7D9000037D90000E7 +:10B17000B7D4000013040000938989F0130A001368 +:10B180001309C9EF130B000F938404EF930AA00077 +:10B1900097F0FFFFE780402A33754503B30734017A +:10B1A0002380A70097F0FFFFE78000293375650330 +:10B1B000B3072401330794002380A700937714007A +:10B1C000938717002300F70013041400E31254FDC3 +:10B1D000B7D70000A38F07ECB7C7000093870754C9 +:10B1E0002322F102B7D700009387C7FA232AF10080 +:10B1F000B7D7000083C7F7ED6398071C97000000DE +:10B20000E78040A037C500001305053D37DD00008D +:10B2100097F0FFFFE780C00223160DEE97F0FFFFC7 +:10B22000E7808041930600001306600093056009E3 +:10B230001305000797F0FFFFE78040289306000002 +:10B2400013064000930560091305800897F0FFFF7F +:10B25000E780C026930600001306200093056009CE +:10B260001305000A97F0FFFFE780402593060000D2 +:10B2700013060000930560091305800B97F0FFFF8C +:10B28000E780C023930780F9230800F6A308F0F6AF +:10B29000230900F6930780FCA309F0F693078000CA +:10B2A000230AF0F637C5000093071000A30AF0F652 +:10B2B0001305C53D97F0FFFFE780800DB7C500007F +:10B2C0009385453E1305700097F0FFFFE78000115E +:10B2D00037C500001305C53697F0FFFFE780400B28 +:10B2E000B7C500009385853F1305A00097F0FFFFC9 +:10B2F000E780C00EB7C50000938505431305B00075 +:10B3000097F0FFFFE780800DB7C5000093854547A4 +:10B310001305D00097F0FFFFE780400C37C5000011 +:10B320001305C53597F0FFFFE7808006B7C500001D +:10B330009385454B1305000197F0FFFFE780000A56 +:10B34000B7C500009385054F1305100197F0FFFF67 +:10B35000E780C00837C500001305C55097F0FFFF10 +:10B36000E7800003B7C500001305C0019385455170 +:10B3700097F0FFFFE7808006B7C700001385073C02 +:10B3800097F0FFFFE780C000834780F893F7070B33 +:10B39000639E070897F0FFFFE780800D97F0FFFF9F +:10B3A000E780C00E97F0FFFFE780000997000000DC +:10B3B000E780C08D834780F813F7F70F93978701D5 +:10B3C00093D7874163D2070897000000E780808306 +:10B3D00037C500001305C55297F0FFFFE78040E630 +:10B3E000834700F093F71700E39807728320C106A4 +:10B3F0000324810683244106032901068329C1050C +:10B40000032A8105832A4105032B0105832BC104EF +:10B41000032C8104832C4104032D0104832DC103DB +:10B4200013050000130101076780000097F0FFFF7C +:10B43000E780000497F0FFFFE780400597000000D9 +:10B44000E780C0846FF05FF493770703E38407F429 +:10B450009307300037D70000A300F7FEB7D70000EE +:10B46000239E07FCB727000037D70000938787B5D6 +:10B470002311F7EE37D400009307800993041000DE +:10B480002311F4FEB7D70000238297EEB7DC00004B +:10B49000B7D70000B7D9000023AC07F023809CFE8B +:10B4A000A38F09FC97F0FFFFE780C07537C5000048 +:10B4B0001305453D97F0FFFFE78080D897F0FFFF29 +:10B4C000E780006503274102B7D7000023ACE7EC13 +:10B4D000B7D7000013078007238AE7ECB7D700002F +:10B4E000238F97EC97F0FFFFE7804021B7D700004C +:10B4F000938747FD2328F100B7D70000938747FAC9 +:10B500002320F10297F0FFFFE78080F697F0FFFF1E +:10B51000E780801297F0FFFFE78040F7630205089D +:10B520009305C0031305100097F0FFFFE780C0DE0E +:10B5300037C500001305453497F0FFFFE78040E56D +:10B5400037C500001305055597F0FFFFE78040CF92 +:10B55000B7C700001385073C97F0FFFFE78040E383 +:10B5600097F0FFFFE780C0F0834780F8939787014B +:10B5700093D7874163DA07009307100037D700009D +:10B58000A30FF7EC6FF0DFC697F0FFFFE78000F046 +:10B59000E30805FCB7D7000013071000238FE7EC82 +:10B5A000834780F813F9F70F9397870193D7874163 +:10B5B000E3C007C4B7D7000083C707EE93F71700AF +:10B5C000638E0702B7D600008357CDEE0387A6EE41 +:10B5D00013066005B387E7009397070193D7070128 +:10B5E0002316FDEE9387B7029397070193D70701C0 +:10B5F0006376F6003307E0402385E6EE37D7000098 +:10B60000834787EE9387F7FF93F7F70F638C070A5B +:10B610002304F7EE83C7F9FD63900724B7DA00002F +:10B6200083C47AEE9384F4FF93F4F40FA3839AEE29 +:10B63000638C040A937749006390074293778900EB +:10B64000638C0700831724FE130790126346F700EC +:10B65000938727002311F4FE1379090137D70000DF +:10B6600063000904B7D60000834747EE03C646F5DA +:10B67000B3E7C70063940702831724FE1306100084 +:10B68000238AC6F493878700B7D60000239CF6F47C +:10B69000B7D700009306600D239BD7F41309100061 +:10B6A000831524FE230227EF930680001307100062 +:10B6B0001306600D1305000097F0FFFFE780405769 +:10B6C0006F008019930780012304F7EE37D700003D +:10B6D000834797EE93C71700A304F7EE97F0FFFF99 +:10B6E000E78000ED6FF01FF397F0FFFFE780403E2B +:10B6F00093077000130AE00163F2A70283C70CFEF0 +:10B7000013075000130A8002636AF700130760FFF3 +:10B71000B387E7029387470613FAF70F97F0FFFF07 +:10B72000E78080D183C70CFE1375F501330AAA00A8 +:10B730009387270013F7F70FA3834AEF93F7F70FC9 +:10B740009306800063F4F60013078000930700005F +:10B75000930600001306800083250101B385B6001F +:10B7600083C50500638605009387170093F7F70FDD +:10B7700093861600E392C6FE63FCE70C37D7000001 +:10B78000834767EE37DA0000130A4AFE93871700F3 +:10B7900093F7F70F2303F7EE93F73700639207222F +:10B7A00097F0FFFFE78040C913751500130B600089 +:10B7B00063040500130B3000B3076A0103C70700D9 +:10B7C000930710006308F70093079000B387674161 +:10B7D00013FBF70FB3076A0103C7070093071000B5 +:10B7E0006310F71E930740009304F0FF63E46701C2 +:10B7F00093041000938604001306F00F93050B00CA +:10B800001305000097F0FFFFE780C00D37D7000059 +:10B8100093070000130747FA9306800003260101EF +:10B820003306F600034606006300060203264101C4 +:10B830003386C70003460600631806003386E70018 +:10B8400003460600E30E662D93871700E398D7FCA6 +:10B8500083C7F9FDE38007DE37D90000834749F548 +:10B86000638A070237DA000083546AF51307F00091 +:10B870009387A4FF9397070193D70741231BFAF4FB +:10B880006348F71E230A09F4930710002308F0F613 +:10B89000A30A00F68327010137DA0000B7D40000BD +:10B8A0002324F100B7D700009387C7F72326F100C0 +:10B8B000B7C700009387075D232CF100B7C70000CE +:10B8C00037DB000037D80000B7DA000037DC0000B3 +:10B8D0009387875D130A4AFC938444FB130BCBF8D0 +:10B8E000930DC8F9938A4AF9130C4CF8930B000096 +:10B8F000232EF1008327810083C70700638407603C +:10B90000832741011306100083960400B387FB00D0 +:10B9100003C707008327010213F9FB0FB387FB005E +:10B9200083C5070083470B006380C72C13052000E5 +:10B930006388A75463960746B7D60000938646F7F8 +:10B94000B386DB0083C70D0083C60600B387D740EC +:10B9500093F7F7032380FD00930600016392D74419 +:10B9600083C60CFE2300CB001306800093870600DD +:10B970006374D600930780009387F70093971700AE +:10B980002380FA006F00C041B3077A0183C7A70084 +:10B99000639EB7019386040013860A0093F5FB0F9C +:10B9A0001305100097F0FFFFE780C0F3938B1B0097 +:10B9B000E3407BEB83470C00E3F8FDFC6FF05FE9AD +:10B9C00097F0FFFFE78040A7937A15009307900058 +:10B9D000930D1000130CA0009385040063860A00E9 +:10B9E000B385974093F5F50F330BBA00930B5000D6 +:10B9F00003472B036312B7052324B10097F0FFFF21 +:10BA0000E78080A3137515008325810093079000BC +:10BA100063140502930740009306F0FF63E4B70048 +:10BA2000930610001306F00F13850B0097F0FFFF2D +:10BA3000E78040EB6FF0DFE1938BFBFF93FBFB0FA5 +:10BA4000130B6BFFE3960BFA9384140093F4F40F3B +:10BA5000E39484F96FF0DFDF831724FE130760009F +:10BA6000E35EF7BC9387E7FF2311F4FE6FF01FBD81 +:10BA7000B7DA000083D78AF5035BCDEE938747FCE6 +:10BA8000B38767419397070193D7074163DE0702A6 +:10BA900003566AF583D58AF513071000130686FF4F +:10BAA000938585FF13160601939505019306900073 +:10BAB0001356064193D505411305100097F0FFFF7B +:10BAC000E78000176FF01FDD938464FD93960401F7 +:10BAD0009394040193D4044193D60601E3CA04FA73 +:10BAE00013064001B3CBC7021307900093FDFB0F71 +:10BAF000E360B7FB93D4444093F4F40F93055000F4 +:10BB0000E3E895F8B3E7C7021306D0009387D7FFA1 +:10BB10009397070193D70701E36CF6F693F7F600C6 +:10BB20009387E7FF9397070193D70701E362F7F63F +:10BB30001307A0003387E402B7D70000938747FEBE +:10BB400093061000B387E700B387B70103CC070063 +:10BB5000E310DCF493850D00138504002324E10039 +:10BB60002380070097F0FFFFE780809C0327810078 +:10BB7000B7C700009387875DB387E700B387B70136 +:10BB800083C70700B7C600009386865CB386F600BD +:10BB900003C50600130BEB0397F0FFFFE78080CD92 +:10BBA0009307400113F5FB0F3305F502939544000D +:10BBB000938545021306000093F5C50F3305650113 +:10BBC000131505011355054197F0FFFFE78000AB02 +:10BBD000230A09F4230880F7A30A00F6834749F5EE +:10BBE000E38A07CA6FF0DFEAB7D7000083C707EE22 +:10BBF00003C6F9FD83180A0093F73700B367F60010 +:10BC0000639C0702835724FE13D54840938787001F +:10BC1000B387A7409397070193D7074113056000A7 +:10BC20006356F50483C70D00130590006376F50095 +:10BC30009387F7FF2380FD0083470C0093D646408F +:10BC4000638407049387F7FF2300FC009307400FEA +:10BC500063D8D714930720002300FB00930700F05C +:10BC60002390F400930780016FF09FD11305A0FF8C +:10BC7000E3D4A7FC83C70D0013056001E36EF5FA5A +:10BC8000938717006FF01FFB8327C10003C50700D0 +:10BC9000E30E05FA9307600463D4D7109307900A64 +:10BCA000E3C6D7FA631E060E93D84840939808015E +:10BCB00093D80801138388009386C60013130301E9 +:10BCC00093960601B7D700001353034193D606415C +:10BCD0009387C7F2130F6000330EF600834E0E00F9 +:10BCE00063940E08930710002300FE00B7D70000EE +:10BCF000131E1600938787F4B387C701931E430072 +:10BD00002390D701B7D700009387C7F3B387C70144 +:10BD1000939646002390D700831724FE130E6000ED +:10BD20009386770063D46600130EA0FFB387174194 +:10BD30009396070193D6064193D6F640B3C7F60013 +:10BD4000B387D74093970701B7D60000938646F391 +:10BD500093D7074193083001B386C60063DEF8101D +:10BD60002380C6016F00C00013061600E316E6F735 +:10BD70008327C1001305F5FF2326B1022380A70006 +:10BD80002324E10297E0FFFFE780006B1375F500C5 +:10BD9000032781028325C102130505012300AC009E +:10BDA00083460B0093072000638AF60483C80D00C6 +:10BDB000B7C60000938646619387080193F7F7039F +:10BDC000B387F60003C50A008387070003530A0000 +:10BDD000B3861601B387A7020396040093D7674082 +:10BDE000B38767002310FA0083870600B387A70292 +:10BDF00093D76740B387C7002390F40083180A00E5 +:10BE00000396040083C7F9FD93D848401356464073 +:10BE100063980720835724FEB387F8409396070161 +:10BE200093D6064193D6F640B3C7F600B387D74002 +:10BE30009397070193D707419306A00063C2F61EAC +:10BE40009307A6F293D6F741B3C7F600B387D7405E +:10BE50009397070193D707019306900063E2F61CBE +:10BE60001305090097F0FFFFE780800C97F0FFFFB4 +:10BE7000E780C0FE6F000009238006006FF05FEFCF +:10BE8000130540013385A5028357CDEE9387E70361 +:10BE9000B387A700939747002310FA0083C70A00CF +:10BEA000B386F600931747009396060193874702DF +:10BEB00093D6064193F7F70F2390D400939747004A +:10BEC000E3C0F6EE9306A000B306D70283278100F5 +:10BED000130929001305070023800700B7D70000C6 +:10BEE000938747FE1379F90FB387D700B387B7005D +:10BEF0002380C70097E0FFFFE7808063230820F7D7 +:10BF0000A30A00F683278100938B1B00130A2A00E3 +:10BF1000938717002324F1008327C1009384240012 +:10BF2000130B1B00938717002326F1009307800053 +:10BF3000938D1D00938A1A00130C1C00E39CFB9A3E +:10BF4000B7DB0000B7DD000037D8000037DC0000A9 +:10BF5000938BCBF2938D8DF4130948F3130CCCF330 +:10BF60009304A000130A80FF930A6000130B900053 +:10BF700083C70B00638407048307090083D50D0082 +:10BF80001307000FB385F50083570C009395050147 +:10BF900093D50541938707039397070193D70741EB +:10BFA0002310FC002390BD0093D74740635EF71435 +:10BFB00023800B00230890F6A30A00F613851400D3 +:10BFC0009374F50F93070001938B1B00938D2D0045 +:10BFD00013091900130C2C00E39CF4F897F0FFFFF1 +:10BFE000E78040DA37D9000097F0FFFFE78000CA0A +:10BFF000834749EDB7D400006388071A9387F7FF9A +:10C0000093F7F70F230AF9EC6390071A93071000D0 +:10C01000238FF4EC97E0FFFFE780406E6F0040193C +:10C02000B7D6000083C746F563840708B7D700007A +:10C0300083D787F513037000938787FFB387174172 +:10C0400013950701135505411355F540B347F50006 +:10C05000B387A7409397070193D70741634AF30437 +:10C06000B7D7000083D767F5938797FFB387C7409B +:10C0700013950701135505411355F540B347F500D6 +:10C08000B387A7409397070193D707416342F30211 +:10C09000238A06F4930710002308F0F6130509001D +:10C0A000A30A00F697F0FFFFE78080E86FF09FE5B6 +:10C0B000B7D7000083C607EE9307A0003307F70247 +:10C0C0008327C10193D6360093F616001305290085 +:10C0D0001375F50F3387E7003307B7008347070071 +:10C0E0000327810193850800B307F70083C7070082 +:10C0F00013071000B386F60093F6F60F97F0FFFFD4 +:10C10000E78000B36FF01FE01396070183C7F9FDC6 +:10C1100093D54540939505011356060193D5050126 +:10C12000639C0704835724FEB307FA40B387F500E6 +:10C1300013970701135707411357F740B347F70009 +:10C14000B387E7409397070193D7074163C6FA0285 +:10C15000930776F29397070193D70701636EFB006D +:10C1600023800B00230890F6A30A00F697F0FFFF48 +:10C17000E780C0CE6FF09FE4130686FF938585FFAE +:10C180001316060193950501130710009306A000EE +:10C190001356064193D505411385040097F0FFFF20 +:10C1A000E78000A96FF09FE183C7E4EDE39407E621 +:10C1B00083C7F9FD638E070C37D70000834757EE1E +:10C1C0009387F7FF93F7F70FA302F7EE6392070C3D +:10C1D00037D70000834717FE9387F7FF93F7F70FD2 +:10C1E000A300F7FE6398070897E0FFFFE780005180 +:10C1F00037C500001305855697E0FFFFE78040191B +:10C2000037C40000930504571305E00097E0FFFFD3 +:10C21000E780C01CB7C50000938505591305F000E1 +:10C2200097E0FFFFE780801B93050457130500018B +:10C2300097E0FFFFE780801AB7C700001385073C2F +:10C2400097E0FFFFE780C0141304600997E0FFFF49 +:10C25000E78000221304F4FF97E0FFFFE78000234C +:10C260001374F40F97F0FFFFE78040A2E31004FE81 +:10C270006FE01FF8930780092311F4FE37D7000001 +:10C2800093071000A38F09FC2302F7EE238FF4EC31 +:10C2900097F0FFFFE780C08383C7F9FD3365F500A2 +:10C2A0001375F50F631005A6B7C700009387075BEA +:10C2B00037D70000232CF7EC93078007230AF9EC0B +:10C2C00097E0FFFFE78080431309800797E0FFFFB7 +:10C2D000E780001A1309F9FF97E0FFFFE780001BD2 +:10C2E0001379F90F97F0FFFFE780409A97F0FFFF6F +:10C2F000E78040A9E31C09FC83C70CFE9387170065 +:10C300002380FCFE97F0FFFFE780808093071000FA +:10C31000238FF4EC6FF00F9F834710F06FF04F8C7A +:10C3200037DC0000930BFBFF130C4CF693FAF70F6E +:10C3300093FBFB0F130B1B00330CFC00930D100041 +:10C340006FF00FE7303B3933000000005354415287 +:10C3500020535741524D202020000000303B3337FE +:10C360000000000053434F5245200000303B393756 +:10C3700000000000202020534849505320000000B6 +:10C38000202020574156452000000000303B393620 +:10C3900000000000202020001B5B4B00424F4E5548 +:10C3A0005320534849500000464C41475348495098 +:10C3B00020414E44204553434F5254533A20383085 +:10C3C000300000001B5B3F336C1B5B3F32356C0061 +:10C3D0001B5B306D1B5B324A00000000313B393380 +:10C3E00000000000532054204120522020205320E0 +:10C3F0005720412052204D005468652073776172A8 +:10C400006D207377617973206F76657268656164FA +:10C410002C20616E64207065656C73206F666620E9 +:10C42000746F206469766520617420796F752E00C1 +:10C430004120666C61677368697020646976657312 +:10C44000207769746820697473206573636F7274F0 +:10C45000733A2073686F6F74207468656D20666925 +:10C4600072737420666F72206120626F6E75732E16 +:10C47000000000004C454654202F205249474854A4 +:10C48000206D6F76652020202020535041434520A9 +:10C4900066697265202020202050207061757365C8 +:10C4A0002020202020455343206769766520757041 +:10C4B0000000000020203630202F20313530202091 +:10C4C0002020202020203530202F20313030202007 +:10C4D0002020202020203430202F20383020202001 +:10C4E00020202020203330202F2036302020000034 +:10C4F00020202020494E20464F524D4154494F4E56 +:10C50000202F20444956494E47000000313B393620 +:10C5100000000000505245535320535041434520E2 +:10C52000544F20424547494E000000001B5B306DD0 +:10C530001B5B324A1B5B481B5B3F323568000000C7 +:10C5400048455245205448455920434F4D45000029 +:10C55000504155534544202D205020544F20474FE3 +:10C56000204F4E1B5B4B0000303B34343B393700CF +:10C5700020202020202020202020202020202020BB +:10C5800020202020202020202020202020200000EB +:10C590002020202020202020202047414D45204FD2 +:10C5A000564552202020202020202020202000003E +:10C5B000535741524D2044455354524F594544001E +:10C5C000003C506496000000001E28323C00000031 +:10C5D0000000020406000000000000040000040047 +:10C5E0000000000003030303030300000002020233 +:10C5F0000202020202000101010101010101010127 +:10C60000010101010101010101010101010101011A +:10C610000101010100060C13181E24292D313538A3 +:10C620003B3D3F4040403F3D3B3835312D29241EA6 +:10C6300018130C0600FAF4EDE8E2DCD7D3CFCBC830 +:10C64000C5C3C1C0C0C0C1C3C5C8CBCFD3D7DCE24E +:10C65000E8EDF4FA00000000000000000000000017 +:10C6600000000000000C00000000C0000000C0003E +:10C67000000C000000000CCCCCC000000000CC4C32 +:10C68000C4CC0000000CCCCCCCCCC0000CCCCCCCAE +:10C69000CCCCCCC00C0CCCCCCCCCC0C00C0C000096 +:10C6A0000000C0C00000CC0000CC00000000000072 +:10C6B000000000000000000000000000000000007A +:10C6C000000000000000000000000000000000006A +:10C6D000000000000000000000000000000000005A +:10C6E000000000000000C000000C00000000C000BE +:10C6F000000C000000000CCCCCC000000000CC4CB2 +:10C70000C4CC0000000CCCCCCCCCC00000CCCCCC39 +:10C71000CCCCCC000CCCCCCCCCCCCCC0C00C000055 +:10C720000000C00C000CC000000CC00000000000A5 +:10C7300000000000000000000000000000000000F9 +:10C7400000000000000000000000000000000000E9 +:10C7500000000000000000000000000000000000D9 +:10C7600000000000000D00000000D0000000D0001C +:10C77000000D000000000DDDDDD000000000DDBD7B +:10C78000DBDD0000000DDDDDDDDDD0000DDDDDDDFC +:10C79000DDDDDDD00D0DDDDDDDDDD0D00D0D0000EA +:10C7A0000000D0D00000DD0000DD0000000000002F +:10C7B0000000000000000000000000000000000079 +:10C7C0000000000000000000000000000000000069 +:10C7D0000000000000000000000000000000000059 +:10C7E000000000000000D000000D00000000D0009C +:10C7F000000D000000000DDDDDD000000000DDBDFB +:10C80000DBDD0000000DDDDDDDDDD00000DDDDDD88 +:10C81000DDDDDD000DDDDDDDDDDDDDD0D00D000099 +:10C820000000D00D000DD000000DD0000000000071 +:10C8300000000000000000000000000000000000F8 +:10C8400000000000000000000000000000000000E8 +:10C8500000000000000000000000000000000000D8 +:10C86000000000000009000000009000000090009F +:10C87000000900000000099999900000000099F952 +:10C880009F9900000009999999999000099999999F +:10C890009999999009099999999990900909000095 +:10C8A0000000909000009900009900000000000036 +:10C8B0000000000000000000000000000000000078 +:10C8C0000000000000000000000000000000000068 +:10C8D0000000000000000000000000000000000058 +:10C8E000000000000000900000090000000090001F +:10C8F000000900000000099999900000000099F9D2 +:10C900009F99000000099999999990000099999927 +:10C910009999990009999999999999909009000084 +:10C92000000090090009900000099000000000003C +:10C9300000000000000000000000000000000000F7 +:10C9400000000000000000000000000000000000E7 +:10C950000000000000000000000000000000000BCC +:10C96000B0000000000000BBBB00000000B00BB92D +:10C970009BB00B0000BB0BBBBBB0BB0000BBBBBB89 +:10C98000BBBBBB00000BB9BBBB9BB0000000BBBB7B +:10C99000BBBB000000000B9BB9B000000000B00062 +:10C9A000000B0000000B00000000B00000000000C1 +:10C9B0000000000000000000000000000000000077 +:10C9C0000000000000000000000000000000000067 +:10C9D0000000000000000000000000000000000B4C +:10C9E000B0000000000000BBBB00000000000BB95D +:10C9F0009BB00000B0BB0BBBBBB0BB0B0BBBBBBB4E +:10CA0000BBBBBBB0000BB9BBBB9BB0000000BBBB4A +:10CA1000BBBB000000000B9BB9B0000000000B0086 +:10CA200000B000000000B000000B0000000000009B +:10CA300000000000000000000000000000000000F6 +:10CA400000000000000000000000000000000000E6 +:10CA50000000000000000000000000000000000FC7 +:10CA6000F00000000000000FF0000000000000FFD8 +:10CA7000FF000000000000F99F00000000F00FFF21 +:10CA8000FFF00F0000F0FFFFFFFF0F0000FFFFFFB0 +:10CA9000FFFFFF0000FFF99FF99FFF0000FF00FF6D +:10CAA000FF00FF0000000000000000000000000088 +:10CAB0000000000000000000000000000000000076 +:10CAC0000000000000000000000000000000000066 +:10CAD0000000000000000000000000000000000056 +:10CAE0000000000000000000000000000000000046 +:10CAF0000000000000000000000000000000000B2B +:10CB0000B00000000000000BB00000000000000BAF +:10CB1000B00000000000000BB00000000000000B9F +:10CB2000B00000000000000BB0000000000000009A +:10CB300000000000000000000000000000000000F5 +:10CB400000000000000000000000000000000000E5 +:10CB500000000000000000000000000000000000D5 +:10CB600000000000000000000000000000000000C5 +:10CB700000000000000000000000000000000000B5 +:10CB80000000000000000009F00000000000000F9D +:10CB9000900000000000000990000000000000006C +:10CBA0000000000000000000000000000000000085 +:10CBB0000000000000000000000000000000000075 +:10CBC0000000000000000000000000000000000065 +:10CBD0000000000000000000000000000000000055 +:10CBE00000000000000000000000000000000099AC +:10CBF0000000000000000990909000000000000B71 +:10CC0000B0B9000000009BB0FB000000000090FFE6 +:10CC1000FBB9900000000BFFFFB0000000000B0FFD +:10CC20000B090000000999B0B900000000000900DC +:10CC300090990000000000090000000000000000C2 +:10CC400000000000000000000000000000000000E4 +:10CC500000000000000000000000000000000100D3 +:10CC600000100000000001000100000000000000B2 +:10CC70001000000000100999000000100019009930 +:10CC800090900010111099BBB0900000001000BBF4 +:10CC9000B0900000001090BBB0B000100000000089 +:10CCA0000090000000000099090900000000090937 +:10CCB0009900010000010000910000000000100038 +:10CCC0000000100000000110000100000000000042 +:10CCD000000000000000000B00000000000000B099 +:10CCE00000000000000000B000000000000000F0A4 +:10CCF0000F00B000000000F00F0B0B000B00FF0056 +:10CD0000000000000000FFFFFF0000000000F0FF37 +:10CD10000FF000000000FFFFFFF0FB000000F0FF3D +:10CD2000F00F000B000FFF0F000FB0B000B00F0F9F +:10CD300000FFB0B00B0000000000B0B000B0000079 +:10CD4000000B0000000B00B0000000000000000B12 +:10CD500000000000000000000000000000000000D3 +:10CD60000000000000000000E000000000000000E3 +:10CD700000000000000000000000000000000000B3 +:10CD800000000000000000000000000000000000A3 +:10CD90000000000000000000000000000000000093 +:10CDA0000000000000000000000000000000000083 +:10CDB0000000000000000000000000000000000073 +:10CDC0000000000000000000000000000000000063 +:10CDD000000000F000000000000000000000000063 +:10CDE0000000000000F00000000000000000000053 +:10CDF0000000000000000000000000000000000033 +:10CE0000070000000000000000000000000000001B +:10CE10000000000000000000000000000000000012 +:10CE20000000000000000000000000000000000002 +:10CE300000000000000000000000000000000000F2 +:10CE400000000000000000000000000000000000E2 +:10CE500000000000000000000000000000000000D2 +:10CE600000000000000000000000000000000000C2 +:10CE70000000000000000000000E000000000000A4 +:10CE800000000000000000000000000000000000A2 +:10CE90000000000000000000000000000000000092 +:10CEA0000000000000000000000000000000000082 +:10CEB0000000000000000000000000000000000072 +:10CEC00000000000000000000000000000D0000092 +:04CED000000000005E +:040000030000A20057 +:00000001FF diff --git a/games/swarm/test-swarm.py b/games/swarm/test-swarm.py new file mode 100644 index 0000000..b7a5d62 --- /dev/null +++ b/games/swarm/test-swarm.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""Run Star Swarm in tools/rv32emu.py on a model of the board (tools/boardemu.py) +and take screenshots. + + python3 test-swarm.py [--shots DIR] [--play] + +It checks the title screen, measures the Z-80 instructions each frame takes +(a 60 Hz frame has about 550,000 at 90 MHz), checks that the formation sways +and that aliens dive, shoots one out of the formation, and with --play lets an +autopilot clear the whole swarm. The autopilot can't be killed (it keeps the +ship shielded), so this checks the rules and the waves, not its skill. +""" +import argparse +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "tools")) +from boardemu import Board, load_ihx, load_font, load_syms # noqa: E402 + +LEFT, RIGHT, FIRE, ESC = 4, 8, 16, 128 +FX0, CW = 60, 20 + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--shots", help="write PNG screenshots here") + ap.add_argument("--play", action="store_true", help="let the autopilot clear a wave") + a = ap.parse_args() + mem, hi = load_ihx(os.path.join(HERE, "swarm.ihx")) + b = Board(mem, code_end=hi) + font = load_font() if a.shots else None + if a.shots: + os.makedirs(a.shots, exist_ok=True) + sym = {"_" + n: a for n, a in load_syms(os.path.join(HERE, "out", "swarm.sym")).items()} + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def s16(n, k=0): + v = b.m[sym[n] + 2 * k] | b.m[sym[n] + 2 * k + 1] << 8 + return v - 65536 if v & 0x8000 else v + + def u8(n, k=0): + return b.m[sym[n] + k] + + def screen(): + return b.screen_text().display + + b.run_frames(5) + check("title screen", "S T A R S W A R M" in "\n".join(screen())) + if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font) + b.run_frames(3, FIRE) + b.run_frames(5) + check("game starts", "WAVE 1" in screen()[0] and "SHIPS 3" in screen()[0]) + check("46 aliens in formation", sum(1 for k in range(60) if b.m[sym["_cell"] + k] == 1) == 46) + s0 = b.scroll_x + c0 = b.steps + worst = 0 + for f in range(240): + c1 = b.steps + b.run_frames(1) + worst = max(worst, b.steps - c1) + per = (b.steps - c0) / 240 + print("%.0f instructions a frame on average, %d at most (%.0f%%)" % (per, worst, worst / 5500)) + check("every frame fits in a 60th of a second", worst < 550000) + check("the formation sways", b.scroll_x != s0) + check("aliens dive", any(u8("_dv_on", k) for k in range(8))) + if a.shots: b.shot(os.path.join(a.shots, "2-dive.png"), font) + sc = s16("_score") + b.m[sym["_shield"]] = 1 + b.run_frames(2, RIGHT) # off the gap between two columns + b.run_frames(3, FIRE) + b.run_frames(40) + check("a shot into the formation scores", s16("_score") > sc) + + if a.play: + frame = 0 + while frame < 20000 and b.pc != 0: + b.m[sym["_shield"]] = 1 + sx = s16("_ship_x") + 8 + # aim at a diver low down if there is one, else the nearest column + target = None + for k in range(8): + if u8("_dv_on", k) and s16("_dv_y", k) >> 4 > 60: + target = (s16("_dv_x", k) >> 4) + 8 + break + if target is None: + sway = (320 - b.scroll_x) % 320 + if sway > 160: sway -= 320 + best = None + for c in range(10): + if any(b.m[sym["_cell"] + r * 10 + c] == 1 for r in range(6)): + x = FX0 + c * CW + 2 + 8 + sway + if best is None or abs(x - sx) < abs(best - sx): + best = x + target = best if best is not None else sx + j = FIRE if frame % 2 else 0 + if target > sx + 1: j |= RIGHT + elif target < sx - 1: j |= LEFT + b.run_frames(1, j) + frame += 1 + if frame == 600 and a.shots: b.shot(os.path.join(a.shots, "3-battle.png"), font) + if "WAVE 2" in screen()[0]: + break + print(screen()[0]) + check("autopilot cleared the swarm in %d frames" % frame, "WAVE 2" in screen()[0]) + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc gives up the game", "PRESS SPACE TO BEGIN" in "\n".join(screen())) + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc returns to BASIC", b.pc == 0) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/games/warden/gen.py b/games/warden/gen.py new file mode 100644 index 0000000..fcc1280 --- /dev/null +++ b/games/warden/gen.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +"""Make data.h for warden.c: the sprite shapes and the planet's mountains. + +Shapes are 16 rows of 16 hex digits, one colour per pixel (0 is see-through). +The planet is 1,280 pixels round; the mountains are a height for every column, +made by midpoint displacement so that they join up where the world wraps. +""" +import random +import sys + +SHIP = ["0" * 16] * 5 + [ + "0F00000000000000", + "0FF0000066000000", + "BFFFFFF666600000", + "BFFFFFFFFFFFFF00", + "0CCCCCCCCCCCC000", + "0FF0000000000000", + "0F00000000000000", +] + ["0" * 16] * 4 +LANDER = ["0" * 16] * 3 + [ + "00000BBBBBB00000", + "0000BBBBBBBB0000", + "000AAAAAAAAAA000", + "00AA2AA2AA2AAA00", + "00AAAAAAAAAAAA00", + "000AAAAAAAAAA000", + "0000A00AA00A0000", + "000A000AA000A000", + "00A0000AA0000A00", +] + ["0" * 16] * 4 +MUTANT = ["0" * 16] * 2 + [ + "0000D00000D00000", + "00000D000D000000", + "000DDDDDDDDD0000", + "00DDAADDDAADD000", + "0DDDAADDDAADDD00", + "00DDDDDDDDDDD000", + "000D0D0D0D0D0000", + "00D0D0D0D0D0D000", +] + ["0" * 16] * 6 +BOMBER = ["0" * 16] * 4 + [ + "0000CCCCCCCC0000", + "0000C444444C0000", + "0000C4EEEE4C0000", + "0000C4EEEE4C0000", + "0000C444444C0000", + "0000CCCCCCCC0000", +] + ["0" * 16] * 6 +MINE = ["0" * 16] * 6 + [ + "0000000990000000", + "000000999F000000", + "000000F999000000", + "0000000990000000", +] + ["0" * 16] * 6 +HUMAN = ["0" * 16] * 6 + [ + "0000000FF0000000", + "0000000FF0000000", + "000000DDDD000000", + "00000D0DD0D00000", + "0000000DD0000000", + "0000000CC0000000", + "000000C00C000000", + "000000C00C000000", +] + ["0" * 16] * 2 +LASER = ["0" * 16] * 8 + ["BFFFFFFFFFFFFFFB"] + ["0" * 16] * 7 +SHOT = ["0" * 16] * 7 + ["0000000F90000000", "00000009F0000000"] + ["0" * 16] * 7 + + +def burst(seed, cols, size): + import math + r = random.Random(seed) + img = [["0"] * 16 for _ in range(16)] + for _ in range(90): + a = r.uniform(0, 2 * math.pi) + d = r.uniform(0, size) + x, y = int(8 + d * math.cos(a)), int(8 + d * math.sin(a)) + if 0 <= x < 16 and 0 <= y < 16: + img[y][x] = cols[0] if d < size / 3 else cols[1] if d < 2 * size / 3 else cols[2] + return ["".join(row) for row in img] + + +BOOM1 = burst(7, "FB9", 5) +BOOM2 = burst(9, "B91", 7.5) +SHIPBOOM = burst(11, "FFB", 7.9) + +SHAPES = [("S_SHIP", SHIP), ("S_LANDER", LANDER), ("S_MUTANT", MUTANT), ("S_BOMBER", BOMBER), + ("S_MINE", MINE), ("S_HUMAN", HUMAN), ("S_LASER", LASER), ("S_SHOT", SHOT), + ("S_BOOM1", BOOM1), ("S_BOOM2", BOOM2), ("S_SHIPBOOM", SHIPBOOM)] + +WORLD = 1280 + + +def mountains(): + r = random.Random(2084) + n = WORLD + h = [0.0] * n + step = 256 # 1280 = 5 x 256, so halving reaches every column + for i in range(0, n, step): + h[i] = r.uniform(150, 205) + amp = 48.0 + while step > 1: + half = step // 2 + for i in range(0, n, step): + a, b = h[i], h[(i + step) % n] + h[i + half] = (a + b) / 2 + r.uniform(-amp, amp) + step = half + amp *= 0.62 + assert all(v > 0 for v in h), "a column was missed" + return [max(118, min(222, int(v))) for v in h] + + +def main(out): + L = ["/* made by gen.py - edit that instead */", ""] + for i, (name, img) in enumerate(SHAPES): + assert len(img) == 16 and all(len(row) == 16 for row in img), name + L.append("#define %s %d" % (name, i)) + L.append("#define N_SHAPES %d" % len(SHAPES)) + L.append("#define WORLD %d" % WORLD) + L.append("static const u8 shape_data[N_SHAPES * 128] = {") + for name, img in SHAPES: + b = [int(row[x], 16) << 4 | int(row[x + 1], 16) for row in img for x in range(0, 16, 2)] + L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % name) + L.append("};") + m = mountains() + L.append("static const u8 mountain[WORLD] = {") + for k in range(0, WORLD, 32): + L.append(" " + ",".join(str(v) for v in m[k:k + 32]) + ",") + L.append("};") + open(out, "w").write("\n".join(L) + "\n") + print("data.h: %d shapes, mountains %d-%d" % (len(SHAPES), min(m), max(m))) + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else "data.h") diff --git a/games/warden/test-warden.py b/games/warden/test-warden.py new file mode 100644 index 0000000..f36d774 --- /dev/null +++ b/games/warden/test-warden.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Run Star Warden in tools/rv32emu.py on a model of the board (tools/boardemu.py) +and take screenshots. + + python3 test-warden.py [--shots DIR] [--play] + +It checks the title screen, measures the Z-80 instructions each frame takes +(a 60 Hz frame has about 550,000 at 90 MHz), flies along the planet checking +that the picture scrolls and the scanner fills in, and with --play lets an +autopilot hunt down every enemy until the wave is cleared. The autopilot +can't be killed (it keeps the ship shielded), so this checks the rules and the +waves, not its skill. +""" +import argparse +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "tools")) +from boardemu import Board, load_ihx, load_font, load_syms # noqa: E402 + +UP, DOWN, LEFT, RIGHT, FIRE, ENTER, SHIFT, ESC = 1, 2, 4, 8, 16, 32, 64, 128 +WORLD = 1280 + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--shots", help="write PNG screenshots here") + ap.add_argument("--play", action="store_true", help="let the autopilot clear a wave") + a = ap.parse_args() + mem, hi = load_ihx(os.path.join(HERE, "warden.ihx")) + b = Board(mem, code_end=hi) + font = load_font() if a.shots else None + if a.shots: + os.makedirs(a.shots, exist_ok=True) + sym = {"_" + n: a for n, a in load_syms(os.path.join(HERE, "out", "warden.sym")).items()} + errors = 0 + + def check(what, ok): + nonlocal errors + print(("PASS " if ok else "FAIL ") + what) + errors += not ok + + def u16(n, k=0): + return b.m[sym[n] + 2 * k] | b.m[sym[n] + 2 * k + 1] << 8 + + def u8(n, k=0): + return b.m[sym[n] + k] + + def screen(): + return b.screen_text().display + + b.run_frames(5) + check("title screen", "S T A R W A R D E N" in "\n".join(screen())) + if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font) + b.run_frames(3, FIRE) + b.run_frames(5) + check("game starts", "WAVE 1" in screen()[0] and "SHIPS 3" in screen()[0]) + c0 = b.steps + b.run_frames(60, RIGHT) + per = (b.steps - c0) / 60 + print("%.0f instructions a frame while flying (%.0f%% of a 60 Hz frame)" % (per, per / 5500)) + check("a frame fits in a 60th of a second", per < 500000) + check("flying right scrolls the planet", b.scroll_x != 0) + check("the scanner shows enemies", sum(r.count("o") for r in screen()[1:4]) >= 4) + if a.shots: b.shot(os.path.join(a.shots, "2-flying.png"), font) + s0 = b.scroll_x + b.run_frames(80, LEFT) + check("turning round scrolls the other way", b.scroll_x != s0) + if a.shots: b.shot(os.path.join(a.shots, "3-turned.png"), font) + + if a.play: + b.m[sym["_shield"]] = 1 + worst = 0 + frame = 0 + while frame < 9000 and b.pc != 0: + b.m[sym["_shield"]] = 1 + px, py = u16("_px"), u8("_py") + best, bd = None, 9999 + for k in range(16): + if u8("_etype", k): + ex = u16("_ex", k) >> 4 + d = (ex - px + WORLD // 2) % WORLD - WORLD // 2 + if abs(d) < abs(bd): + bd, best = d, k + j = 0 + if best is not None: + ey = u8("_ey", best) + if ey < py - 1: j |= UP + elif ey > py + 1: j |= DOWN + if abs(bd) > 90 or (bd > 0) != (b.spr[0][3] & 2 == 0): + j |= RIGHT if bd > 0 else LEFT + if abs(ey - py) < 6 and abs(bd) < 260: + j |= FIRE if frame % 2 else 0 + c0 = b.steps + b.run_frames(1, j) + worst = max(worst, b.steps - c0) + frame += 1 + if frame == 120 and a.shots: b.shot(os.path.join(a.shots, "4-battle.png"), font) + if "WAVE 2" in screen()[0]: + break + print(screen()[0]) + check("autopilot cleared wave 1 in %d frames" % frame, "WAVE 2" in screen()[0]) + print("slowest frame: %d instructions (%.0f%% of a 60 Hz frame)" % (worst, worst / 5500)) + check("every frame fits in a 60th of a second", worst < 550000) + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc gives up the game", "PRESS SPACE TO BEGIN" in "\n".join(screen())) + b.run_frames(5, ESC) + b.run_frames(5) + check("Esc returns to BASIC", b.pc == 0) + sys.exit(1 if errors else 0) + + +if __name__ == "__main__": + main() diff --git a/games/warden/warden.bas b/games/warden/warden.bas new file mode 100644 index 0000000..412ff5b --- /dev/null +++ b/games/warden/warden.bas @@ -0,0 +1,4 @@ +10 REM STAR WARDEN: LOAD THE GAME (MEMORY FILE WARDGAME) AND PLAY IT +20 REM THE GAME RUNS AT A200H, PAST THIS PROGRAM, AND COMES BACK HERE +30 BLOAD "WARDGAME": CALL 41472 +40 CLS diff --git a/games/warden/warden.c b/games/warden/warden.c new file mode 100644 index 0000000..eccf8d3 --- /dev/null +++ b/games/warden/warden.c @@ -0,0 +1,816 @@ +/* Star Warden: a side-scrolling planet defence game for the Basys 3 RISC-V computer. + + Landers come down to snatch the humanoids walking on the planet and carry + them off; one that reaches the top turns into a mutant that hunts you. + Shoot them, catch the humanoids they drop, and stay clear of the bombers' + mines. The long-range scanner at the top shows the whole planet. A wave + ends when every enemy is gone, with a bonus for each humanoid still alive. + + The planet is 1,280 pixels round, exactly four buffers wide, so world + column x always lives in buffer column x mod 320. The hardware scrolls the + graphics (ports 35h-37h) with its edge border on, and the game draws the + columns that come into view in the hidden border. Everything that moves is + a sprite; the scanner and the score are text. It runs at A200h, loaded by + the WARDEN program in BASIC. */ + +typedef unsigned char u8; +typedef signed char i8; +typedef unsigned short u16; +typedef short i16; + +#include "basys3.h" + +#define con_stat IO8(0x00) +#define con_data IO8(0x01) +#define gx_lo IO8(0x30) +#define gx_hi IO8(0x31) +#define gy_p IO8(0x32) +#define gpix IO8(0x33) +#define gfill IO8(0x34) +#define scr_xlo IO8(0x35) +#define scr_xhi IO8(0x36) +#define scr_y IO8(0x37) +#define sp_sel IO8(0x70) +#define sp_xlo IO8(0x71) +#define sp_xhi IO8(0x72) +#define sp_y IO8(0x73) +#define sp_shape IO8(0x74) +#define sp_ctl IO8(0x75) +#define sp_load IO8(0x76) +#define sp_data IO8(0x77) +#define frame_ctr IO8(0x78) +#define joy IO8(0x88) + +#include "data.h" /* out/data.h, made by gen.py */ + +#define J_UP 1 +#define J_DOWN 2 +#define J_LEFT 4 +#define J_RIGHT 8 +#define J_FIRE 16 +#define J_ENTER 32 +#define J_SHIFT 64 +#define J_ESC 128 + +#define TOP_Y 34 /* the play area: below the scanner */ +#define GROUND_Y 210 /* a humanoid's sprite stands here */ +#define BOT_Y 214 /* lowest the ship goes */ + +/* sprites: lower numbers in front */ +#define SP_SHIP 0 +#define SP_LASER 1 /* 4 */ +#define SP_SHOT 5 /* 4 */ +#define SP_POOL 9 /* 23: enemies, humanoids, mines, explosions */ +#define SP_END 32 + +#define NE 16 /* enemies */ +#define NH 8 /* humanoids */ +#define NM 6 /* mines */ +#define NL 4 /* lasers */ +#define NS 4 /* enemy shots */ +#define NX 5 /* explosions */ + +#define E_NONE 0 +#define E_LANDER 1 +#define E_MUTANT 2 +#define E_BOMBER 3 + +#define L_SEEK 0 +#define L_DOWN 1 +#define L_CARRY 2 + +#define H_WALK 0 +#define H_HELD 1 +#define H_FALL 2 +#define H_GONE 3 + +/* ---------------------------------------------------------------- state */ +/* not static: test-warden.py reads these from the link map */ +u16 cam; /* world column at the screen's left */ +u16 px; /* ship, world pixels */ +u8 py; +u8 lives, bombs, wave, dead, inv, shield; +u16 score; +u8 etype[NE]; +u16 ex[NE]; /* world x in 1/16 pixels */ +u8 ey[NE]; + +static i16 vx; /* 1/16 pixels a frame */ +static u8 pxf; /* sub-pixel */ +static u8 facing; /* 0 right, 1 left */ +static i16 off; /* ship's screen x */ +static u8 dead_time, fire_cool, bomb_held, hyper_held; +static u16 next_extra; + +static u8 estate[NE], etgt[NE], ecool[NE]; +static i8 evx[NE], evy[NE]; +static u8 ebase[NE]; + +static u16 hx[NH]; +static u8 hy[NH], hstate[NH], hdir[NH], hvy[NH], hfrom[NH]; + +static u16 mx[NM]; +static u8 my[NM]; +static u16 mlife[NM]; + +static u16 lx[NL]; +static u8 ly[NL], ldir[NL], llife[NL]; + +static u16 sx16[NS], sy16[NS]; +static i16 svx[NS], svy[NS]; +static u8 slife[NS]; + +static u16 xx[NX]; +static u8 xy[NX], xt[NX]; + +static u8 pool_used, pool_last; +static u8 last_frame, quit, hud_dirty, scan_timer; +static u16 rnd_state; +static const char *msg; +static u8 msg_time; + +/* ----------------------------------------------------------------- text */ +static void putch(char c) { while (!(con_stat & 2)); con_data = c; } +static void puts_(const char *s) { while (*s) putch(*s++); } +static void putn(u16 n, u8 width) +{ + char b[6]; + u8 i = 0; + do { b[i++] = '0' + n % 10; n /= 10; } while (n); + while (width > i) { putch('0'); width--; } + while (i) putch(b[--i]); +} +static void at(u8 r, u8 c) { putch(27); putch('['); putn(r, 0); putch(';'); putn(c, 0); putch('H'); } +static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); } +static void centre(u8 r, const char *s) +{ + u8 n = 0; + while (s[n]) n++; + at(r, 41 - n / 2); + puts_(s); +} + +static u16 rnd(void) +{ + rnd_state ^= rnd_state << 7; + rnd_state ^= rnd_state >> 9; + rnd_state ^= rnd_state << 8; + return rnd_state; +} + +static void wait_frame(void) +{ + while (frame_ctr == last_frame); + last_frame = frame_ctr; +} + +static u8 drain_keys(void) +{ + u8 c, p = 0; + while (con_stat & 1) { + c = con_data; + if (c == 'p' || c == 'P') p = 1; + } + return p; +} + +static void say(const char *s) { msg = s; msg_time = 120; hud_dirty = 1; } + +/* ---------------------------------------------------------- the planet */ +static u16 wrapx(i16 x) +{ + while (x < 0) x += WORLD; + while (x >= WORLD) x -= WORLD; + return (u16)x; +} + +/* shortest signed distance from a to b round the planet */ +static i16 dist(u16 a, u16 b) +{ + i16 d = (i16)b - (i16)a; + if (d > WORLD / 2) d -= WORLD; + else if (d < -WORLD / 2) d += WORLD; + return d; +} + +static i16 absd(i16 v) { return v < 0 ? -v : v; } + +/* move a world x in 1/16 pixels by d, round the planet */ +static u16 step16(u16 x, i16 d) +{ + i16 v = (i16)x + d; + if (v < 0) v += WORLD * 16; + else if (v >= WORLD * 16) v -= WORLD * 16; + return (u16)v; +} + +/* Draw world column x into its buffer column. */ +static void draw_col(u16 x) +{ + u16 bx = x; + u8 y, a, b, lo, hi, star_y, star_c = 0, c; + while (bx >= 320) bx -= 320; + a = mountain[x]; + b = mountain[x + 1 < WORLD ? x + 1 : 0]; + lo = a < b ? a : b; + hi = a < b ? b : a; + star_y = 0; + if (!((x * 37) & 3)) { + star_y = TOP_Y + (u8)((x * 71) % 110); + star_c = (x & 8) ? 15 : (x & 16) ? 14 : 7; + } + for (y = 0; y < 240; y++) { + c = 0; + if (y >= lo && y <= hi) c = 3; + else if (y == star_y) c = star_c; + else if (y == 236) c = 4; /* the planet's surface line */ + gx_lo = (u8)bx; gx_hi = (u8)(bx >> 8); gy_p = y; + gpix = c; + } +} + +static void set_scroll(void) +{ + u16 b = cam; + while (b >= 320) b -= 320; + scr_xlo = (u8)b; scr_xhi = (u8)(b >> 8) | 2; scr_y = 0; +} + +static void draw_all(void) +{ + u16 i; + for (i = 0; i < 320; i++) draw_col(wrapx(cam + i)); +} + +/* Move the camera by d columns (at most 4 either way) and draw what comes + into view: those columns are in the hidden border until next frame. */ +static void scroll_by(i16 d) +{ + i16 k; + if (d > 0) + for (k = 0; k < d; k++) draw_col(wrapx(cam + 320 + k)); + else + for (k = 0; k < -d; k++) draw_col(wrapx((i16)cam - 1 - k)); + cam = wrapx((i16)cam + d); +} + +/* -------------------------------------------------------------- sprites */ +static void spr_at(u8 n, i16 x, i16 y, u8 shape, u8 ctl) +{ + sp_sel = n; + if (x < -15 || x > 319 || y < -15 || y > 239) { sp_ctl = 0; return; } + sp_xlo = (u8)x; sp_xhi = (u8)(x >> 8) & 1; sp_y = (u8)y; + sp_shape = shape; sp_ctl = ctl; +} +static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; } + +/* A world object at (wx, y) on screen gets the next pool sprite. */ +static void pool_put(u16 wx, i16 y, u8 shape, u8 ctl) +{ + i16 s = dist(cam, wx); + if (s < -15 || s > 319 || pool_used == SP_END - SP_POOL) return; + spr_at(SP_POOL + pool_used, s - 8, y - 8, shape, ctl); + pool_used++; +} + +static void pool_end(void) +{ + u8 i; + for (i = pool_used; i < pool_last; i++) spr_off(SP_POOL + i); + pool_last = pool_used; + pool_used = 0; +} + +static void all_off(void) { u8 i; for (i = 0; i < 32; i++) spr_off(i); pool_last = 0; } + +static void load_shapes(void) +{ + const u8 *p = shape_data; + u8 s, i; + for (s = 0; s < N_SHAPES; s++) { + sp_load = s; + for (i = 0; i < 128; i++) sp_data = *p++; + } +} + +static u8 on_screen(u16 wx) +{ + i16 s = dist(cam, wx); + return s >= 0 && s < 320; +} + +static void boom(u16 wx, u8 y) +{ + u8 i, best = 0; + for (i = 0; i < NX; i++) if (xt[i] < xt[best]) best = i; + xx[best] = wx; xy[best] = y; xt[best] = 20; +} + +/* ------------------------------------------------------------------ HUD */ +static void hud(void) +{ + hud_dirty = 0; + at(1, 1); ink("0;93"); puts_("STAR WARDEN "); + ink("0;37"); puts_("SCORE "); ink("0;97"); putn(score, 6); + ink("0;37"); puts_(" SHIPS "); ink("0;97"); putn(lives, 0); + ink("0;37"); puts_(" BOMBS "); ink("0;97"); putn(bombs, 0); + ink("0;37"); puts_(" WAVE "); ink("0;97"); putn(wave, 0); + if (msg && msg_time) { ink("0;96"); puts_(" "); puts_(msg); } + puts_("\033[K"); + ink("0"); +} + +/* The scanner: the whole planet in 80 columns and 3 rows, the ship in the + middle. */ +static u8 scan_col(u16 wx) +{ + i16 d = dist(px, wx) + WORLD / 2; + d >>= 4; + return 1 + (u8)(d > 79 ? 79 : d); +} +static u8 scan_row(u8 y) { return 2 + (y < 100 ? 0 : y < 160 ? 1 : 2); } + +static void scanner(void) +{ + u8 i; + for (i = 2; i <= 4; i++) { at(i, 1); puts_("\033[2K"); } + ink("0;34"); + at(2, 33); putch('['); at(4, 33); putch('['); + at(2, 48); putch(']'); at(4, 48); putch(']'); + ink("0;95"); + for (i = 0; i < NH; i++) + if (hstate[i] != H_GONE) { at(scan_row(hy[i]), scan_col(hx[i])); putch('.'); } + for (i = 0; i < NE; i++) { + if (!etype[i]) continue; + ink(etype[i] == E_LANDER ? "0;92" : etype[i] == E_MUTANT ? "0;95" : "0;94"); + at(scan_row(ey[i]), scan_col(ex[i] >> 4)); + putch(etype[i] == E_BOMBER ? '#' : 'o'); + } + if (!dead) { ink("0;93"); at(scan_row(py), scan_col(px)); putch(facing ? '<' : '>'); } + ink("0"); +} + +/* --------------------------------------------------------------- waves */ +static u8 humans_left(void) +{ + u8 i, n = 0; + for (i = 0; i < NH; i++) if (hstate[i] != H_GONE) n++; + return n; +} + +static void place_humans(void) +{ + u8 i; + for (i = 0; i < NH; i++) { + hx[i] = wrapx(i * (WORLD / NH) + (rnd() & 63)); + hy[i] = GROUND_Y; hstate[i] = H_WALK; hdir[i] = rnd() & 1; + } +} + +static void spawn(u8 type) +{ + u8 i; + u16 x; + for (i = 0; i < NE && etype[i]; i++); + if (i == NE) return; + do x = rnd() % WORLD; while (absd(dist(px, x)) < 260); + etype[i] = type; ex[i] = x << 4; + ey[i] = TOP_Y + 6 + (rnd() & 63); + estate[i] = L_SEEK; etgt[i] = 255; + ecool[i] = 60 + (rnd() & 127); + evx[i] = (rnd() & 1) ? 8 : -8; + evy[i] = 0; + ebase[i] = ey[i]; +} + +static void start_wave(void) +{ + u8 i, n; + for (i = 0; i < NE; i++) etype[i] = E_NONE; + for (i = 0; i < NM; i++) mlife[i] = 0; + for (i = 0; i < NS; i++) { slife[i] = 0; spr_off(SP_SHOT + i); } + if (wave % 5 == 1) place_humans(); /* the planet is restored */ + n = 4 + 2 * wave; if (n > 12) n = 12; + for (i = 0; i < n; i++) spawn(E_LANDER); + n = wave < 4 ? wave - 1 : 3; + for (i = 0; i < n; i++) spawn(E_BOMBER); + if (!humans_left()) + for (i = 0; i < NE; i++) if (etype[i] == E_LANDER) etype[i] = E_MUTANT; +} + +static u8 enemies_left(void) +{ + u8 i, n = 0; + for (i = 0; i < NE; i++) if (etype[i]) n++; + return n; +} + +/* --------------------------------------------------------------- rules */ +static void add_score(u16 n) +{ + score += n; + if (score >= next_extra) { + next_extra += 10000; + lives++; bombs++; + say("BONUS SHIP"); + } + hud_dirty = 1; +} + +static void kill_ship(void) +{ + u8 i; + if (dead || inv || shield) return; + dead = 1; dead_time = 100; + boom(px, py); + spr_off(SP_SHIP); + for (i = 0; i < NS; i++) { slife[i] = 0; spr_off(SP_SHOT + i); } +} + +static void kill_enemy(u8 i) +{ + u8 h; + if (etype[i] == E_LANDER && estate[i] == L_CARRY && etgt[i] < NH) { + h = etgt[i]; + hstate[h] = H_FALL; hvy[h] = 0; hfrom[h] = hy[h]; + } + add_score(etype[i] == E_BOMBER ? 250 : 150); + boom(ex[i] >> 4, ey[i]); + etype[i] = E_NONE; +} + +static void enemy_fire(u8 i, u8 often) +{ + u8 k; + i16 dx, dy, m; + if (ecool[i]) { ecool[i]--; return; } + ecool[i] = often + (rnd() & 63); + if (dead || !on_screen(ex[i] >> 4)) return; + for (k = 0; k < NS && slife[k]; k++); + if (k == NS) return; + dx = dist(ex[i] >> 4, px); + dy = (i16)py - ey[i]; + m = absd(dx) > absd(dy) ? absd(dx) : absd(dy); + if (!m) return; + sx16[k] = ex[i]; sy16[k] = (u16)ey[i] << 4; + svx[k] = dx * 32 / m; svy[k] = dy * 32 / m; + slife[k] = 90; +} + +static void enemies(void) +{ + u8 i, h, best; + i16 d, bd; + u16 x; + for (i = 0; i < NE; i++) { + if (!etype[i]) continue; + x = ex[i] >> 4; + switch (etype[i]) { + case E_LANDER: + if (estate[i] == L_SEEK) { + ex[i] = step16(ex[i], evx[i]); + if (!(last_frame & 31)) ey[i] = ebase[i] + (rnd() & 15); + /* pick a humanoid nobody is after, and go for it when above it */ + if (etgt[i] == 255) { + best = 255; bd = 2000; + for (h = 0; h < NH; h++) { + if (hstate[h] != H_WALK) continue; + d = absd(dist(x, hx[h])); + if (d < bd) { bd = d; best = h; } + } + etgt[i] = best; + } else if (hstate[etgt[i]] != H_WALK) etgt[i] = 255; + else if (absd(dist(x, hx[etgt[i]])) < 3) estate[i] = L_DOWN; + enemy_fire(i, 90); + } else if (estate[i] == L_DOWN) { + h = etgt[i]; + if (h >= NH || hstate[h] != H_WALK) { estate[i] = L_SEEK; etgt[i] = 255; break; } + ex[i] = (u16)hx[h] << 4; + if (ey[i] + 12 < hy[h]) ey[i]++; + else { estate[i] = L_CARRY; hstate[h] = H_HELD; } + enemy_fire(i, 120); + } else { + h = etgt[i]; + if (!(last_frame & 1)) ey[i]--; + hx[h] = ex[i] >> 4; hy[h] = ey[i] + 12; + if (ey[i] <= TOP_Y) { + hstate[h] = H_GONE; + etype[i] = E_MUTANT; + say(humans_left() ? "A HUMANOID IS LOST" : "THE PLANET IS LOST"); + if (!humans_left()) + for (h = 0; h < NE; h++) if (etype[h] == E_LANDER) etype[h] = E_MUTANT; + } + } + break; + case E_MUTANT: + d = dist(x, px); + ex[i] = step16(ex[i], d > 0 ? 22 : -22); + if (ey[i] < py) ey[i]++; else if (ey[i] > py) ey[i]--; + if (!(rnd() & 3)) ey[i] += (rnd() & 1) ? 2 : -2; + if (ey[i] < TOP_Y) ey[i] = TOP_Y; + if (ey[i] > BOT_Y) ey[i] = BOT_Y; + enemy_fire(i, 40); + break; + case E_BOMBER: + ex[i] = step16(ex[i], evx[i]); + ey[i] = ebase[i] + ((last_frame >> 2) & 15); + if (ecool[i]) ecool[i]--; + else { + ecool[i] = 70 + (rnd() & 63); + for (h = 0; h < NM && mlife[h]; h++); + if (h < NM) { mx[h] = x; my[h] = ey[i]; mlife[h] = 400; } + } + break; + } + if (!etype[i]) continue; + x = ex[i] >> 4; + if (!dead && absd(dist(x, px)) < 12 && absd((i16)ey[i] - py) < 8) { + kill_enemy(i); + kill_ship(); + continue; + } + pool_put(x, ey[i], etype[i] == E_LANDER ? S_LANDER : etype[i] == E_MUTANT ? S_MUTANT : S_BOMBER, 1); + } +} + +static void humans(void) +{ + u8 i; + for (i = 0; i < NH; i++) { + switch (hstate[i]) { + case H_WALK: + if (!(last_frame & 7)) { + hx[i] = wrapx((i16)hx[i] + (hdir[i] ? 1 : -1)); + if (!(rnd() & 31)) hdir[i] ^= 1; + } + break; + case H_FALL: + if (!(last_frame & 3) && hvy[i] < 4) hvy[i]++; + hy[i] += hvy[i]; + if (!dead && absd(dist(hx[i], px)) < 12 && absd((i16)hy[i] - py) < 12) { + hstate[i] = H_WALK; hy[i] = GROUND_Y; + add_score(500); say("HUMANOID SAVED"); + break; + } + if (hy[i] >= GROUND_Y) { + hy[i] = GROUND_Y; + if (GROUND_Y - hfrom[i] > 90) { hstate[i] = H_GONE; boom(hx[i], GROUND_Y); say("A HUMANOID FELL"); } + else { hstate[i] = H_WALK; add_score(250); } + } + break; + } + if (hstate[i] != H_GONE) pool_put(hx[i], hy[i], S_HUMAN, 1); + } +} + +static void mines_and_booms(void) +{ + u8 i; + for (i = 0; i < NM; i++) { + if (!mlife[i]) continue; + mlife[i]--; + if (!dead && absd(dist(mx[i], px)) < 8 && absd((i16)my[i] - py) < 6) { + mlife[i] = 0; boom(mx[i], my[i]); kill_ship(); continue; + } + pool_put(mx[i], my[i], S_MINE, 1); + } + for (i = 0; i < NX; i++) { + if (!xt[i]) continue; + xt[i]--; + pool_put(xx[i], xy[i], dead && xx[i] == px ? S_SHIPBOOM : (xt[i] & 4) ? S_BOOM1 : S_BOOM2, 1); + } +} + +static void shots(void) +{ + u8 i; + i16 s; + for (i = 0; i < NS; i++) { + if (!slife[i]) continue; + slife[i]--; + sx16[i] = step16(sx16[i], svx[i]); + sy16[i] += svy[i]; + if ((sy16[i] >> 4) < TOP_Y || (sy16[i] >> 4) > 236) slife[i] = 0; + if (!dead && slife[i] && absd(dist(sx16[i] >> 4, px)) < 7 && absd((i16)(sy16[i] >> 4) - py) < 5) { + slife[i] = 0; kill_ship(); + } + if (!slife[i]) { spr_off(SP_SHOT + i); continue; } + s = dist(cam, sx16[i] >> 4); + spr_at(SP_SHOT + i, s - 8, (i16)(sy16[i] >> 4) - 8, S_SHOT, 1); + } +} + +static void lasers(u8 j) +{ + u8 i, k; + i16 s; + if ((j & J_FIRE) && !fire_cool && !dead) { + for (i = 0; i < NL && llife[i]; i++); + if (i < NL) { + lx[i] = wrapx((i16)px + (facing ? -14 : 14)); ly[i] = py + 1; ldir[i] = facing; llife[i] = 26; + fire_cool = 7; + } + } + if (fire_cool) fire_cool--; + for (i = 0; i < NL; i++) { + if (!llife[i]) continue; + llife[i]--; + lx[i] = wrapx((i16)lx[i] + (ldir[i] ? -12 : 12)); + for (k = 0; k < NE; k++) + if (etype[k] && absd(dist(lx[i], ex[k] >> 4)) < 12 && absd((i16)ey[k] - ly[i]) < 7) { + kill_enemy(k); llife[i] = 0; break; + } + for (k = 0; k < NM && llife[i]; k++) + if (mlife[k] && absd(dist(lx[i], mx[k])) < 10 && absd((i16)my[k] - ly[i]) < 5) { + mlife[k] = 0; boom(mx[k], my[k]); add_score(50); llife[i] = 0; + } + if (!llife[i] || !on_screen(lx[i])) { llife[i] = 0; spr_off(SP_LASER + i); continue; } + s = dist(cam, lx[i]); + spr_at(SP_LASER + i, s - 8, (i16)ly[i] - 8, S_LASER, 1); + } +} + +static void smart_bomb(void) +{ + u8 i; + if (!bombs || dead) return; + bombs--; + for (i = 0; i < NE; i++) if (etype[i] && on_screen(ex[i] >> 4)) kill_enemy(i); + for (i = 0; i < NM; i++) if (mlife[i] && on_screen(mx[i])) { mlife[i] = 0; boom(mx[i], my[i]); } + for (i = 0; i < NS; i++) { slife[i] = 0; spr_off(SP_SHOT + i); } + say("SMART BOMB"); +} + +static void hyperspace(void) +{ + if (dead) return; + px = rnd() % WORLD; + py = TOP_Y + 10 + (rnd() % (BOT_Y - TOP_Y - 20)); + vx = 0; + off = facing ? 208 : 104; + cam = wrapx((i16)px - off); + set_scroll(); + draw_all(); + inv = 30; +} + +static void fly(u8 j) +{ + i16 target, want, d; + if (dead) return; + if (j & J_LEFT) facing = 1; + if (j & J_RIGHT) facing = 0; + if (j & (J_LEFT | J_RIGHT)) { + vx += facing ? -5 : 5; + if (vx > 64) vx = 64; + if (vx < -64) vx = -64; + } else if (vx > 0) vx -= vx > 2 ? 2 : vx; + else if (vx < 0) vx += vx < -2 ? 2 : -vx; + if ((j & J_UP) && py > TOP_Y + 4) py -= 2; + if ((j & J_DOWN) && py < BOT_Y) py += 2; + /* move the ship */ + d = vx + pxf; + px = wrapx((i16)px + (d >> 4)); + pxf = d & 15; + /* the camera keeps the ship a third of the way in from behind, and + swings across when it turns, 4 columns a frame at most */ + target = facing ? 208 : 104; + if (off < target) off += off + 3 < target ? 3 : target - off; + else if (off > target) off -= off - 3 > target ? 3 : off - target; + want = (i16)px - off; + d = dist(cam, wrapx(want)); + if (d > 4) d = 4; + if (d < -4) d = -4; + scroll_by(d); + off = dist(cam, px); + spr_at(SP_SHIP, off - 8, (i16)py - 8, S_SHIP, ((inv & 4) ? 0 : 1) | (facing ? 2 : 0)); +} + +/* ------------------------------------------------------------- screens */ +static void clear_all(void) +{ + gfill = 0; + while (gfill & 1); + all_off(); +} + +static u8 wait_fire(void) +{ + u8 j; + while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); } + for (;;) { + wait_frame(); drain_keys(); rnd(); + j = joy; + if (j & J_ESC) return 0; + if (j & (J_FIRE | J_ENTER)) return 1; + } +} + +static u8 title(void) +{ + clear_all(); + puts_("\033[0m\033[2J"); + cam = 0; + set_scroll(); + draw_all(); + spr_at(0, 150, 150, S_SHIP, 1); + spr_at(1, 196, 120, S_LANDER, 1); + spr_at(2, 230, 140, S_MUTANT, 1); + spr_at(3, 110, 120, S_BOMBER, 1); + spr_at(4, 196, 202, S_HUMAN, 1); + ink("1;93"); centre(7, "S T A R W A R D E N"); + ink("0;97"); + centre(10, "Landers are stealing the humanoids from the planet."); + centre(11, "Shoot them, and catch the humanoids they drop."); + centre(12, "A lander that carries one to the top becomes a mutant."); + centre(15, "LEFT / RIGHT fly UP / DOWN climb and dive SPACE fire"); + centre(16, "SHIFT smart bomb ENTER hyperspace P pause ESC give up"); + ink("1;96"); centre(29, "PRESS SPACE TO BEGIN"); + ink("0"); + return wait_fire(); +} + +static void play(void) +{ + u8 j, i; + lives = 3; bombs = 3; score = 0; wave = 1; next_extra = 10000; + for (i = 0; i < NX; i++) xt[i] = 0; + for (i = 0; i < NL; i++) llife[i] = 0; + px = 160; py = 120; vx = 0; pxf = 0; facing = 0; off = 104; + clear_all(); + puts_("\033[2J"); + cam = wrapx((i16)px - off); + set_scroll(); + draw_all(); + start_wave(); + dead = 0; inv = 60; fire_cool = 0; bomb_held = 1; hyper_held = 1; + msg = 0; say("DEFEND THE HUMANOIDS"); + hud(); + for (;;) { + wait_frame(); + set_scroll(); + if (drain_keys()) { + at(1, 60); ink("0;93"); puts_("PAUSED - P TO GO ON\033[K"); ink("0"); + for (;;) { + wait_frame(); + if (joy & J_ESC) { quit = 1; return; } + if (drain_keys()) break; + } + hud_dirty = 1; + } + j = joy; + if (j & J_ESC) return; + if (j & J_SHIFT) { if (!bomb_held) smart_bomb(); bomb_held = 1; } else bomb_held = 0; + if (j & J_ENTER) { if (!hyper_held) hyperspace(); hyper_held = 1; } else hyper_held = 0; + fly(j); + lasers(j); + enemies(); + humans(); + mines_and_booms(); + shots(); + pool_end(); + if (inv) inv--; + if (msg_time && !--msg_time) hud_dirty = 1; + if (hud_dirty) hud(); + if (!scan_timer--) { scan_timer = 9; scanner(); } + if (dead && !--dead_time) { + if (!--lives) { + hud(); + ink("0;44;97"); + centre(14, " "); + centre(15, " GAME OVER "); + centre(16, " "); + ink("0"); + for (i = 0; i < 150; i++) { wait_frame(); drain_keys(); } + return; + } + dead = 0; inv = 120; vx = 0; + hud_dirty = 1; + } + if (!enemies_left() && !dead) { + i = humans_left(); + add_score((u16)i * 100 * (wave < 5 ? wave : 5)); + say("WAVE CLEARED"); + hud(); + for (j = 0; j < 120; j++) { wait_frame(); set_scroll(); drain_keys(); } + wave++; + start_wave(); + } + } +} + +int main(void) +{ + rnd_state = 0x2084 ^ frame_ctr; + last_frame = frame_ctr; + puts_("\033[?3l\033[?25l"); + load_shapes(); + quit = 0; + while (!quit) { + if (!title()) break; + play(); + } + clear_all(); + puts_("\033[0m\033[2J\033[H\033[?25h"); + while (con_stat & 1) (void)con_data; +} diff --git a/games/warden/warden.ihx b/games/warden/warden.ihx new file mode 100644 index 0000000..8ad9cf9 --- /dev/null +++ b/games/warden/warden.ihx @@ -0,0 +1,953 @@ +:10A2000097420000938282B617430000130383CC69 +:10A2100063F8620023A00200938242006FF05FFFA8 +:10A22000171300006700830C834700F093F72700A3 +:10A23000E38C07FEA300A0F067800000130101FF7C +:10A240002324810023261100130405000345040084 +:10A25000631A05008320C10003248100130101015A +:10A26000678000001304140097000000E78000FCE2 +:10A270006FF0DFFD130101FE232C8100232A9100E2 +:10A28000232E110093840500130400009306A00000 +:10A29000130690003377D5029307040093870701D4 +:10A2A000B3872700130414001374F40F1307070374 +:10A2B000238CE7FE930705003355D502E36CF6FCCB +:10A2C000636E9400631804028320C101032481019A +:10A2D000832441011301010267800000130500037C +:10A2E0009384F4FF97000000E78040F493F4F40FA8 +:10A2F0006FF01FFD1304F4FF1374F40F93070401B0 +:10A30000B387270003C587FF97000000E78000F2AE +:10A310006FF05FFB130101FF2322910093040500FE +:10A320001305B001232611002324810013840500A6 +:10A3300097000000E78080EF1305B005970000004C +:10A34000E780C0EE9305000013850400970000002D +:10A35000E78080F21305B00397000000E78000ED6E +:10A36000130504009305000097000000E780C0F08B +:10A37000032481008320C10083244100130580044D +:10A380001301010117030000670043EA130101FFF5 +:10A3900023248100130405001305B00123261100B6 +:10A3A00097000000E78080E81305B00597000000E3 +:10A3B000E780C0E71305040097000000E78040E84D +:10A3C000032481008320C1001305D006130101017D +:10A3D00017030000670083E5130101FF23248100B8 +:10A3E0002326110013840500930700003307F400AF +:10A3F00003470700631A070293D7170093059002DB +:10A40000B385F54093F5F50F97000000E780C0F0A5 +:10A4100013050400032481008320C10013010101FE +:10A42000170300006700C3E19387170093F7F70F46 +:10A430006FF0DFFBB7E7000003D507D713177500F0 +:10A440003345E50013150501135505011357950014 +:10A450003345E500131785003345E5001315050165 +:10A46000135505012398A7D667800000B7E70000C1 +:10A4700003C757D7834680F7E38EE6FE034780F78E +:10A48000A38AE7D667800000130500009306000545 +:10A49000834700F093F7170063940700678000007C +:10A4A000034710F01377F70D6304D70093070500F7 +:10A4B000138507006FF0DFFDB7E700001307800783 +:10A4C00023A6A7D6B7E700002384E7D6B7E70000A6 +:10A4D00013071000A389E7D66780000093070500E3 +:10A4E00063CC07001307F04F1395070113550501BF +:10A4F000634CF7006780000093870750939707012C +:10A5000093D707416FF0DFFD130505B093170501E1 +:10A5100093D707416FF05FFD3385A5409317050181 +:10A5200013150501135505411307002893D707019B +:10A53000635AA700938707B0139507011355054188 +:10A5400067800000130700D8E35CE5FE938707509F +:10A550006FF09FFE3305B500931705011315050134 +:10A560001355054193D7070137570000634805008D +:10A5700037570000634AE50037B7FFFFB387E700AE +:10A5800013950701135505411315050113550501D1 +:10A5900067800000130705009307F01363ECE70CD6 +:10A5A000B7D700009386872EB386A6009305E04FA9 +:10A5B00003C606009387872E9306000063E4A50078 +:10A5C00093061500B387D70083C6070093070600DC +:10A5D00063F4C6009387060013F8F70F930706008D +:10A5E0006374D6009387060093F8F70F93773500CE +:10A5F000639A070893067004B306D5029307E00632 +:10A600009305F000B3E6F602937785009386260261 +:10A61000639A070013750501930570006304050034 +:10A620009305E00013538700930700001377F70F9B +:10A630001305000F63E607011306300063FCF80002 +:10A64000138605006388F600138647F1133616005B +:10A65000131626002308E0F2A30860F22309F0F2A3 +:10A6600093871700A309C0F293F7F70FE394A7FCB1 +:10A6700067800000130707EC131707011357070142 +:10A680006FF0DFF193050000930600006FF09FF973 +:10A69000B7E7000083D7C7EC1307F0136360F70236 +:10A6A00013F7F70F93E70720A30AE0F293D7870089 +:10A6B000230BF0F2A30B00F267800000938707ECF6 +:10A6C0009397070193D707016FF05FFD130101FF17 +:10A6D000232481002322910023202101232611001D +:10A6E0001304000037E90000930400140355C9EC7B +:10A6F0003305A40013150501130414001355054177 +:10A700001314040197000000E78080DD1354040156 +:10A7100097000000E78040E8E31A94FC8320C10022 +:10A720000324810083244100032901001301010156 +:10A7300067800000B7E700009305050003D5C7EC6C +:10A74000130101FF2326110097000000E78000DDC0 +:10A750008320C10013150501135505011335051498 +:10A760001301010167800000B7E7000093060000B5 +:10A7700013070000938787D7930850003388F600AB +:10A780003386E70003480800034606006374C800E8 +:10A7900013F7F60F93861600E39216FFB7E6000054 +:10A7A00013161700938686D8B386C6002390A6009A +:10A7B000B7E60000938606D8B386E600B387E700C5 +:10A7C000130740012380B6002380E7006780000064 +:10A7D000130101FFB7E700009305100013051000F7 +:10A7E00023261100A38907D6232481002322910068 +:10A7F00097000000E78040B237D500001305C5FE82 +:10A8000097000000E780C0B837D50000130545FF6A +:10A8100097000000E780C0A2B7D400001385440071 +:10A8200097000000E780C0B637D500001305C500CB +:10A8300037D4000097000000E78080A01305440192 +:10A8400097000000E780C0B4B7E7000003D507EC2D +:10A850009305600097000000E78000A21385440084 +:10A8600097000000E780C0B237D500001305C5018E +:10A8700097000000E780C09C13054401970000008A +:10A88000E78000B1B7E7000003C577EC930500004F +:10A8900097000000E780409E138544009700000069 +:10A8A000E78000AF37D50000130585029700000050 +:10A8B000E78000991305440197000000E78040AD50 +:10A8C000B7E7000003C567EC9305000097000000A0 +:10A8D000E780809A1385440097000000E78040AB32 +:10A8E00037D500001305450397000000E780409529 +:10A8F0001305440197000000E78080A9B7E7000036 +:10A9000003C557EC9305000097000000E780C09650 +:10A91000B7E7000003A4C7D6630E0402B7E7000040 +:10A9200083C787D66388070237D50000130505045F +:10A9300097000000E780C0A537D500001305850407 +:10A9400097000000E780C08F130504009700000007 +:10A95000E780008F37D500001305C504970000007D +:10A96000E780008E032481008320C10083244100FE +:10A9700037D5000013050505130101011703000079 +:10A98000670003A1B7E700009305050003D5A7EC16 +:10A99000130101FF2326110097000000E78000B893 +:10A9A0001305052813150501135505411355454099 +:10A9B0009307F00463CCA700130515001375F50F7A +:10A9C0008320C10013010101678000001305000509 +:10A9D0006FF01FFF37E7000093070000130500002A +:10A9E000130747E01306300093068000B385E700A5 +:10A9F00083C505006386C500130515001375F50FA3 +:10AA000093871700E394D7FE67800000130101FECF +:10AA10002328210137E90000232C8100232631015E +:10AA2000232E1100232A91002324410123225101C6 +:10AA3000232061019309050013040000130909EBA9 +:10AA400013070001B307240183C7070063980710A9 +:10AA5000930A005037EA0000130B301097000000F3 +:10AA6000E780809DB37455030355AAEC93850400D9 +:10AA700097000000E78080AA1357F540B347E50030 +:10AA8000B387E7409397070193D70741E358FBFC4F +:10AA9000B7E7000013171400938707E9B387E700AF +:10AAA00093944400330989002390970023003901CF +:10AAB000B7E4000097000000E7800098938704E85F +:10AAC0001375F503B3878700130585022380A7005C +:10AAD000B7E70000938747E6B38787002380070026 +:10AAE000B7E70000938747E51307F0FFB3878700B8 +:10AAF0002380E70097000000E7800094B7E700009C +:10AB0000938747E41375F507B38787001305C503DB +:10AB10002380A70097000000E780009213751500BE +:10AB2000938404E8130780FF630405001307800083 +:10AB3000B7E70000938747E3B3878700B3848400B7 +:10AB40002380E70003C70400B7E70000938747E2CC +:10AB5000B38787002380E7006F00C0001304140050 +:10AB6000E312E4EE8320C101032481018324410127 +:10AB7000032901018329C100032A8100832A41009E +:10AB8000032B01001301010267800000130101FD86 +:10AB9000B7E7000023248102232E3101232611026E +:10ABA0002322910223202103232C4101232A510136 +:10ABB000232861012326710123248101232291018D +:10ABC000138707EB23200700232207002324070015 +:10ABD0002326070037E70000232607DC1307C7DC1E +:10ABE000232207002324070037E70000230A07D8A1 +:10ABF000930650002308D0F6A30A00F6130747D99E +:10AC0000A3000700130660002308C0F6A30A00F69D +:10AC100023010700130670002308C0F6A30A00F6FC +:10AC2000A3010700130780002308E0F6A30A00F63B +:10AC3000B7E9000003C759EC138407EB3377D70259 +:10AC4000930610006316D70837E90000B7EA000042 +:10AC500037EA000037EC0000130949E193040000D3 +:10AC6000930B000A938ACAE0130B20FD130A4AE0F3 +:10AC7000130CCCDF930C800097F0FFFFE780C07BC4 +:10AC8000B38774031375F503130929003305F50021 +:10AC9000131505011355054197000000E780408416 +:10ACA000B387540123806701B387440123800700E1 +:10ACB000231FA9FE97F0FFFFE7800078B387840188 +:10ACC000137515002380A70093841400E39694FB6A +:10ACD00083C759EC9306C00093872700939717000A +:10ACE0001387070093F7F70F63F4F6001307C0000C +:10ACF0001379F70F930400006396240903C759ECF6 +:10AD0000930640009307070063F4E60093074000B2 +:10AD10009387F7FF93F4F70F130900006360990816 +:10AD200097000000E78040CB6314050293070400FE +:10AD300013070401930610001306200083C50700C3 +:10AD40006394D5002380C70093871700E398E7FE3C +:10AD50008320C102032481028324410203290102CA +:10AD60008329C101032A8101832A4101032B0101A7 +:10AD7000832BC100032C8100832C410013010103AC +:10AD800067800000130510009384140097000000F2 +:10AD9000E78000C893F4F40F6FF01FF6130530003E +:10ADA0001309190097000000E78080C61379F90F96 +:10ADB0006FF0DFF6B7E7000003D707ECB7E6000057 +:10ADC0003305E50013150501135505012390A7EC84 +:10ADD00083D746E76362F50637270000130707713C +:10ADE000B387E70037E70000130101FF239AF6E677 +:10ADF000834777EC37D50000130545059387170087 +:10AE0000A303F7EC37E70000834767EC2326110024 +:10AE1000938717002303F7EC97F0FFFFE780006AA2 +:10AE20008320C100B7E7000013071000A389E7D60D +:10AE30001301010167800000B7E70000130710004D +:10AE4000A389E7D667800000130101FF2322910048 +:10AE5000B7E40000938704EB23248100232611002C +:10AE6000B387A70083C7070013071000130405006A +:10AE7000938404EB6396E70CB7E70000938747E6FB +:10AE8000B387A70003C7070093072000631EF704DA +:10AE9000B7E70000938747E5B387A70083C607009D +:10AEA0009307700063E2D704B7E70000938747E099 +:10AEB000B387D7002380E700B7E7000037E700003B +:10AEC000938747DF1307C7E0B387D7003307D7005F +:10AED0002380070003470700B7E700009387C7DE1A +:10AEE000B387D7002380E7001305600997000000AF +:10AEF000E78080EC37E7000093161400B7E7000006 +:10AF0000130707E93307D700938707E8B38787005C +:10AF10000355070083C50700B3848400135545001B +:10AF200097000000E7808084238004008320C10014 +:10AF30000324810083244100130101016780000084 +:10AF400013073000E392E7FA1305A00F6FF01FFA22 +:10AF5000130101FE232C810037E40000130444E4B4 +:10AF6000232E1100232A91002328210123263101B9 +:10AF7000232441013304A4008347040063860702AD +:10AF80009387F7FF2300F4008320C101032481018C +:10AF900083244101032901018329C100032A81007F +:10AFA00013010102678000009384050093090500E6 +:10AFB00097F0FFFFE7804048B7E700001375F503FF +:10AFC00083C747ECB384A40023009400E39E07FAF0 +:10AFD000B7E7000013971900938707E9B387E700E5 +:10AFE00003D90700135A490013050A0097F0FFFF21 +:10AFF000E7808074E30A05F8B7E40000130400005A +:10B00000938444D913074000B307940083C7070013 +:10B01000639C070CB7E7000083D5A7EC13050A0073 +:10B0200097F0FFFFE780804F37E70000130707E83E +:10B03000930705003305370137E700008345050016 +:10B04000034787EC93D6F74033C6D7003307B740A2 +:10B050003306D6401358F7403345070193060600E0 +:10B0600013160601B3080541135606416354160131 +:10B07000938608009396060193D60641E38606F070 +:10B0800093975700B3C7D7021317570037E600004E +:10B0900013151400130606DB3306A6002310260141 +:10B0A00037E60000130686DA3306A60093954500BE +:10B0B0002310B60037E60000130606DA3306A600B2 +:10B0C000B38484003347D7022310F600B7E70000AB +:10B0D000938787D9B387A7002390E7009307A0053C +:10B0E0002380F4006FF05FEA13041400E31EE4F021 +:10B0F0006FF09FE9230A00F2834740F393F71700AC +:10B10000E39C07FE130700022308F0F6938717005D +:10B11000A30A00F693F7F70FE398E7FEB7E70000FE +:10B12000238B07D6678000009387F500939707016C +:10B130002308A0F693D707011305E014636CF5000C +:10B140009307F6009397070193D707011305E00FC4 +:10B150006376F500A30A00F66780000093F7F50F09 +:10B1600093D58540A308F0F693F515002309B0F6B2 +:10B170001376F60FA309C0F6230AD0F6A30AE0F669 +:10B180006780000037E70000B7E6000083C636ECB2 +:10B19000834747ECB3E7D700B7E6000083C626EC49 +:10B1A000B3E7D700639A070893071000130101FF64 +:10B1B0002302F7EC13074006B7E70000A38CE7E68D +:10B1C000B7E7000083C587ECB7E7000003D5A7EC1D +:10B1D0002326110097F0FFFFE7804059230800F66F +:10B1E000A30A00F6B7E70000238A07D81307500028 +:10B1F0002308E0F6A30A00F6938747D9A380070047 +:10B20000130760002308E0F6A30A00F62381070075 +:10B21000130770002308E0F6A30A00F6A3810700D5 +:10B22000930780002308F0F6A30A00F68320C100EC +:10B23000130101016780000067800000130101FE17 +:10B24000B7E70000232A91009384050093050500C9 +:10B2500003D5C7EC232E1100232C810023282101C4 +:10B260002326C10097F0FFFFE780402B131505014F +:10B27000135505019307F5009397070193D707012D +:10B280001307E0146366F70437E90000034479D735 +:10B2900093077001630EF402930585FF8326C100B6 +:10B2A000938484FF1305940013960401939505017C +:10B2B000130710001356064193D505411375F50F7A +:10B2C0001304140097000000E78040E6A30B89D622 +:10B2D0008320C10103248101832441010329010149 +:10B2E0001301010267800000130101F8232E1106EB +:10B2F000232C8106232A91062328210723263107A0 +:10B30000232441072322510723206107232E71059F +:10B31000232C8105232A91052328A1052326B10585 +:10B32000834780F73727000013074708B3C7E700B4 +:10B3300037E700002318F7D6834780F737D500009A +:10B3400037E700001305050AA30AF7D697F0FFFFB9 +:10B35000E78000EFB7D700009387877E13070000D0 +:10B360009306B000230BE0F61386070883C5070099 +:10B3700093871700A30BB0F6E39AC7FE13071700D5 +:10B380001377F70FE310D7FEB7E70000238A07D63D +:10B39000B7270000938707712319F102B7E7000070 +:10B3A000938787DD2328F100B7E7000083C747D7DD +:10B3B0006390071E97000000E78000D437D5000097 +:10B3C0001305C50A97F0FFFFE78080E7B7E70000A5 +:10B3D000239607EC97F0FFFFE780C02B97F0FFFF65 +:10B3E000E780002F930760F9230800F6A308F0F622 +:10B3F000230900F6A309F0F6230A00F693071000CC +:10B40000A30AF0F62308F0F6130740FCA308E0F6C1 +:10B41000230900F613068007A309C0F6230AF0F6F5 +:10B42000A30AF0F6930620002308D0F6930560FEE9 +:10B43000A308B0F6230900F69305C0F8A309B0F6F7 +:10B44000230AD0F6A30AF0F6930630002308D0F6BC +:10B450009305E006A308B0F6230900F6A309C0F699 +:10B46000230AD0F6A30AF0F6930640002308D0F68C +:10B47000A308E0F6230900F61307A0FCA309E0F6F1 +:10B4800013075000230AE0F637D50000A30AF0F6B0 +:10B490001305850B97F0FFFFE78080EFB7D500001D +:10B4A0009385050C1305700097F0FFFFE78000F30C +:10B4B00037D500001305450197F0FFFFE78040ED09 +:10B4C000B7D500009385850D1305A00097F0FFFF09 +:10B4D000E780C0F0B7D500009385C5101305B00014 +:10B4E00097F0FFFFE78080EFB7D500009385C51385 +:10B4F0001305C00097F0FFFFE78040EEB7D50000CE +:10B50000938545171305F00097F0FFFFE78000EDE6 +:10B51000B7D500009385051B1305000197F0FFFFC9 +:10B52000E780C0EB37D500001305051F97F0FFFF3C +:10B53000E78000E6B7D500001305D0019385851F8D +:10B5400097F0FFFFE78080E9B7D700001385070574 +:10B5500097F0FFFFE780C0E3834780F893F7070B7E +:10B56000639C070897F0FFFFE78080F097F0FFFFEC +:10B57000E780C0F197F0FFFFE78000EC834780F899 +:10B5800013F7F70F9397870193D7874163D0070885 +:10B5900097000000E78040B637D50000130505216D +:10B5A00097F0FFFFE780C0C9834700F093F71700CB +:10B5B000638407006F1010238320C10703248107D1 +:10B5C00083244107032901078329C106032A810631 +:10B5D000832A4106032B0106832BC105032C810519 +:10B5E000832C4105032D0105832DC10413050000A3 +:10B5F000130101086780000097F0FFFFE78040E734 +:10B6000097F0FFFFE78080E86FF01FF5937707035F +:10B61000E38A07F49307300037E70000A303F7EC51 +:10B6200037E700002303F7EC03572103B7E70000D7 +:10B6300013091000239007ECB7E7000037E400007F +:10B64000A38227EDB7E70000239AE7E6930784D7A4 +:10B6500023820700B7E7000023AC07DAB7E4000055 +:10B660009307000A2395F4ECB7ED000093078007D9 +:10B670002384FDECB7E70000239F07E6B7E700004F +:10B68000A38E07E6B7E7000037E70000238E07E642 +:10B6900093078006231DF7E6232C04D697000000AD +:10B6A000E78080A537D500001305050B97F0FFFF55 +:10B6B000E78000B903D5A4EC130585F9131505013E +:10B6C0001355054197F0FFFFE78080E1B7E70000E1 +:10B6D0002396A7EC97F0FFFFE780C0FB97F0FFFFF2 +:10B6E000E78000FF97F0FFFFE780804AB7E70000A0 +:10B6F0001307C003238207ECB7E70000A381E7EC40 +:10B70000B7E70000238C07E6B7E70000A38B27E725 +:10B7100037D50000B7E70000238B27E71305452244 +:10B72000B7E7000023A607D697F0FFFFE78000D910 +:10B7300097F0FFFFE780000A930784D72320F102E8 +:10B7400097F0FFFFE780C0D297F0FFFFE78080F41B +:10B7500097F0FFFFE78080D3630205089305C003DD +:10B760001305100097F0FFFFE78000BB37D50000FE +:10B770001305C5FE97F0FFFFE78080C137D50000B5 +:10B780001305C52397F0FFFFE78080ABB7D7000014 +:10B790001385070597F0FFFFE78080BF97F0FFFF55 +:10B7A000E78000CD834780F89397870193D787413F +:10B7B00063DA07009307100037E70000230AF7D683 +:10B7C0006FF09FBE97F0FFFFE78040CCE30805FCD9 +:10B7D000B7E7000013071000A389E7D6834780F876 +:10B7E00013F4F70F9397870193D78741E3CE07BAF6 +:10B7F0009377040437E9000037EA000063880712F2 +:10B8000083477AE763920712B7E6000083C766ECC6 +:10B81000638C0710034749EC631807109387F7FF01 +:10B82000B7EB0000B7E900002383F6EC938B0BE93C +:10B83000130B0000938909EB930A0001B3073B0146 +:10B8400083C707006382070203D50B001355450029 +:10B8500097F0FFFFE78040EE630805001375FB0FCC +:10B8600097F0FFFFE780805E130B1B00938B2B008C +:10B87000E3165BFD37EB000037EC0000130BCBDC6D +:10B88000130C0CDE930B0000930A600083570B002F +:10B89000638A070283590C001385090097F0FFFFA4 +:10B8A000E78080E9630005028327010123100B0074 +:10B8B00013850900B387FB0083C5070097F0FFFFDE +:10B8C000E780C0EA938B1B00130B2B00130C2C009A +:10B8D000E39E5BFBB7E70000238A07D813075000FD +:10B8E0002308E0F6A30A00F6938747D9A380070050 +:10B8F000230870F7A30A00F62381070013077000DE +:10B900002308E0F6A30A00F6A3810700930780004E +:10B910002308F0F637D50000A30A00F613054525E5 +:10B9200097F0FFFFE78080B993071000A30BFAE6BA +:10B9300093770402B7E900006382070A83C769E7C7 +:10B94000034749ECB3E7E7006398070897F0FFFF68 +:10B95000E78080AE930700503375F5022395A4EC81 +:10B9600097F0FFFFE78040AD9307000A3375F502BB +:10B97000B7E70000239F07E6B7E7000003C7C7E764 +:10B98000930780061305C5022384ADEC630407000A +:10B990009307000D03D5A4EC37E70000231DF7E65D +:10B9A0003305F540131505011355054197F0FFFFC9 +:10B9B000E78000B3B7E700002396A7EC97F0FFFFFE +:10B9C000E78040CD97F0FFFFE78080D0B7E7000029 +:10B9D0001307E001A381E7EC93071000238BF9E63E +:10B9E000834749EC639C072413774400B7E70000C2 +:10B9F0006306070013071000238EE7E61377840021 +:10BA000063040700238E07E683C9C7E7B7E7000092 +:10BA10008396E7E79377C40013970601135707014E +:10BA2000638C075E9307500063860900B707010027 +:10BA30009387B7FFB387E7009397070193D7074131 +:10BA4000130700046350F75CB7E70000239FE7E6A5 +:10BA500093771400638C070083C78DEC1307600293 +:10BA60006376F7009387E7FF2384FDEC9377240048 +:10BA7000638C070083C78DEC1307500D6366F700D6 +:10BA8000938727002384FDECB7EA000037E7000026 +:10BA900083C7DAE70355E7E73305F500131A050115 +:10BAA00083D7A4EC131505011355054113554540E3 +:10BAB0003305F50013150501135A0A011355054105 +:10BAC00097F0FFFFE780C0A1137AFA002395A4EC5A +:10BAD000A38E4AE793078006638409009307000D4D +:10BAE000B7E500000397A5E79316070193D6060173 +:10BAF0006354F75613073700130630006348F70006 +:10BB0000B387D74013960701135606013306D600B4 +:10BB1000239DC5E6B7E7000003DAC7ECB7E70000EE +:10BB200083D7A7E73305F5401315050113550541E4 +:10BB300097F0FFFFE780C09A9305050013050A0000 +:10BB400097F0FFFFE780809D1307C0FF9307050074 +:10BB50006354E5009307C0FF13970701135707418C +:10BB60009306400063D4E60093074000939A0701D0 +:10BB700093DA0A41930700006356A054139A070111 +:10BB8000B7E7000003D5C7EC135A0A0113050514E3 +:10BB90003305AA00131505011355054197F0FFFF62 +:10BBA000E780009497F0FFFFE780009F93071A005B +:10BBB0009397070193D70741E3C257FD37EA000087 +:10BBC0000355CAEC330555011315050113550541FD +:10BBD00097F0FFFFE780C09083D5A4EC2316AAEC72 +:10BBE00097F0FFFFE7808093B7E70000239DA7E66B +:10BBF000B7E7000083C737EC03C68DEC130585FF5C +:10BC000093D7270093C7170033373001130686FFF9 +:10BC10009315050193F71700131717001316060164 +:10BC200033E7E700930600001356064193D505411C +:10BC30001305000097F0FFFFE780404F9377040162 +:10BC400037E40000B7E90000130484DB638A0700CF +:10BC5000834749EC03C789E7B3E7E70063840750EC +:10BC600083C789E7638607009387F7FF238CF9E68C +:10BC700037E9000037EA0000B7EA0000B7EB000040 +:10BC8000130909DC130A4ADC938ACADB130B100080 +:10BC9000938B0BEB83470400638A071A03C70A00E0 +:10BCA0009387F7FF2300F40003550A009307C000B1 +:10BCB00063060700B7070100938747FF3305F500C8 +:10BCC000131505011355054197F0FFFFE7804081EB +:10BCD000B7EC00002324A1002310AA00938C0CE9E8 +:10BCE000130C00009309B000130D0001B3077C0191 +:10BCF00083C70700638E074683D50C0003258100A8 +:10BD000093D5450097F0FFFFE78040819357F540BA +:10BD10003345F5003305F54013150501135505416D +:10BD20001307600063C6A944B7E70000938707E8DC +:10BD3000B307FC008346090083C70700B387D740D9 +:10BD40009396070193D6064193D6F640B3C7F60003 +:10BD5000B387D7409397070193D70701636AF740EA +:10BD60001375FC0F97F0FFFFE780400E23000400DF +:10BD7000B7E6000037E70000938906DE930CC7DCC6 +:10BD8000130C0000130D4000834704006384070A6E +:10BD900083D70C006386070883D709000325810039 +:10BDA000938507002326F10097E0FFFFE7800077E7 +:10BDB0009357F5403345F5003305F540131505015C +:10BDC000135505419307900063CCA7048327010115 +:10BDD000B307FC0083C5070083470900B387F5401C +:10BDE00013950701135505411355F540B347F50069 +:10BDF000B387A7409397070193D707016362FD02BA +:10BE00000325C10023900C0097F0FFFFE780009608 +:10BE10001305200397F0FFFFE78000FA23000400DA +:10BE2000130C1C009307600093892900938C2C004D +:10BE3000E31CFCF483470400137CFB0F639207347C +:10BE400023000400230880F7A30A00F6130B1B004D +:10BE5000930750001304140013091900130A2A0051 +:10BE6000938A1A00E318FBE2B7E70000138707EB99 +:10BE7000938C07EB938707EB2322F102B7E70000CF +:10BE8000938747E12324F102B7E7000037E9000078 +:10BE90009387C7E02326E1002326F102130709E96F +:10BEA000B7E70000232AE10037EA000037E7000087 +:10BEB000B7E90000B7EA000037EB0000B7EB00007D +:10BEC000938747E0130407E8130A4AE6938949E594 +:10BED000938A4AE4130B4BE3938B4BE2130909E972 +:10BEE00023240100130D2000232EF10083C70C0032 +:10BEF000638A074003570900135C4700E38AA707DA +:10BF000093063000E380D712930610006390D73673 +:10BF100083450A006394053283050B00130507006F +:10BF200097E0FFFFE7804063B7E7000083C757D77C +:10BF30002310A90093F7F7016392070283C70B0050 +:10BF4000232CF10097E0FFFFE780004F832781015A +:10BF50001375F500B387A7002300F40003C7090099 +:10BF60009307F00F631AF72637E60000130646E141 +:10BF7000930600001308007D930880008327C10109 +:10BF8000B387D70083C70700639C07048355060067 +:10BF900013050C00232ED102232C0103232AE102D6 +:10BFA000232CC10097E0FFFFE78040579355F540F1 +:10BFB000B347B500B387B7400328810393970701C0 +:10BFC00093D7074103268101032741038326C10339 +:10BFD0009308800063D6070113F7F60F1388070054 +:10BFE0009386160013062600E39A16F92380E900CB +:10BFF0009305A0050325810097F0FFFFE78080F5FA +:10C000006F00C026130700FCE3C0E7A437E7000079 +:10C01000231FF7E66FF0DFA3635ED0001306200056 +:10C02000938706006354D600930720003307F74038 +:10C030006FF09FA1E38E06A01306E0FF9307200098 +:10C0400063C8C600B307E0409397070193D7070181 +:10C05000B387E7006FF09FFBE3DEE7AA1307D7FF84 +:10C060001306300063C8E700B387F6401396070154 +:10C0700013560601B386C640239DD5E66FF09FA9EF +:10C08000139A0701135A0A011305F5FF33054541B9 +:10C09000131505011355054197E0FFFFE780404464 +:10C0A00097E0FFFFE780404F93071A00939707013F +:10C0B00093D7074137E700000355C7ECE3C267FD9C +:10C0C0006FF0DFAF330B50416FF0DFFE1309190043 +:10C0D000E308E9B8B307890083C70700E39807FEC0 +:10C0E000B7E7000003CAC7E737050100130525FFBE +:10C0F00063140A001305E00083D7A4EC3305F500B0 +:10C10000131505011355054197E0FFFFE780403DFA +:10C11000B7E7000013171900938747DCB387E700E0 +:10C1200003C78DEC2390A700B7E70000938707DCD7 +:10C13000B307F900130717002380E700B7E70000F3 +:10C140009387C7DBB307F9002380470133098900D0 +:10C150009307A0012300F90093077000238CF9E6F0 +:10C160006FF01FB013090000130740006FF09FF637 +:10C17000130C1C00938C2C00E31AACB76FF05FBF5C +:10C180000325810097E0FFFFE780005BE30A05CA13 +:10C19000B7E700008325810003D5C7EC97E0FFFFD8 +:10C1A000E780C03703460900930585FF9395050195 +:10C1B000130686FF1316060113071000930660008E +:10C1C0001356064193D5054113050C0097F0FFFF68 +:10C1D000E780C0F56FF09FC78327C101B387E700F1 +:10C1E00083C70700638807009307F0FF2380F900E7 +:10C1F0006FF01FE0B7E7000013171700938747E1C0 +:10C20000B387E70083D5070013050C0097E0FFFF15 +:10C21000E780C0309357F5403345F5003305F540CE +:10C22000131505011355054193072000E3C2A7DC50 +:10C23000930710002300FA006FF09FDB03C609008C +:10C240006398F5469307700063ECC700B7E70000FA +:10C25000938747E0B387C70003C707006300074021 +:10C260009307F0FF23000A002380F90003C60C00A7 +:10C27000630A0608035C090093574C00232CF10065 +:10C28000B7E7000083C747EC034C0400639C0764D6 +:10C2900083D5A4EC03258101232AC10297E0FFFF87 +:10C2A000E780C0279357F5403345F5003305F54047 +:10C2B00013150501135505419307B00003264103EB +:10C2C00063C2A76283C78DECB307FC409396070156 +:10C2D00093D6064193D6F640B3C7F600B387D7404E +:10C2E0009397070193D707019306700063ECF65EFE +:10C2F0000325810097F0FFFFE78040B597F0FFFF2F +:10C30000E78080E883278100938C1C0013092900B3 +:10C310009387170093F7F70F2324F1000327810079 +:10C320009307000113041400130A1A0093891900DB +:10C33000938A1A00130B1B00938B1B00E318F7BAA8 +:10C3400037E40000930744E137E700002324F100BD +:10C35000B7E70000130A47E09389C7E0B7EA000097 +:10C3600037E90000130747E09387C7E0B7EB000009 +:10C37000938ACADF130949DF130444E1130B000059 +:10C38000232CE100232EF100930C20FD938BCBDEB8 +:10C39000130D200D130C300083470A0063880756E5 +:10C3A000130720006386E75C83470A00638C8701DC +:10C3B00083C50900035504001306500097F0FFFFE2 +:10C3C000E78000E8130B1B0093078000130A1A0094 +:10C3D0001304240093891900938A1A001309190081 +:10C3E000E31CFBFA37EC000037E40000130CCCDC54 +:10C3F000130404DE13090000B7EA0000130B7000F9 +:10C40000930B5000130A600083570C0063880708E1 +:10C410009387F7FF2310FC00832701018359040051 +:10C42000B307F90083CC070083C74AEC6392076621 +:10C4300083D5A4EC1385090097E0FFFFE780000E89 +:10C440009357F5403345F5003305F54013150501C5 +:10C4500013550541634EAB6283C78DECB387FC4037 +:10C4600013970701135707411357F740B347F700D6 +:10C47000B387E7409397070193D7070163EAFB600F +:10C4800093850C001385090023100C0097E0FFFF33 +:10C49000E780C02D97F0FFFFE78000CF1309190058 +:10C4A000130C2C0013042400E31049F78329010224 +:10C4B00037E4000037EA0000130484D813090000B1 +:10C4C000130A0AD837EB0000930A500083C709000B +:10C4D0006382070433074901834507009387F7FF09 +:10C4E00003474BEC93F7F70F2380F9000355040043 +:10C4F0006308070003D7A4EC1306A0006308A70095 +:10C5000093F7470013B617001306860097F0FFFF56 +:10C51000E78000D31309190093891900130424003C +:10C52000E31659FB37E90000B7EA0000B7EB00005B +:10C5300037EA000037EB0000130949D9938A0ADB78 +:10C54000938B0BDA130A8ADA130B8BD993095000F9 +:10C55000930CA00C37ED0000834709002324F1025F +:10C560006388070603D50A0083950B0097E0FFFF59 +:10C57000E78080FE83560B0003540A002390AA0034 +:10C58000130C05003304D4001314040113540401E4 +:10C5900023108A00135444001306E4FD1316060109 +:10C5A000135606019306000063E8CC00832781023E +:10C5B0009387F7FF93F6F70F83474DEC2300D900DD +:10C5C000639607546392064E230830F7A30A00F6D9 +:10C5D0009389190093F9F90F930790001309190033 +:10C5E000938A2A00938B2B00130A2A00130B2B002B +:10C5F000E394F9F637E70000834777D737E6000082 +:10C60000834666D763E6D754834777D7B7E90000F8 +:10C61000A30B07D6230BF6D683C739EC6386070036 +:10C620009387F7FFA381F9EC37E70000834787D6AC +:10C6300037E90000638C07529387F7FF93F7F70FF2 +:10C640002304F7D66394075293071000A309F9D681 +:10C6500097E0FFFFE78000186F00C05137E7000048 +:10C6600093161600130747E13307D7000357070057 +:10C6700083460400131747002310E90037E7000042 +:10C680001307C7E03307C700034707001385C60039 +:10C69000635AE500938616002300D40093058007B3 +:10C6A0006FF05F952300AA012380B7006FF01FFF92 +:10C6B000B7E7000083C757D793F7170063980700C1 +:10C6C000834704009387F7FF2300F40003278102C8 +:10C6D00093171600B307F700239087010347040060 +:10C6E0008327C1029306C700B387C7002380D70002 +:10C6F00093072002E3ECE7B6B7E70000938747E033 +:10C70000B387C700130730002380E700930720009A +:10C710002380FC0097E0FFFFE780002C6304050402 +:10C7200037D500001305050697E0FFFFE78000D925 +:10C7300097E0FFFFE780402AE31A05B28327C10094 +:10C7400093061000130620001387070183C5070016 +:10C750006394D5002380C70093871700E318F7FE82 +:10C760006FF0DFB037D50000130545076FF0DFFB32 +:10C7700083D5A4EC13050C00232CE10097E0FFFF08 +:10C78000E780C0D9032781019305A0FE6354A00070 +:10C79000930560011305070097E0FFFFE780C0DB0A +:10C7A0008347040003C78DEC2310A90063FEE70450 +:10C7B000938717002300F40097E0FFFFE780C0C7CE +:10C7C000137535006314050297E0FFFFE780C0C6CC +:10C7D000137515001307E0FF63040500130720001D +:10C7E00083470400B387E7002300F4008347040075 +:10C7F000130710026360F702930720022300F4007E +:10C80000930580026FF00FFFE378F7FA9387F7FF45 +:10C810006FF05FFA1307600DE374F7FE930760FD96 +:10C820006FF0DFFD83050B001305070097E0FFFFA6 +:10C83000E78080D2B7E7000083C757D703C70B0054 +:10C840002310A90093D7270093F7F700B387E700D9 +:10C850002300F40083C70A00638807009387F7FF6B +:10C860002380FA006FF09FA0232CF10097E0FFFFD8 +:10C87000E78080BC1375F5038327810137E700004B +:10C88000130565049306C7DC2380AA001307C7DCE1 +:10C890009305600003D60600631C0602B7E600009D +:10C8A00013961700938606DEB386C6002390860192 +:10C8B000832601013307C700B387F60083460400CF +:10C8C0002380D700930700192310F7006FF01F9AF9 +:10C8D0009387170093F7F70F93862600E39CB7FA28 +:10C8E0006FF0DF9893150C019307100093D5054165 +:10C8F0006306F6006304A6011306300003258101D8 +:10C9000097F0FFFFE780C0936FF0DF9FB7E700006D +:10C9100083C757D793F77700E39807A883C70A0020 +:10C920000355040013071000639607003707010042 +:10C930001307F7FF3305E5001315050113550541EE +:10C940002324F10297E0FFFFE78080B92310A400C1 +:10C9500097E0FFFFE78040AE1375F501E31605A4ED +:10C960008327810293C717002380FA006FF0DFA3AB +:10C97000B7E7000083C757D793F73700639A0700DC +:10C98000834709006366FC00938717002300F900C2 +:10C9900003C70900834709003307F700B7E7000022 +:10C9A00083C747EC1377F70F2380E90063960708E6 +:10C9B00083D5A4EC035504002324E10297E0FFFF94 +:10C9C000E780C0B59357F5403345F5003305F54092 +:10C9D00013150501135505411306B0000327810205 +:10C9E000634CA60483C78DECB307F7409396070109 +:10C9F00093D6064193D6F640B3C7F600B387D74027 +:10CA00009397070193D707016368F602930720FD08 +:10CA10001305401F23000A002380F90097E0FFFF61 +:10CA2000E780803937D500001305052697E0FFFF22 +:10CA3000E780C0A86FF05F979307100DE3F6E796C5 +:10CA4000B3077B0183C70700238099011307A00563 +:10CA5000B307FD406354F702035504009307300009 +:10CA60002300FA009305200D97E0FFFFE78000D038 +:10CA700037D50000130505276FF05FFB23000A0080 +:10CA80001305A00F97E0FFFFE78000336FF0DF9101 +:10CA90001306400093850C001385090097E0FFFF03 +:10CAA000E780007A6FF09F9F83D5A4EC13554C006C +:10CAB00097E0FFFFE78080A69356F540B347D50087 +:10CAC000B387D7409397070193D707419306600038 +:10CAD00063C2F60483C78DECB307F4409396070155 +:10CAE00093D6064193D6F640B3C7F600B387D74036 +:10CAF0009397070193D707019306400063ECF60074 +:10CB00002300090097E0FFFFE780006883470900E2 +:10CB1000E38C07AAB7E7000003D5C7EC93554C0098 +:10CB200097E0FFFFE780809F930585FF93950501C0 +:10CB30001307100093067000130684FF93D5054178 +:10CB40001385090097E0FFFFE780405E6FF05FA864 +:10CB50009386970093F6F60F2308D0F69387170075 +:10CB6000A30A00F693F7F70F6FF09FA9834739D711 +:10CB7000E39007AE37E70000834727D76386070CAB +:10CB80009387F7FF2309F7D6B7E6000083C746EC83 +:10CB90006380073837E70000834797E79387F7FFFD +:10CBA00093F7F70FA30CF7E66394073637E7000017 +:10CBB000834777EC9387F7FF93F7F70FA303F7EC1F +:10CBC000639A073297E0FFFFE780C0C037D50000C7 +:10CBD0001305052997D0FFFFE780807B37D400003D +:10CBE000930584291305E00097D0FFFFE780007FBD +:10CBF000B7D500009385852B1305F00097D0FFFF74 +:10CC0000E780C07D930584291305000197D0FFFFBD +:10CC1000E780C07C37D500001305050597D0FFFFDE +:10CC2000E7800077130460091304F4FF97E0FFFF27 +:10CC3000E78000841374F40F97E0FFFFE78000851E +:10CC4000E31404FE6FE04FF6930790002309F7D634 +:10CC5000130A200037D40000930A500013050A007D +:10CC60009305100097D0FFFFE780006B130A1A00AE +:10CC700013050428137AFA0F97D0FFFFE780405C72 +:10CC8000E31E5AFD37D500001305852897D0FFFF16 +:10CC9000E7800070930510021305200097D0FFFF76 +:10CCA000E78080671305B00597D0FFFFE780005845 +:10CCB000930510021305400097D0FFFFE780C06581 +:10CCC0001305B00597D0FFFFE7804056930500039A +:10CCD0001305200097D0FFFFE78000641305D005FF +:10CCE00097D0FFFFE78080549305000313054000B1 +:10CCF00097D0FFFFE78040621305D00597D0FFFF74 +:10CD0000E780C05237DB000013050B0997D0FFFF07 +:10CD1000E780006813040000930B3000130C30060A +:10CD2000930CF009930A800083278101B387870061 +:10CD300083C70700638677058327C101130A200094 +:10CD4000B387870083C707006376FC0033BAFC0013 +:10CD5000130A3A008327810003D5070097E0FFFFFD +:10CD6000E78080C29305050013050A0097D0FFFFF6 +:10CD7000E780805A1305E00297D0FFFFE780004B61 +:10CD80008327810013041400938727002324F100D4 +:10CD9000E31C54F937DA0000B7DA0000130400008E +:10CDA000930B1000130C3006930C3000130A8A0802 +:10CDB000938A8A098327C10083C707006384070811 +:10CDC00013050A00638A77011307200013850A0000 +:10CDD0006394E70013050B0997D0FFFFE780405BE2 +:10CDE000B7E70000938707E8B387870083C707008A +:10CDF000130D20006378FC00130DF009333DFD0096 +:10CE0000130D3D008327410103D50700135545004D +:10CE100097E0FFFFE78040B79305050013050D007D +:10CE200097D0FFFFE780404F8327C1001305F0062E +:10CE300083C70700639497011305300297D0FFFF63 +:10CE4000E780C03E8327C1001304140093871700B6 +:10CE50002326F1008327410193872700232AF1002D +:10CE600093070001E318F4F4B7E7000083C747EC29 +:10CE70006398070637D500001305C5FE97D0FFFF5E +:10CE8000E7800051B7E7000083C787EC130730063F +:10CE9000130420006378F7001304F0093334F4001E +:10CEA00013043400B7E7000003D5A7EC97E0FFFFB9 +:10CEB000E78080AD930505001305040097D0FFFFC0 +:10CEC000E7808045B7E7000083C7C7E71305E003A5 +:10CED000638407001305C00397D0FFFFE780003588 +:10CEE00037D500001305050597D0FFFFE780404ABE +:10CEF0006FF09FC993078007A381F9ECB7E70000A3 +:10CF0000239F07E693071000238206ECA309F9D6B6 +:10CF10009307000013070000130600018325410258 +:10CF2000B385E50083C50500638605009387170078 +:10CF300093F7F70F13071700E312C7FE03C746EC7A +:10CF4000B3E7E700638407006FE08FFF97E0FFFF20 +:10CF5000E78080A837E90000034759EC93065000AA +:10CF60009307070063F4E6009307500093F7F70F69 +:10CF70003305F50293074006130480073305F502D5 +:10CF8000131505011355050197E0FFFFE780C0E287 +:10CF900037D500001305852D97D0FFFFE78000529D +:10CFA00097E0FFFFE78000831304F4FF97D0FFFFB3 +:10CFB000E780004C1374F40F97D0FFFFE780806D7B +:10CFC00097D0FFFFE780804CE31004FE834759ECC5 +:10CFD00093871700A302F9EC97E0FFFFE78040BBBF +:10CFE0006FE00FF6834710F06FE00FDC303B393312 +:10CFF00000000000535441522057415244454E20F6 +:10D0000020200000303B33370000000053434F52D4 +:10D0100045200000303B393700000000202020531D +:10D020004849505320000000202020424F4D4253D9 +:10D03000200000002020205741564520000000001D +:10D04000303B393600000000202020001B5B4B00E5 +:10D0500030000000424F4E555320534849500000C5 +:10D06000412048554D414E4F4944204953204C4F93 +:10D070005354000054484520504C414E45542049DB +:10D0800053204C4F53540000303B39320000000015 +:10D09000303B393500000000303B393400000000DF +:10D0A0001B5B3F336C1B5B3F32356C001B5B306D91 +:10D0B0001B5B324A00000000313B393300000000A6 +:10D0C000532054204120522020205720412052201C +:10D0D000442045204E0000004C616E646572732050 +:10D0E00061726520737465616C696E672074686530 +:10D0F0002068756D616E6F6964732066726F6D2054 +:10D1000074686520706C616E65742E0053686F6F73 +:10D1100074207468656D2C20616E64206361746393 +:10D1200068207468652068756D616E6F696473202E +:10D13000746865792064726F702E000041206C6104 +:10D140006E646572207468617420636172726965CF +:10D1500073206F6E6520746F2074686520746F7023 +:10D16000206265636F6D65732061206D7574616EFB +:10D17000742E00004C454654202F205249474854F5 +:10D1800020666C79202020205550202F20444F57B6 +:10D190004E20636C696D6220616E642064697665FF +:10D1A00020202020535041434520666972650000CD +:10D1B000534849465420736D61727420626F6D62EA +:10D1C00020202020454E54455220687970657273A6 +:10D1D0007061636520202020502070617573652088 +:10D1E0002020204553432067697665207570000034 +:10D1F000313B393600000000505245535320535004 +:10D2000041434520544F20424547494E000000000D +:10D210001B5B306D1B5B324A1B5B481B5B3F32352F +:10D2200068000000444546454E4420544845204887 +:10D23000554D414E4F494453000000005041555355 +:10D240004544202D205020544F20474F204F4E1B47 +:10D250005B4B0000534D41525420424F4D42000061 +:10D2600048554D414E4F49442053415645440000D6 +:10D27000412048554D414E4F49442046454C4C00B5 +:10D280001B5B324B00000000303B333400000000D9 +:10D29000303B34343B393700202020202020202010 +:10D2A000202020202020202020202020202020207E +:10D2B00020202020202000002020202020202020AE +:10D2C000202047414D45204F564552202020202008 +:10D2D00020202020202000005741564520434C4567 +:10D2E0004152454400000000ADABABACAEACAAACC3 +:10D2F000AAA8A8A9A9A7A8A5A2A5A4A4A3A4A4A3D1 +:10D30000A1A4A5A6A6A7A8A9ACADACADADAAA9AA93 +:10D31000A7A7A7AAAAABA9A9AAABABABA9A5A3A388 +:10D32000A2A3A29F9F9D9D9996989B999A9A9A993C +:10D330009B9EA2A5A9ACAEADAEAFB1AFB0B0AFAC45 +:10D34000ABAAABADABABADAFB0AFB1B1AFAFB0AF00 +:10D35000AFACACABABACAAA8A6A4A5A8A8A8A6A441 +:10D36000A4A5A4A6A6A6A9A8A8A5A5A4A6A8A9AA56 +:10D37000ABA9A9AAABAAA6A5A6A7AAAAADAFAEAE0D +:10D38000ADB0B0B1B0B1B3B5B8B8B7B5B5B8B8BB5A +:10D39000BBBBBCB9B8B7B8B9B7B8B5B7B7B6B4B412 +:10D3A000B2B3B3B1B2B2B1B4B5B7B7B6B6B6B4B240 +:10D3B000B2B5B6B7B5B3B4B5B7B4B4B0ACABABAB4C +:10D3C000AAADAEAFAFADAEABABAFB1B0B3B5B4B568 +:10D3D000B5B4B3B2B5B3B5B8BABEBEC0C0BFC0C0B5 +:10D3E000BEBDBABBBBB9BBBAB7B9B8B8B6B5B3B2B4 +:10D3F000B1AEAEB0AFB0AFB1B3B3B2B3B3B5B9BA0B +:10D40000BABBBCBEBDBABAB9BABDBDBBBAB6B4B27E +:10D41000B2B2B3B3B4B2B1B2B0AFB0AFB0AFB0AEFE +:10D42000AEACA9A5A4A3A1A2A2A19F9F9E9FA1A0CB +:10D430009F9FA1A09E9D9D9C9EA1A1A09F9E9C9E02 +:10D440009E9D9C9C989697989B9C9B9C9F9D9C9B2B +:10D450009D9D9B9B999693929190908F8F8E918F8B +:10D460008F90918E8E8D898A8A8E8F9293949493C9 +:10D470009494939698999CA0A29FA0A2A2A5A5A6D9 +:10D48000A6A8A7A7A8ABABADADACAAACABACADAEF4 +:10D49000AFB1B1B2B2B1B3B2B3B3B1B2B1B2B0AD78 +:10D4A000ADADACABABABABADAEABA9A7A6A7A5A4DE +:10D4B000A6A5A5A4A29FA09C9B9B9B9A9A9999998B +:10D4C0009B9C9E9D9D9B999B9B9B9A9998999A98B2 +:10D4D00098989A999A9A9B98979796999A9A9D9FB5 +:10D4E000A0A3A4A4A8A5A6A6A7A39F9F9C9A999A27 +:10D4F0009A979697969897989A98969796969697B9 +:10D50000959597979595969B9B9D9C9C9F9D9E9B83 +:10D510009C999595949493959494949598999C9F9F +:10D52000A2A2A0A1A2A4A4A5A4A5A4A09FA09F9EDE +:10D530009E9D9E9F9F9F9FA2A5A39FA09E9F9D9DF6 +:10D540009FA09F9F9EA0A2A3A5A5A7A6A7A5A5A7AC +:10D55000A8A9ABADAEADAEB0B3B2B2B4B2B3B4B4D1 +:10D56000B4B4B6B8BABAB9B7B9B6B7B7B5B6B5B64E +:10D57000B4B3B1B2B1B2B1B2B0AFAFB0ADADAFACA8 +:10D58000ACAEAEADB0AFADACADABA9A9A7A8A6A6E9 +:10D59000A8A9A8A8ABA9A9AAACAAA9A9ABAAA9AAF3 +:10D5A000ADAFB0B3B8BAB9BABABBBCC0C3C2C4C5D8 +:10D5B000C4C2C4C4C4C4C5C7CACCCCCBCBCBCECEEA +:10D5C000CCCBC9C8C9C8C8C9C7C5C6C1C0C1C3C2F8 +:10D5D000C2C3C2C3C7C9C7C7C7C6C6C6C6C3C2C0FF +:10D5E000C1C1C2C3C2C0C1C0BEBEBDBDBBBCBDBD4A +:10D5F000BBBDBEC0C2C2C3C3C4C3C2C2C0BFBAB92E +:10D60000B8B8B7B7B9B7B8B7B7B8B8B8B8B9BBBE94 +:10D61000BFBFC1C1BFBFC0C3C6C9CACAC8CACCCCBC +:10D62000CBC9C7C8C7C7C7C6C4C2C3C5C8C8C8C690 +:10D63000C4C5C5C6C6C4C2C0C0BFBDBCBEBFBDBEDA +:10D64000C0C0C0C3C5C5C5C4C4C5C8C9C9C9CBC984 +:10D65000C8C9CACFD2D3D5D6D6D4D2D3D2D3D2D4B6 +:10D66000D4D5D6D7D6D8D8DBDCDCD9DBD9D8D8D737 +:10D67000D8D6D4D3D2D1D0D1D1D1CECFCECECCCB9F +:10D68000CDCBCBC8C4C3C0BFC1C4C3C3C1C0BDBD63 +:10D69000BABABDBEBCBCBBBAB9B7B4B6B5B4B5B501 +:10D6A000B3B3B6B5B6B5B6B3B2B2AFADABAAA7A673 +:10D6B000A5A3A4A3A4A3A4A3A0A0A1A1A3A09E9F4B +:10D6C0009E9EA19E9F9EA09E9EA0A1A0A19F9D9C6C +:10D6D0009C9D9E9D9D9E9FA0A3A2A1A1A1A3A3A24C +:10D6E000A2A4A4A3A5A4A1A2A19F9E9E9E9E9E9D2E +:10D6F0009B9C9996959593928F8F8F8E91919393F2 +:10D70000939493919191919190929191928F8E8E09 +:10D710008F8D8E8D8D8C8E8E8C8B898A8B8B8A8C47 +:10D720008D8B8B8988898A8B8A888885868988876A +:10D7300089898A8B89868585858687878A8986886F +:10D74000878784807D7E7C7D7B7C7D7E7D808184DF +:10D75000858588898A88878686858785868788865D +:10D7600085858986878786878686888B8B8A8C8F36 +:10D770008F91939293928F8F908E8B8B898A898BC6 +:10D780008B8B8A88898A898A8D8A8B8D8C8A8987F6 +:10D790008485858382848383868685848688888C35 +:10D7A0008E8F9192908F8D8C8A8B8A898A8D908FA3 +:10D7B00091908E90908D8C8C8C8D8C8A8A8A8989A0 +:10D7C0008989898989898B9092939194949694926E +:10D7D00092939694959A9B9E9FA0A0A0A2A5AAAA78 +:10D7E000ADAEACABAAADAEAF0000000000000000D3 +:10D7F0000000000000000000000000000000000029 +:10D800000000000000000000000000000000000018 +:10D810000F000000000000000FF000006600000094 +:10D82000BFFFFFF666600000BFFFFFFFFFFFFF00C6 +:10D830000CCCCCCCCCCCC0000FF000000000000021 +:10D840000F000000000000000000000000000000C9 +:10D8500000000000000000000000000000000000C8 +:10D8600000000000000000000000000000000000B8 +:10D8700000000000000000000000000000000000A8 +:10D8800000000BBBBBB000000000BBBBBBBB00007B +:10D89000000AAAAAAAAAA00000AA2AA2AA2AAA0042 +:10D8A00000AAAAAAAAAAAA00000AAAAAAAAAA0002A +:10D8B0000000A00AA00A0000000A000AA000A000C0 +:10D8C00000A0000AA0000A00000000000000000004 +:10D8D0000000000000000000000000000000000048 +:10D8E0000000000000000000000000000000000038 +:10D8F00000000000000000000000D00000D0000088 +:10D9000000000D000D000000000DDDDDDDDD00007C +:10D9100000DDAADDDAADD0000DDDAADDDAADDD0077 +:10D9200000DDDDDDDDDDD000000D0D0D0D0D000095 +:10D9300000D0D0D0D0D0D000000000000000000007 +:10D9400000000000000000000000000000000000D7 +:10D9500000000000000000000000000000000000C7 +:10D9600000000000000000000000000000000000B7 +:10D9700000000000000000000000000000000000A7 +:10D9800000000000000000000000CCCCCCCC000067 +:10D990000000C444444C00000000C4EEEE4C000003 +:10D9A0000000C4EEEE4C00000000C444444C0000F3 +:10D9B0000000CCCCCCCC0000000000000000000037 +:10D9C0000000000000000000000000000000000057 +:10D9D0000000000000000000000000000000000047 +:10D9E0000000000000000000000000000000000037 +:10D9F0000000000000000000000000000000000027 +:10DA00000000000000000000000000000000000016 +:10DA1000000000000000000000000009900000006D +:10DA2000000000999F000000000000F9990000002C +:10DA3000000000099000000000000000000000004D +:10DA400000000000000000000000000000000000D6 +:10DA500000000000000000000000000000000000C6 +:10DA600000000000000000000000000000000000B6 +:10DA700000000000000000000000000000000000A6 +:10DA80000000000000000000000000000000000096 +:10DA900000000000000000000000000FF000000087 +:10DAA0000000000FF0000000000000DDDD000000BD +:10DAB00000000D0DD0D000000000000DD0000000CF +:10DAC0000000000CC0000000000000C00C000000BE +:10DAD000000000C00C00000000000000000000007A +:10DAE0000000000000000000000000000000000036 +:10DAF0000000000000000000000000000000000026 +:10DB00000000000000000000000000000000000015 +:10DB10000000000000000000000000000000000005 +:10DB20000000000000000000BFFFFFFFFFFFFFFB41 +:10DB300000000000000000000000000000000000E5 +:10DB400000000000000000000000000000000000D5 +:10DB500000000000000000000000000000000000C5 +:10DB600000000000000000000000000000000000B5 +:10DB700000000000000000000000000000000000A5 +:10DB80000000000000000000000000000000000095 +:10DB90000000000000000000000000000000000085 +:10DBA0000000000F9000000000000009F0000000DD +:10DBB0000000000000000000000000000000000065 +:10DBC0000000000000000000000000000000000055 +:10DBD0000000000000000000000000000000000045 +:10DBE0000000000000000000000000000000000035 +:10DBF0000000000000000000000000000000000025 +:10DC000000000000099000000000990099900000B9 +:10DC1000000000B0B0990000000900BFFF0900003B +:10DC2000000990FFF00000000000BBFFF0B9900079 +:10DC3000000090BBFBB90000000099BBBB000000D6 +:10DC40000000099009000000000000000000000032 +:10DC500000000000000000000000000000000000C4 +:10DC600000000000000000000000000000000000B4 +:10DC70000000001000000000000000100000000084 +:10DC80000010010000000000001109090900000057 +:10DC900000000000999900000109090BBB00000079 +:10DCA000010090BBB000900011000BBBBB990100BC +:10DCB0000019090B0B0900010000090090099010E0 +:10DCC00000010000000010000100000090001000A2 +:10DCD0000000101000000000000000000011000013 +:10DCE000000000011000000000000B0B000000000D +:10DCF000000000000B0000000000000B000000000E +:10DD0000000B0FF0000F0B000B000000F0FF0B00EA +:10DD10000B000000FF0000000000F0F0F00F0BB05F +:10DD200000FF000F0F0F0F0B00B00F0FFFFFF00BE6 +:10DD3000000F000FFFFF000B0B000F00FFFFF000B4 +:10DD400000B00000FF0F0B000000B000F00000B0BA +:10DD5000000B0000B0B0000000000B0B0000000042 +:08DD60000000B00000B000005B +:040000030000A20057 +:00000001FF diff --git a/include/basys3.h b/include/basys3.h new file mode 100644 index 0000000..fee4b18 --- /dev/null +++ b/include/basys3.h @@ -0,0 +1,29 @@ +/* The Basys 3 RISC-V computer's I/O, for C programs (see rtl/rv32_system.v). + * + * Port N of the Z-80 machine is the byte at FFFF_FF00 + N, so IO8(0x01) = c + * compiles to one store relative to x0. The 32-bit registers are at + * FFFF_FE00 + N. */ +#ifndef BASYS3_H +#define BASYS3_H + +#define IO8(n) (*(volatile unsigned char *)(0xFFFFFF00u + (n))) +#define IO32(n) (*(volatile unsigned int *)(0xFFFFFE00u + (n))) + +#define IO_MS IO32(0x00) /* milliseconds since reset */ +#define IO_US IO32(0x04) /* microseconds since reset */ +#define IO_TIMECMP IO32(0x08) /* timer interrupt when IO_US reaches it */ +#define IO_BP0 IO32(0x10) /* monitor breakpoint addresses */ +#define IO_BP1 IO32(0x14) + +#define ROM_TOP 0x0000A000u /* BASIC's code below: the hardware ignores writes */ +#define ARENA_BASE 0x0000A000u /* BASIC's program area */ +#define GAME_BASE 0x0000A200u /* machine-code programs loaded into it */ +#define MC_FREE 0x00012000u /* 12000h-12FFFh: free for machine code */ +#define MON_BASE 0x00020000u /* the monitor: NMI entry */ +#define MON_TRAP 0x00020004u /* the monitor's trap entry (mtvec) */ + +/* BASIC's clock, set by DATE, at a fixed place the monitor can read */ +#define CLK_SEC (*(volatile unsigned int *)0x13FF8u) /* seconds since 2000 */ +#define CLK_MS (*(volatile int *)0x13FFCu) /* IO_MS at CLK_SEC */ + +#endif diff --git a/lib/mathf.c b/lib/mathf.c new file mode 100644 index 0000000..a299317 --- /dev/null +++ b/lib/mathf.c @@ -0,0 +1,186 @@ +/* Single-precision maths for BASIC: sinf cosf tanf atanf expf logf sqrtf + floorf. Range reduction by Cody and Waite, minimax polynomials as in the + Cephes library; good to an ulp or two, which BASIC's 6-7 printed digits + don't show. sqrtf and floorf are exact. (newlib's versions are larger and + bring in errno, stdio and malloc.) */ +#include +#include + +typedef union { float f; uint32_t i; } fbits; + +static const float DP1 = 0.78515625f, DP2 = 2.4187564849853515625e-4f, + DP3 = 3.77489497744594108e-8f, FOPI = 1.27323954473516f; + +/* x reduced to [-pi/4, pi/4]; returns the octant */ +static float reduce(float x, int *oct) +{ + int j = (int)(x * FOPI); + float y; + if (j & 1) j++; + y = (float)j; + *oct = j & 7; + return ((x - y * DP1) - y * DP2) - y * DP3; +} + +static float sin_poly(float z) +{ + float zz = z * z; + return ((-1.9515295891e-4f * zz + 8.3321608736e-3f) * zz - 1.6666654611e-1f) * zz * z + z; +} + +static float cos_poly(float z) +{ + float zz = z * z; + return ((2.443315711809948e-5f * zz - 1.388731625493765e-3f) * zz + + 4.166664568298827e-2f) * zz * zz - 0.5f * zz + 1.0f; +} + +float sinf(float x) +{ + int neg = x < 0, j; + float z, y; + if (neg) x = -x; + z = reduce(x, &j); + if (j > 3) { neg = !neg; j -= 4; } + y = (j == 1 || j == 2) ? cos_poly(z) : sin_poly(z); + return neg ? -y : y; +} + +float cosf(float x) +{ + int neg = 0, j; + float z, y; + if (x < 0) x = -x; + z = reduce(x, &j); + if (j > 3) { neg = 1; j -= 4; } + if (j > 1) neg = !neg; + y = (j == 1 || j == 2) ? sin_poly(z) : cos_poly(z); + return neg ? -y : y; +} + +float tanf(float x) +{ + int neg = x < 0, j; + float z, zz, y; + if (neg) x = -x; + z = reduce(x, &j); + zz = z * z; + if (x > 1e-4f) + y = (((((9.38540185543e-3f * zz + 3.11992232697e-3f) * zz + 2.44301354525e-2f) * zz + + 5.34112807005e-2f) * zz + 1.33387994085e-1f) * zz + 3.33331568548e-1f) * zz * z + z; + else + y = z; + if (j & 2) y = -1.0f / y; + return neg ? -y : y; +} + +float atanf(float x) +{ + int neg = x < 0; + float y, z; + if (neg) x = -x; + if (x > 2.414213562373095f) { y = 1.5707963267948966f; x = -1.0f / x; } + else if (x > 0.4142135623730950f) { y = 0.7853981633974483f; x = (x - 1.0f) / (x + 1.0f); } + else y = 0.0f; + z = x * x; + y += (((8.05374449538e-2f * z - 1.38776856032e-1f) * z + 1.99777106478e-1f) * z + - 3.33329491539e-1f) * z * x + x; + return neg ? -y : y; +} + +/* x * 2^n */ +static float scale2(float x, int n) +{ + fbits u; + while (n > 127) { x *= 1.7014118e38f; n -= 127; } + while (n < -126) { x *= 1.1754944e-38f; n += 126; } + u.i = (uint32_t)(n + 127) << 23; + return x * u.f; +} + +float expf(float x) +{ + float z, y; + int n; + if (x > 88.72283905206835f) return HUGE_VALF; + if (x < -103.278929903431851f) return 0.0f; + z = floorf(1.44269504088896341f * x + 0.5f); + x -= z * 0.693359375f; + x -= z * -2.12194440e-4f; + n = (int)z; + z = x * x; + y = (((((1.9875691500e-4f * x + 1.3981999507e-3f) * x + 8.3334519073e-3f) * x + + 4.1665795894e-2f) * x + 1.6666665459e-1f) * x + 5.0000001201e-1f) * z + x + 1.0f; + return scale2(y, n); +} + +float logf(float x) +{ + fbits u = { x }; + int e; + float y, z; + if (x <= 0.0f) return x == 0.0f ? -HUGE_VALF : (x - x) / (x - x); + if (u.i >= 0x7F800000) return x; + e = 0; + if (u.i < 0x00800000) { u.f *= 16777216.0f; e = -24; } /* subnormal */ + e += (int)(u.i >> 23) - 126; + u.i = (u.i & 0x007FFFFF) | 0x3F000000; /* [0.5, 1) */ + x = u.f; + if (x < 0.707106781186547524f) { e--; x = x + x - 1.0f; } + else x = x - 1.0f; + z = x * x; + y = ((((((((7.0376836292e-2f * x - 1.1514610310e-1f) * x + 1.1676998740e-1f) * x + - 1.2420140846e-1f) * x + 1.4249322787e-1f) * x - 1.6668057665e-1f) * x + + 2.0000714765e-1f) * x - 2.4999993993e-1f) * x + 3.3333331174e-1f) * x * z; + y += -2.12194440e-4f * (float)e; + y += -0.5f * z; + z = x + y; + return z + 0.693359375f * (float)e; +} + +/* exact: one bit at a time (after fdlibm) */ +float sqrtf(float x) +{ + fbits u = { x }; + int32_t ix = (int32_t)u.i, m, i; + uint32_t q, s, r, t; + if (ix <= 0) return (ix & 0x7FFFFFFF) == 0 ? x : (x - x) / (x - x); + if (ix >= 0x7F800000) return x; + m = ix >> 23; + if (m == 0) { /* subnormal */ + for (i = 0; !(ix & 0x00800000); i++) ix <<= 1; + m -= i - 1; + } + m -= 127; + ix = (ix & 0x007FFFFF) | 0x00800000; + if (m & 1) ix += ix; + m >>= 1; + ix += ix; + q = s = 0; + r = 0x01000000; + while (r) { + t = s + r; + if (t <= (uint32_t)ix) { s = t + r; ix -= t; q += r; } + ix += ix; + r >>= 1; + } + if (ix) q += q & 1; + u.i = (q >> 1) + 0x3F000000 + ((uint32_t)m << 23); + return u.f; +} + +float floorf(float x) +{ + fbits u = { x }; + int e = (int)(u.i >> 23 & 0xFF) - 0x7F; + uint32_t m; + if (e >= 23) return x; + if (e >= 0) { + m = 0x007FFFFF >> e; + if (!(u.i & m)) return x; + if (u.i >> 31) u.i += m; + u.i &= ~m; + } else if (!(u.i >> 31)) u.i = 0; + else if (u.i << 1) u.f = -1.0f; + return u.f; +} diff --git a/lib/setjmp.S b/lib/setjmp.S new file mode 100644 index 0000000..5f5a8d1 --- /dev/null +++ b/lib/setjmp.S @@ -0,0 +1,38 @@ +# setjmp/longjmp: ra, sp and s0-s11 (newlib's jmp_buf has room). + .text + .globl setjmp, longjmp +setjmp: + sw ra, 0(a0) + sw sp, 4(a0) + sw s0, 8(a0) + sw s1, 12(a0) + sw s2, 16(a0) + sw s3, 20(a0) + sw s4, 24(a0) + sw s5, 28(a0) + sw s6, 32(a0) + sw s7, 36(a0) + sw s8, 40(a0) + sw s9, 44(a0) + sw s10, 48(a0) + sw s11, 52(a0) + li a0, 0 + ret +longjmp: + lw ra, 0(a0) + lw sp, 4(a0) + lw s0, 8(a0) + lw s1, 12(a0) + lw s2, 16(a0) + lw s3, 20(a0) + lw s4, 24(a0) + lw s5, 28(a0) + lw s6, 32(a0) + lw s7, 36(a0) + lw s8, 40(a0) + lw s9, 44(a0) + lw s10, 48(a0) + lw s11, 52(a0) + seqz a0, a1 + add a0, a0, a1 # 0 becomes 1 + ret diff --git a/lib/string.c b/lib/string.c new file mode 100644 index 0000000..df281ad --- /dev/null +++ b/lib/string.c @@ -0,0 +1,75 @@ +/* The few string functions the programs use, small rather than fast + (newlib's versions pull in its stdio and malloc). */ +#include +#include + +void *memcpy(void *d, const void *s, size_t n) +{ + unsigned char *p = d; + const unsigned char *q = s; + while (n--) *p++ = *q++; + return d; +} + +void *memmove(void *d, const void *s, size_t n) +{ + unsigned char *p = d; + const unsigned char *q = s; + if (p < q) while (n--) *p++ = *q++; + else { p += n; q += n; while (n--) *--p = *--q; } + return d; +} + +void *memset(void *d, int c, size_t n) +{ + unsigned char *p = d; + while (n--) *p++ = (unsigned char)c; + return d; +} + +int memcmp(const void *a, const void *b, size_t n) +{ + const unsigned char *p = a, *q = b; + for (; n; n--, p++, q++) if (*p != *q) return *p - *q; + return 0; +} + +size_t strlen(const char *s) +{ + const char *p = s; + while (*p) p++; + return p - s; +} + +int strcmp(const char *a, const char *b) +{ + while (*a && *a == *b) { a++; b++; } + return (unsigned char)*a - (unsigned char)*b; +} + +char *strcpy(char *d, const char *s) +{ + char *p = d; + while ((*p++ = *s++)); + return d; +} + +char *strcat(char *d, const char *s) +{ + strcpy(d + strlen(d), s); + return d; +} + +int strncmp(const char *a, const char *b, size_t n) +{ + for (; n; n--, a++, b++) + if (*a != *b || !*a) return (unsigned char)*a - (unsigned char)*b; + return 0; +} + +char *strrchr(const char *s, int c) +{ + const char *r = 0; + do if (*s == (char)c) r = s; while (*s++); + return (char *)r; +} diff --git a/monitor/asm.c b/monitor/asm.c new file mode 100644 index 0000000..a370531 --- /dev/null +++ b/monitor/asm.c @@ -0,0 +1,541 @@ +/* RISC-V assembler for the monitor (included by monitor.c). + * + * The syntax the disassembler prints. A line is + * [line number] [label:] [instruction or directive] [; comment] + * (the line number is there when the source was typed into BASIC). Numbers: + * 123, 0FFH, $FF, 0x1F, 1010B, 'A'; $ alone is the current address. + * Expressions use + - * / & | and parentheses. Registers are X0-X31 or their + * ABI names (ZERO RA SP GP TP T0-T6 S0-S11 FP A0-A7); memory operands are + * offset(register). CSRs by name (MSTATUS, MEPC, CYCLE...) or number. + * + * Instructions: RV32I and M, CSRRW..CSRRCI, ECALL EBREAK MRET MNRET WFI FENCE + * FENCE.I, and the usual short forms: NOP LI LA MV NOT NEG SEQZ SNEZ SLTZ SGTZ + * J JR JAL target RET CALL BEQZ BNEZ BLEZ BGEZ BLTZ BGTZ BGT BLE BGTU BLEU CSRR + * CSRW CSRS CSRC CSRWI CSRSI CSRCI. LI is one instruction for a constant of + * -2048..2047 known by then, else LUI and ADDI; LA is AUIPC and ADDI. + * Directives: ORG, EQU (NAME EQU value), DB/DEFB/DEFM (numbers and "strings"), + * DH (16 bits), DW/DEFW (32 bits), DS/DEFS n, ALIGN n, END. Instructions must + * be on a 4-byte boundary. Labels are up to 8 characters. + */ +#define MAXSYM 200 +struct sym { char name[8]; u32 val; u16 line; }; +static struct sym syms[MAXSYM]; +static u16 nsym; + +static u32 a_pc; /* address of the line being assembled */ +static u32 a_lo, a_hi; /* lowest and highest byte written */ +static u8 a_pass; /* 1: sizes and labels, 2: bytes */ +static u8 a_undef; /* the expression used an undefined symbol */ +static u8 a_fwd; /* ... or one defined further on */ +static u8 a_end; /* END seen */ +static u16 a_lnum; /* source line, for forward references */ +static const char *a_err; /* this line's error */ +static const char *ap; /* parse pointer */ + +static void a_fail(const char *m) { if (!a_err) a_err = m; } +static void a_sp(void) { while (*ap == ' ' || *ap == '\t') ap++; } +static u8 a_alpha(char c) { return (c >= 'A' && c <= 'Z') || c == '_' || c == '.'; } +static u8 a_alnum(char c) { return a_alpha(c) || (c >= '0' && c <= '9'); } + +static void a_emit(u8 b) +{ + if (a_pass == 2) { + if (!wr(a_pc, b)) a_fail("CAN'T WRITE THERE"); + if (a_pc < a_lo) a_lo = a_pc; + if (a_pc > a_hi) a_hi = a_pc; + } + a_pc++; +} +static void a_emit32(u32 w) { a_emit(w); a_emit(w >> 8); a_emit(w >> 16); a_emit(w >> 24); } + +static i16 sym_find(const char *n) +{ + u16 i; + for (i = 0; i < nsym; i++) + if (!memcmp(syms[i].name, n, 8)) return i; + return -1; +} + +static void sym_def(const char *n, u32 v) +{ + i16 i = sym_find(n); + if (a_pass == 2) { + if (i >= 0 && syms[i].val != v) a_fail("PHASE ERROR"); + return; + } + if (i >= 0) { a_fail("DUPLICATE LABEL"); return; } + if (nsym == MAXSYM) { a_fail("TOO MANY LABELS"); return; } + memcpy(syms[nsym].name, n, 8); + syms[nsym].val = v; + syms[nsym++].line = a_lnum; +} + +/* a name at ap (up to 8 characters kept) */ +static void a_name(char *n) +{ + u8 k = 0; + memset(n, 0, 8); + while (a_alnum(*ap)) { if (k < 8) n[k++] = *ap; ap++; } +} + +/* ---------------------------------------------------------- expressions */ +static u32 a_expr(void); + +static u32 a_number(void) +{ + const char *s = ap; + u32 v = 0; + u8 base = 10, n = 0; + if (s[0] == '0' && s[1] == 'X') { base = 16; s += 2; } + else { + while (a_alnum(s[n])) n++; + if (s[n - 1] == 'H') base = 16; + else if (s[n - 1] == 'B') { + u8 k; + for (k = 0; k < n - 1 && (s[k] == '0' || s[k] == '1'); k++); + if (k == n - 1) base = 2; + } + } + for (; a_alnum(*s); s++) { + char c = *s; + u8 d = c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : 99; + if ((c == 'H' && base == 16) || (c == 'B' && base == 2 && !a_alnum(s[1]))) { s++; break; } + if (d >= base) { a_fail("BAD NUMBER"); break; } + v = v * base + d; + } + ap = s; + return v; +} + +static u32 a_factor(void) +{ + u32 v; + a_sp(); + if (*ap == '-') { ap++; return -a_factor(); } + if (*ap == '+') { ap++; return a_factor(); } + if (*ap == '(') { + ap++; + v = a_expr(); + a_sp(); + if (*ap == ')') ap++; else a_fail("MISSING )"); + return v; + } + if (*ap == '\'' && ap[1] && ap[2] == '\'') { v = (u8)ap[1]; ap += 3; return v; } + if (*ap == '$') { + ap++; + if ((*ap >= '0' && *ap <= '9') || (*ap >= 'A' && *ap <= 'F')) { + v = 0; + while ((*ap >= '0' && *ap <= '9') || (*ap >= 'A' && *ap <= 'F')) + v = v * 16 + (*ap <= '9' ? *ap - '0' : *ap - 'A' + 10), ap++; + return v; + } + return a_pc; + } + if (*ap >= '0' && *ap <= '9') return a_number(); + if (a_alpha(*ap)) { + char n[8]; + i16 i; + a_name(n); + i = sym_find(n); + if (i >= 0) { + if (a_lnum && syms[i].line > a_lnum) a_fwd = 1; + return syms[i].val; + } + a_undef = 1; + if (a_pass == 2) a_fail("UNDEFINED LABEL"); + return 0; + } + a_fail("BAD EXPRESSION"); + return 0; +} + +static u32 a_term(void) +{ + u32 v = a_factor(), w; + for (;;) { + a_sp(); + if (*ap == '*') { ap++; v *= a_factor(); } + else if (*ap == '/') { ap++; w = a_factor(); if (w) v /= w; else a_fail("DIVIDE BY 0"); } + else return v; + } +} + +static u32 a_expr(void) +{ + u32 v = a_term(); + for (;;) { + a_sp(); + if (*ap == '+') { ap++; v += a_term(); } + else if (*ap == '-') { ap++; v -= a_term(); } + else if (*ap == '&') { ap++; v &= a_term(); } + else if (*ap == '|') { ap++; v |= a_term(); } + else return v; + } +} + +/* ------------------------------------------------------------- operands */ +#define MAXOP 3 +static char a_ops[MAXOP][40]; +static u8 a_nops; + +/* the operands at ap, split at commas outside brackets and quotes */ +static void a_split(void) +{ + a_nops = 0; + a_sp(); + while (*ap) { + const char *s = ap; + u8 d = 0, q = 0, len; + while (*ap && (d || q || *ap != ',')) { + if (*ap == '\'' && !q && ap[1] && ap[2] == '\'') ap += 2; + else if (*ap == '"') q = !q; + else if (*ap == '(') d++; + else if (*ap == ')' && d) d--; + ap++; + } + len = ap - s; + while (len && (s[len - 1] == ' ' || s[len - 1] == '\t')) len--; + if (a_nops == MAXOP || len >= sizeof a_ops[0]) { a_fail("TOO MANY OPERANDS"); return; } + memcpy(a_ops[a_nops], s, len); + a_ops[a_nops++][len] = 0; + if (*ap == ',') { ap++; a_sp(); } + } +} + +/* a register name, the whole of s; 0xFF if it isn't one */ +static u8 a_regname(const char *s) +{ + u8 i; + if (s[0] == 'X' && s[1] >= '0' && s[1] <= '9') { + u8 k = s[1] - '0'; + if (s[2] >= '0' && s[2] <= '9') { k = k * 10 + s[2] - '0'; if (s[3]) return 0xFF; } + else if (s[2]) return 0xFF; + return k < 32 ? k : 0xFF; + } + if (!strcmp(s, "FP")) return 8; + for (i = 0; i < 32; i++) if (!strcmp(s, regn[i])) return i; + return 0xFF; +} + +static u8 a_reg(u8 i) +{ + u8 r = i < a_nops ? a_regname(a_ops[i]) : 0xFF; + if (r == 0xFF) a_fail("BAD REGISTER"); + return r & 31; +} + +static u32 a_val(const char *s) +{ + u32 v; + ap = s; + v = a_expr(); + a_sp(); + if (*ap) a_fail("BAD OPERAND"); + return v; +} +static u32 a_imm(u8 i) +{ + if (i >= a_nops) { a_fail("MISSING OPERAND"); return 0; } + return a_val(a_ops[i]); +} + +/* offset(reg) or (reg); the register number, the offset in *off */ +static u8 a_mem(u8 i, i32 *off) +{ + char *s, *o; + u8 n, r; + *off = 0; + if (i >= a_nops) { a_fail("MISSING OPERAND"); return 0; } + s = a_ops[i]; + n = strlen(s); + if (!n || s[n - 1] != ')' || !(o = strrchr(s, '('))) { a_fail("OFFSET(REGISTER)"); return 0; } + s[n - 1] = 0; + r = a_regname(o + 1); + if (r == 0xFF) { a_fail("BAD REGISTER"); return 0; } + *o = 0; + if (o > s) *off = (i32)a_val(s); + return r; +} + +static u16 a_csr(u8 i) +{ + const struct csrn *c; + u32 v; + if (i >= a_nops) { a_fail("MISSING OPERAND"); return 0; } + for (c = csrs; c->s; c++) if (!strcmp(a_ops[i], c->s)) return c->n; + v = a_val(a_ops[i]); + if (v > 0xFFF) a_fail("BAD CSR"); + return v; +} + +/* ------------------------------------------------------------ encoding */ +static i32 a_range(i32 v, i32 lo, i32 hi) +{ + if (a_pass == 2 && (v < lo || v > hi)) a_fail("VALUE OUT OF RANGE"); + return v; +} +static u32 enc_i(u32 base, u8 rd, u8 rs1, i32 imm) +{ + imm = a_range(imm, -2048, 2047); + return base | rd << 7 | rs1 << 15 | ((u32)imm & 0xFFF) << 20; +} +static u32 enc_r(u32 base, u8 rd, u8 rs1, u8 rs2) { return base | rd << 7 | rs1 << 15 | rs2 << 20; } +static u32 enc_s(u32 base, u8 rs1, u8 rs2, i32 imm) +{ + u32 v = (u32)a_range(imm, -2048, 2047); + return base | (v & 31) << 7 | rs1 << 15 | rs2 << 20 | (v >> 5 & 0x7F) << 25; +} +static u32 enc_b(u32 base, u8 rs1, u8 rs2, u32 target) +{ + i32 d = (i32)(target - a_pc); + u32 v; + if (a_pass == 2 && (d & 1)) a_fail("ODD TARGET"); + if (a_pass == 2 && (d < -4096 || d > 4094)) a_fail("BRANCH TOO FAR"); + v = (u32)d; + return base | rs1 << 15 | rs2 << 20 | (v >> 11 & 1) << 7 | (v >> 1 & 15) << 8 | + (v >> 5 & 0x3F) << 25 | (v >> 12 & 1) << 31; +} +static u32 enc_j(u8 rd, u32 target) +{ + i32 d = (i32)(target - a_pc); + u32 v; + if (a_pass == 2 && (d & 1)) a_fail("ODD TARGET"); + if (a_pass == 2 && (d < -(1 << 20) || d >= (1 << 20))) a_fail("JUMP TOO FAR"); + v = (u32)d; + return 0x6F | rd << 7 | (v >> 12 & 0xFF) << 12 | (v >> 11 & 1) << 20 | + (v >> 1 & 0x3FF) << 21 | (v >> 20 & 1) << 31; +} +static u32 enc_u(u32 base, u8 rd, u32 imm) +{ + if (a_pass == 2 && imm > 0xFFFFF) a_fail("VALUE OUT OF RANGE"); + return base | rd << 7 | (imm & 0xFFFFF) << 12; +} +/* the LUI/AUIPC part and the ADDI part of a 32-bit value */ +static u32 hi20(u32 v) { return (v + 0x800) >> 12 & 0xFFFFF; } +static i32 lo12(u32 v) { return sx(v, 12); } + +/* --------------------------------------------------------- instructions */ +enum { + F_R, F_I, F_SH, F_LD, F_ST, F_B, F_U, F_JAL, F_JALR, F_CSR, F_CSRI, F_FIX, + P_LI, P_LA, P_MV, P_NOT, P_NEG, P_SEQZ, P_SNEZ, P_SLTZ, P_SGTZ, P_J, P_JR, P_RET, + P_CALL, P_BZ, P_BZS, P_BSW, P_CSRR, P_CSRW, P_CSRWI +}; +struct ins { char name[8]; u8 f; u32 base; }; +static const struct ins itab[] = { + { "ADD", F_R, 0x00000033 }, { "SUB", F_R, 0x40000033 }, { "SLL", F_R, 0x00001033 }, + { "SLT", F_R, 0x00002033 }, { "SLTU", F_R, 0x00003033 }, { "XOR", F_R, 0x00004033 }, + { "SRL", F_R, 0x00005033 }, { "SRA", F_R, 0x40005033 }, { "OR", F_R, 0x00006033 }, + { "AND", F_R, 0x00007033 }, + { "MUL", F_R, 0x02000033 }, { "MULH", F_R, 0x02001033 }, { "MULHSU", F_R, 0x02002033 }, + { "MULHU", F_R, 0x02003033 }, { "DIV", F_R, 0x02004033 }, { "DIVU", F_R, 0x02005033 }, + { "REM", F_R, 0x02006033 }, { "REMU", F_R, 0x02007033 }, + { "ADDI", F_I, 0x00000013 }, { "SLTI", F_I, 0x00002013 }, { "SLTIU", F_I, 0x00003013 }, + { "XORI", F_I, 0x00004013 }, { "ORI", F_I, 0x00006013 }, { "ANDI", F_I, 0x00007013 }, + { "SLLI", F_SH, 0x00001013 }, { "SRLI", F_SH, 0x00005013 }, { "SRAI", F_SH, 0x40005013 }, + { "LB", F_LD, 0x00000003 }, { "LH", F_LD, 0x00001003 }, { "LW", F_LD, 0x00002003 }, + { "LBU", F_LD, 0x00004003 }, { "LHU", F_LD, 0x00005003 }, + { "SB", F_ST, 0x00000023 }, { "SH", F_ST, 0x00001023 }, { "SW", F_ST, 0x00002023 }, + { "BEQ", F_B, 0x00000063 }, { "BNE", F_B, 0x00001063 }, { "BLT", F_B, 0x00004063 }, + { "BGE", F_B, 0x00005063 }, { "BLTU", F_B, 0x00006063 }, { "BGEU", F_B, 0x00007063 }, + { "LUI", F_U, 0x00000037 }, { "AUIPC", F_U, 0x00000017 }, + { "JAL", F_JAL, 0 }, { "JALR", F_JALR, 0x00000067 }, + { "CSRRW", F_CSR, 0x00001073 }, { "CSRRS", F_CSR, 0x00002073 }, { "CSRRC", F_CSR, 0x00003073 }, + { "CSRRWI", F_CSRI, 0x00005073 }, { "CSRRSI", F_CSRI, 0x00006073 }, { "CSRRCI", F_CSRI, 0x00007073 }, + { "ECALL", F_FIX, 0x00000073 }, { "EBREAK", F_FIX, 0x00100073 }, { "MRET", F_FIX, 0x30200073 }, + { "MNRET", F_FIX, 0x70200073 }, { "WFI", F_FIX, 0x10500073 }, { "FENCE", F_FIX, 0x0FF0000F }, + { "FENCE.I", F_FIX, 0x0000100F }, { "NOP", F_FIX, 0x00000013 }, + { "LI", P_LI, 0 }, { "LA", P_LA, 0 }, { "MV", P_MV, 0 }, { "NOT", P_NOT, 0 }, + { "NEG", P_NEG, 0 }, { "SEQZ", P_SEQZ, 0 }, { "SNEZ", P_SNEZ, 0 }, { "SLTZ", P_SLTZ, 0 }, + { "SGTZ", P_SGTZ, 0 }, { "J", P_J, 0 }, { "JR", P_JR, 0 }, { "RET", P_RET, 0 }, + { "CALL", P_CALL, 0 }, + { "BEQZ", P_BZ, 0x00000063 }, { "BNEZ", P_BZ, 0x00001063 }, { "BLTZ", P_BZ, 0x00004063 }, + { "BGEZ", P_BZ, 0x00005063 }, { "BGTZ", P_BZS, 0x00004063 }, { "BLEZ", P_BZS, 0x00005063 }, + { "BGT", P_BSW, 0x00004063 }, { "BLE", P_BSW, 0x00005063 }, { "BGTU", P_BSW, 0x00006063 }, + { "BLEU", P_BSW, 0x00007063 }, + { "CSRR", P_CSRR, 0 }, { "CSRW", P_CSRW, 0x00001073 }, { "CSRS", P_CSRW, 0x00002073 }, + { "CSRC", P_CSRW, 0x00003073 }, { "CSRWI", P_CSRWI, 0x00005073 }, + { "CSRSI", P_CSRWI, 0x00006073 }, { "CSRCI", P_CSRWI, 0x00007073 }, +}; +#define NINS (sizeof itab / sizeof itab[0]) + +static void a_need(u8 n) { if (a_nops != n) a_fail(a_nops < n ? "MISSING OPERAND" : "TOO MANY OPERANDS"); } + +static void a_instr(const struct ins *t) +{ + u32 b = t->base, v; + i32 off; + u8 rd, rs; + if (a_pc & 3) { a_fail("NOT ON A WORD: USE ALIGN 4"); return; } + switch (t->f) { + case F_R: a_need(3); a_emit32(enc_r(b, a_reg(0), a_reg(1), a_reg(2))); return; + case F_I: a_need(3); a_emit32(enc_i(b, a_reg(0), a_reg(1), (i32)a_imm(2))); return; + case F_SH: + a_need(3); + v = a_imm(2); + if (a_pass == 2 && v > 31) a_fail("SHIFT OVER 31"); + a_emit32(enc_r(b, a_reg(0), a_reg(1), v & 31)); + return; + case F_LD: a_need(2); rd = a_reg(0); rs = a_mem(1, &off); a_emit32(enc_i(b, rd, rs, off)); return; + case F_ST: a_need(2); rd = a_reg(0); rs = a_mem(1, &off); a_emit32(enc_s(b, rs, rd, off)); return; + case F_B: a_need(3); a_emit32(enc_b(b, a_reg(0), a_reg(1), a_imm(2))); return; + case F_U: a_need(2); a_emit32(enc_u(b, a_reg(0), a_imm(1))); return; + case F_JAL: /* JAL target (RA) or JAL rd,target */ + if (a_nops == 1) { a_emit32(enc_j(1, a_imm(0))); return; } + a_need(2); a_emit32(enc_j(a_reg(0), a_imm(1))); return; + case F_JALR: /* JALR rs / JALR rd,off(rs) / JALR rd,rs,off */ + if (a_nops == 1) { a_emit32(enc_i(b, 1, a_reg(0), 0)); return; } + if (a_nops == 2) { rd = a_reg(0); rs = a_mem(1, &off); a_emit32(enc_i(b, rd, rs, off)); return; } + a_need(3); a_emit32(enc_i(b, a_reg(0), a_reg(1), (i32)a_imm(2))); return; + case F_CSR: a_need(3); a_emit32(b | a_reg(0) << 7 | a_reg(2) << 15 | (u32)a_csr(1) << 20); return; + case F_CSRI: + a_need(3); + v = a_imm(2); + if (a_pass == 2 && v > 31) a_fail("VALUE OVER 31"); + a_emit32(b | a_reg(0) << 7 | (v & 31) << 15 | (u32)a_csr(1) << 20); + return; + case F_FIX: a_need(0); a_emit32(b); return; + case P_LI: + a_need(2); + rd = a_reg(0); + a_undef = a_fwd = 0; + v = a_imm(1); + if (!a_undef && !a_fwd && (i32)v >= -2048 && (i32)v <= 2047) { + a_emit32(enc_i(0x13, rd, 0, (i32)v)); + } else { + a_emit32(enc_u(0x37, rd, hi20(v))); + a_emit32(enc_i(0x13, rd, rd, lo12(v))); + } + return; + case P_LA: + a_need(2); + rd = a_reg(0); + v = a_imm(1) - a_pc; + a_emit32(enc_u(0x17, rd, hi20(v))); + a_emit32(enc_i(0x13, rd, rd, lo12(v))); + return; + case P_MV: a_need(2); a_emit32(enc_i(0x13, a_reg(0), a_reg(1), 0)); return; + case P_NOT: a_need(2); a_emit32(enc_i(0x4013, a_reg(0), a_reg(1), -1)); return; + case P_NEG: a_need(2); a_emit32(enc_r(0x40000033, a_reg(0), 0, a_reg(1))); return; + case P_SEQZ: a_need(2); a_emit32(enc_i(0x3013, a_reg(0), a_reg(1), 1)); return; + case P_SNEZ: a_need(2); a_emit32(enc_r(0x3033, a_reg(0), 0, a_reg(1))); return; + case P_SLTZ: a_need(2); a_emit32(enc_r(0x2033, a_reg(0), a_reg(1), 0)); return; + case P_SGTZ: a_need(2); a_emit32(enc_r(0x2033, a_reg(0), 0, a_reg(1))); return; + case P_J: a_need(1); a_emit32(enc_j(0, a_imm(0))); return; + case P_CALL: a_need(1); a_emit32(enc_j(1, a_imm(0))); return; + case P_JR: a_need(1); a_emit32(enc_i(0x67, 0, a_reg(0), 0)); return; + case P_RET: a_need(0); a_emit32(0x00008067); return; + case P_BZ: a_need(2); a_emit32(enc_b(b, a_reg(0), 0, a_imm(1))); return; + case P_BZS: a_need(2); a_emit32(enc_b(b, 0, a_reg(0), a_imm(1))); return; + case P_BSW: a_need(3); rs = a_reg(0); a_emit32(enc_b(b, a_reg(1), rs, a_imm(2))); return; + case P_CSRR: a_need(2); a_emit32(0x2073 | a_reg(0) << 7 | (u32)a_csr(1) << 20); return; + case P_CSRW: a_need(2); a_emit32(b | a_reg(1) << 15 | (u32)a_csr(0) << 20); return; + case P_CSRWI: + a_need(2); + v = a_imm(1); + if (a_pass == 2 && v > 31) a_fail("VALUE OVER 31"); + a_emit32(b | (v & 31) << 15 | (u32)a_csr(0) << 20); + return; + } +} + +/* DB/DH/DW items: numbers and (for DB) strings */ +static void a_data(u8 size) +{ + for (;;) { + a_sp(); + if (*ap == '"' && size == 1) { + ap++; + while (*ap && *ap != '"') a_emit(*ap++); + if (*ap) ap++; + } else { + u32 v = a_expr(); + u8 k; + for (k = 0; k < size; k++) a_emit(v >> (8 * k)); + } + a_sp(); + if (*ap != ',') break; + ap++; + } + if (*ap) a_fail("BAD DATA"); +} + +static u8 is_w(const char *w, const char *s) { return !strncmp(w, s, 8); } + +/* Assemble one source line (uppercase except in quotes). */ +static void a_line(char *s) +{ + char w[8], lab[8]; + u8 has_lab = 0, q = 0; + u16 m; + char *c; + a_err = 0; + /* cut the comment */ + for (c = s; *c; c++) { + if (*c == '"') q = !q; + else if (*c == '\'' && !q && c[1] && c[2] == '\'') c += 2; + else if (*c == ';' && !q) { *c = 0; break; } + } + ap = s; + a_sp(); + if (*ap >= '0' && *ap <= '9') { /* a BASIC line number */ + const char *t = ap; + while (*t >= '0' && *t <= '9') t++; + if (*t == ' ' || !*t) ap = t; + } + a_sp(); + if (!*ap) return; + if (!a_alpha(*ap)) { a_fail("SYNTAX ERROR"); return; } + a_name(w); + a_sp(); + if (*ap == ':') { /* LABEL: */ + ap++; + memcpy(lab, w, 8); has_lab = 1; + a_sp(); + if (!*ap) { sym_def(lab, a_pc); return; } + if (!a_alpha(*ap)) { a_fail("SYNTAX ERROR"); return; } + a_name(w); + a_sp(); + } else if (!strncmp(ap, "EQU", 3) && !a_alnum(ap[3])) { + memcpy(lab, w, 8); has_lab = 1; + memcpy(w, "EQU\0\0\0\0\0", 8); + ap += 3; + } + if (is_w(w, "EQU")) { + u32 v = a_expr(); + if (!has_lab) a_fail("EQU NEEDS A NAME"); + else if (a_undef && a_pass == 1) a_fail("EQU BEFORE ITS VALUE"); + else sym_def(lab, v); + return; + } + if (has_lab) sym_def(lab, a_pc); + if (is_w(w, "ORG")) { a_pc = a_expr(); return; } + if (is_w(w, "END")) { a_end = 1; return; } + if (is_w(w, "DB") || is_w(w, "DEFB") || is_w(w, "DEFM")) { a_data(1); return; } + if (is_w(w, "DH")) { a_data(2); return; } + if (is_w(w, "DW") || is_w(w, "DEFW")) { a_data(4); return; } + if (is_w(w, "DS") || is_w(w, "DEFS")) { a_pc += a_expr(); return; } + if (is_w(w, "ALIGN")) { + u32 n = a_expr(); + if (!n || (n & (n - 1))) a_fail("ALIGN TO A POWER OF 2"); + else while (a_pc & (n - 1)) a_emit(0); + return; + } + for (m = 0; m < NINS; m++) + if (!strncmp(w, itab[m].name, 8)) break; + if (m == NINS) { a_fail("UNKNOWN INSTRUCTION"); return; } + a_split(); + if (a_err) return; + a_instr(&itab[m]); +} + +/* Upper-case a source line outside quotes, in place. */ +static void a_upper(char *s) +{ + u8 q = 0; + for (; *s; s++) { + if (*s == '"') q = !q; + else if (*s == '\'' && !q && s[1] && s[2] == '\'') s += 2; + else if (!q && *s >= 'a' && *s <= 'z') *s -= 32; + if (*s == '\t') *s = ' '; + } +} diff --git a/monitor/build.sh b/monitor/build.sh new file mode 100755 index 0000000..8d58392 --- /dev/null +++ b/monitor/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Compile the monitor and write monitor.mem (its 32 KB bank) and monitor.bin; +# also out/monitor-host, the disassembler and assembler for the PC (tests). +set -e +cd "$(dirname "$0")" +source ../scripts/rv_env.sh +mkdir -p out +CFLAGS="$RV_ARCH -Os -mno-relax -ffunction-sections -fdata-sections -fno-common -Wall -I../include" +${RV_PREFIX}gcc $CFLAGS -c -o out/crt0.o crt0.S +${RV_PREFIX}gcc $CFLAGS -c -o out/monitor.o monitor.c +${RV_PREFIX}gcc $CFLAGS -c -o out/string.o ../lib/string.c +${RV_PREFIX}gcc $CFLAGS -c -o out/setjmp.o ../lib/setjmp.S +${RV_PREFIX}gcc $RV_ARCH -nostdlib -nostartfiles -T monitor.ld -Wl,--no-relax -Wl,--gc-sections \ + -Wl,--build-id=none -Wl,-Map,out/monitor.map -o out/monitor.elf \ + out/crt0.o out/monitor.o out/string.o out/setjmp.o -lgcc +${RV_PREFIX}objcopy -O binary -j .text -j .data out/monitor.elf monitor.bin +${RV_PREFIX}nm -n out/monitor.elf > out/monitor.sym +python3 ../tools/bin2mem.py monitor.bin monitor.mem 8192 +${RV_PREFIX}size out/monitor.elf +cc -O1 -Wall -o out/monitor-host monitor.c diff --git a/monitor/crt0.S b/monitor/crt0.S new file mode 100644 index 0000000..5dfd430 --- /dev/null +++ b/monitor/crt0.S @@ -0,0 +1,95 @@ +# Monitor start-up. The monitor has ROM at 20000-27FFF and RAM (data only) at +# 28000-29FFF. It is entered by the NMI (20000h: the Pause key, MONITOR, a +# breakpoint or a single step) or by a trap (20004h, BASIC's mtvec: an illegal +# instruction, a misaligned access, ebreak, ecall, an unhandled interrupt). +# The program's registers go to u (struct regs in monitor.c), the monitor runs, +# and mnret takes the program back to u.pc with its registers as u has them. + .equ U, 0x29F00 # struct regs, below RAM's last 256 bytes + .equ INITED, 0x29FFC # C data is set up once, then kept + .equ U_PC, 128 + .equ U_HOW, 132 # 0 NMI, 1 trap + .equ U_CAUSE, 136 + .equ U_TVAL, 140 + .equ U_STATUS, 144 + + .section .text.start, "ax" + .globl _start, u + .set u, U +_start: + j nmi_entry # 20000h + j trap_entry # 20004h + + .macro SAVE_REGS + sw x1, 4(sp) + .irp n, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 + sw x\n, 4*\n(sp) + .endr + csrr t0, 0x740 # mnscratch: the program's sp + sw t0, 8(sp) + sw zero, 0(sp) + .endm + +nmi_entry: + csrw 0x740, sp # mnscratch + li sp, U + SAVE_REGS + csrr t0, 0x741 # mnepc + sw t0, U_PC(sp) + sw zero, U_HOW(sp) + j common + +trap_entry: + csrci 0x744, 8 # NMIE off first: no NMI may reuse mnscratch + csrw 0x740, sp + li sp, U + SAVE_REGS + csrr t0, mepc + sw t0, U_PC(sp) + li t0, 1 + sw t0, U_HOW(sp) + csrr t0, mcause + sw t0, U_CAUSE(sp) + csrr t0, mtval + sw t0, U_TVAL(sp) + csrr t0, mstatus + sw t0, U_STATUS(sp) + +common: + li sp, U # the monitor's stack, below u + li t0, INITED + lw t1, 0(t0) + li t2, 0xA5A5 + beq t1, t2, 3f + la a0, __data_start # copy initialised data + la a1, __data_load + la a2, __data_end +1: bgeu a0, a2, 2f + lw t1, 0(a1) + sw t1, 0(a0) + addi a0, a0, 4 + addi a1, a1, 4 + j 1b +2: la a0, __bss_start # clear the rest + la a2, __bss_end +21: bgeu a0, a2, 22f + sw zero, 0(a0) + addi a0, a0, 4 + j 21b +22: sw t2, 0(t0) +3: call mon_main + + li sp, U + lw t0, U_PC(sp) + csrw 0x741, t0 # mnepc + lw t0, U_HOW(sp) + beqz t0, 4f + csrr t0, mstatus # from a trap: interrupts back as they were + andi t0, t0, 0x80 + beqz t0, 4f + csrsi mstatus, 8 +4: lw x1, 4(sp) + .irp n, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 + lw x\n, 4*\n(sp) + .endr + lw sp, 8(sp) + .word 0x70200073 # mnret diff --git a/monitor/monitor.bin b/monitor/monitor.bin new file mode 100755 index 0000000..4d32cf3 Binary files /dev/null and b/monitor/monitor.bin differ diff --git a/monitor/monitor.c b/monitor/monitor.c new file mode 100644 index 0000000..c6a53bf --- /dev/null +++ b/monitor/monitor.c @@ -0,0 +1,1118 @@ +/* Machine-code monitor for the Basys 3 RISC-V computer. + * + * Entered by the NMI (the Pause key, BASIC's MONITOR, a breakpoint or a + * single step) or by a trap (an illegal instruction, a misaligned access, + * ebreak, ecall, an interrupt with no handler): crt0.S saves the program's + * registers in u. It shows the registers, a disassembly from the PC, the stack + * and a memory dump on the terminal's alternate screen, and takes commands on + * the bottom line. The program and the monitor share the address space, so + * memory is read directly; writes go only to RAM above BASIC's code. + */ +#include +#include +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef int16_t i16; +typedef uint32_t u32; +typedef int32_t i32; + +#ifdef __riscv +#include "basys3.h" +#define con_stat IO8(0x00) +#define con_data IO8(0x01) +#define mon_ctl IO8(0x60) +#define bp_ctl IO8(0x67) +#define fl_ctl IO8(0x40) +#define fl_dat IO8(0x41) + +/* saved by crt0.S at 29F00h */ +struct regs { + u32 x[32]; /* x[0] is 0 */ + u32 pc; + u32 how; /* 0 NMI, 1 trap */ + u32 cause, tval, status; /* for a trap */ +}; +extern struct regs u; + +static void putc_(char c) { while (!(con_stat & 2)); con_data = c; } +static u8 getk(void) { while (!(con_stat & 1)); return con_data; } +static u8 rd(u32 a) { return *(volatile u8 *)a; } +static u8 wr(u32 a, u8 v) +{ + if (a < ROM_TOP || a >= 0x14000) return 0; + *(volatile u8 *)a = v; + return 1; +} +#else +/* host build: only for testing the disassembler and assembler (see main) */ +#include +#include +#define ROM_TOP 0 +#define MC_FREE 0x12000u +static u8 hostmem[0x2A000]; +static void putc_(char c) { putchar(c); } +static u8 rd(u32 a) { return a < sizeof hostmem ? hostmem[a] : 0; } +static u8 wr(u32 a, u8 v) { if (a >= sizeof hostmem) return 0; hostmem[a] = v; return 1; } +#endif + +static u32 rd32(u32 a) { return rd(a) | rd(a + 1) << 8 | rd(a + 2) << 16 | (u32)rd(a + 3) << 24; } + +/* ------------------------------------------------------------ text out */ +static char line[100]; +static char *lp; + +static void s_ch(char c) { *lp++ = c; } +static void s_str(const char *s) { while (*s) *lp++ = *s++; } +static const char hexd[] = "0123456789ABCDEF"; +static void s_hex(u32 v, u8 n) { while (n--) s_ch(hexd[v >> (4 * n) & 15]); } +static void s_h2(u8 v) { s_hex(v, 2); } +static void s_h8(u32 v) { s_hex(v, 8); } +static void s_udec(u32 v) +{ + char b[11], *q = b + 10; + *q = 0; + do *--q = '0' + v % 10; while (v /= 10); + s_str(q); +} +static void s_dec(i32 v) { if (v < 0) { s_ch('-'); v = -v; } s_udec((u32)v); } +/* assembler style: 1F0H, 0A200H (a leading 0 when it starts with a letter) */ +static void s_lit(u32 v) +{ + u8 n = 1; + while (n < 8 && v >> (4 * n)) n++; + if ((v >> (4 * (n - 1)) & 15) >= 10) s_ch('0'); + s_hex(v, n); + s_ch('H'); +} + +/* ---------------------------------------------------------- disassembler */ +static const char *const regn[32] = { + "ZERO", "RA", "SP", "GP", "TP", "T0", "T1", "T2", "S0", "S1", "A0", "A1", "A2", "A3", "A4", "A5", + "A6", "A7", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "T3", "T4", "T5", "T6" +}; +struct csrn { u16 n; const char *s; }; +static const struct csrn csrs[] = { + { 0x300, "MSTATUS" }, { 0x301, "MISA" }, { 0x304, "MIE" }, { 0x305, "MTVEC" }, + { 0x340, "MSCRATCH" }, { 0x341, "MEPC" }, { 0x342, "MCAUSE" }, { 0x343, "MTVAL" }, + { 0x344, "MIP" }, { 0x740, "MNSCRATCH" }, { 0x741, "MNEPC" }, { 0x742, "MNCAUSE" }, + { 0x744, "MNSTATUS" }, { 0x7A0, "TSELECT" }, { 0x7A1, "TDATA1" }, { 0x7A2, "TDATA2" }, + { 0x7A5, "TCONTROL" }, { 0xB00, "MCYCLE" }, { 0xB02, "MINSTRET" }, { 0xB80, "MCYCLEH" }, + { 0xB82, "MINSTRETH" }, { 0xC00, "CYCLE" }, { 0xC01, "TIME" }, { 0xC02, "INSTRET" }, + { 0xC80, "CYCLEH" }, { 0xC81, "TIMEH" }, { 0xC82, "INSTRETH" }, { 0xF14, "MHARTID" }, + { 0, 0 } +}; + +static i32 sx(u32 v, u8 bits) { return (i32)(v << (32 - bits)) >> (32 - bits); } +static void s_reg(u8 r) { s_str(regn[r]); } +static void s_c(void) { s_ch(','); } +static void s_csr(u16 n) +{ + const struct csrn *c; + for (c = csrs; c->s; c++) if (c->n == n) { s_str(c->s); return; } + s_lit(n); +} +static void s_mn(const char *m) { s_str(m); s_ch(' '); } + +static const char *const brn[8] = { "BEQ", "BNE", 0, 0, "BLT", "BGE", "BLTU", "BGEU" }; +static const char *const ldn[8] = { "LB", "LH", "LW", 0, "LBU", "LHU", 0, 0 }; +static const char *const stn[4] = { "SB", "SH", "SW", 0 }; +static const char *const opin[8] = { "ADDI", "SLLI", "SLTI", "SLTIU", "XORI", 0, "ORI", "ANDI" }; +static const char *const opn[8] = { "ADD", "SLL", "SLT", "SLTU", "XOR", "SRL", "OR", "AND" }; +static const char *const muln[8] = { "MUL", "MULH", "MULHSU", "MULHU", "DIV", "DIVU", "REM", "REMU" }; +static const char *const csrin[8] = { 0, "CSRRW", "CSRRS", "CSRRC", 0, "CSRRWI", "CSRRSI", "CSRRCI" }; + +/* One instruction at a into line (at lp); returns its length, 4. */ +static u8 disasm(u32 a) +{ + u32 w = rd32(a); + u8 op = w & 0x7F, rd = w >> 7 & 31, f3 = w >> 12 & 7, rs1 = w >> 15 & 31, rs2 = w >> 20 & 31; + u8 f7 = w >> 25; + i32 ii = sx(w >> 20, 12); + switch (op) { + case 0x37: s_mn("LUI"); s_reg(rd); s_c(); s_lit(w >> 12); return 4; + case 0x17: s_mn("AUIPC"); s_reg(rd); s_c(); s_lit(w >> 12); return 4; + case 0x6F: { + u32 t = a + sx((w >> 31) << 20 | (w >> 12 & 0xFF) << 12 | (w >> 20 & 1) << 11 | + (w >> 21 & 0x3FF) << 1, 21); + if (rd == 0) s_mn("J"); + else if (rd == 1) s_mn("JAL"); + else { s_mn("JAL"); s_reg(rd); s_c(); } + s_lit(t); + return 4; + } + case 0x67: + if (f3) break; + if (rd == 0 && rs1 == 1 && !ii) { s_str("RET"); return 4; } + if (!ii && (rd == 0 || rd == 1)) { s_mn(rd ? "JALR" : "JR"); s_reg(rs1); return 4; } + s_mn("JALR"); s_reg(rd); s_c(); s_dec(ii); s_ch('('); s_reg(rs1); s_ch(')'); + return 4; + case 0x63: { + u32 t = a + sx((w >> 31) << 12 | (w >> 7 & 1) << 11 | (w >> 25 & 0x3F) << 5 | (w >> 8 & 15) << 1, 13); + if (!brn[f3]) break; + if (rs2 == 0 && f3 <= 1) { s_mn(f3 ? "BNEZ" : "BEQZ"); s_reg(rs1); } + else if (rs2 == 0 && f3 == 4) { s_mn("BLTZ"); s_reg(rs1); } + else if (rs2 == 0 && f3 == 5) { s_mn("BGEZ"); s_reg(rs1); } + else if (rs1 == 0 && f3 == 4) { s_mn("BGTZ"); s_reg(rs2); } + else if (rs1 == 0 && f3 == 5) { s_mn("BLEZ"); s_reg(rs2); } + else { s_mn(brn[f3]); s_reg(rs1); s_c(); s_reg(rs2); } + s_c(); s_lit(t); + return 4; + } + case 0x03: + if (!ldn[f3]) break; + s_mn(ldn[f3]); s_reg(rd); s_c(); s_dec(ii); s_ch('('); s_reg(rs1); s_ch(')'); + return 4; + case 0x23: + if (!stn[f3 & 3] || f3 > 2) break; + s_mn(stn[f3]); s_reg(rs2); s_c(); s_dec(sx((w >> 25) << 5 | rd, 12)); + s_ch('('); s_reg(rs1); s_ch(')'); + return 4; + case 0x13: + if (f3 == 1 || f3 == 5) { + if (f7 && !(f3 == 5 && f7 == 0x20)) break; + s_mn(f3 == 1 ? "SLLI" : f7 ? "SRAI" : "SRLI"); + s_reg(rd); s_c(); s_reg(rs1); s_c(); s_udec(rs2); + return 4; + } + if (w == 0x00000013) { s_str("NOP"); return 4; } + if (f3 == 0 && rs1 == 0) { s_mn("LI"); s_reg(rd); s_c(); s_dec(ii); return 4; } + if (f3 == 0 && ii == 0) { s_mn("MV"); s_reg(rd); s_c(); s_reg(rs1); return 4; } + if (f3 == 4 && ii == -1) { s_mn("NOT"); s_reg(rd); s_c(); s_reg(rs1); return 4; } + if (f3 == 3 && ii == 1) { s_mn("SEQZ"); s_reg(rd); s_c(); s_reg(rs1); return 4; } + s_mn(opin[f3]); s_reg(rd); s_c(); s_reg(rs1); s_c(); s_dec(ii); + return 4; + case 0x33: + if (f7 == 1) { s_mn(muln[f3]); } + else if (f7 == 0x20 && f3 == 0) { + if (rs1 == 0) { s_mn("NEG"); s_reg(rd); s_c(); s_reg(rs2); return 4; } + s_mn("SUB"); + } + else if (f7 == 0x20 && f3 == 5) s_mn("SRA"); + else if (f7 == 0) { + if (f3 == 3 && rs1 == 0) { s_mn("SNEZ"); s_reg(rd); s_c(); s_reg(rs2); return 4; } + if (f3 == 2 && rs2 == 0) { s_mn("SLTZ"); s_reg(rd); s_c(); s_reg(rs1); return 4; } + if (f3 == 2 && rs1 == 0) { s_mn("SGTZ"); s_reg(rd); s_c(); s_reg(rs2); return 4; } + s_mn(opn[f3]); + } + else break; + s_reg(rd); s_c(); s_reg(rs1); s_c(); s_reg(rs2); + return 4; + case 0x0F: + if (f3 == 0) { s_str("FENCE"); return 4; } + if (f3 == 1) { s_str("FENCE.I"); return 4; } + break; + case 0x73: { + u16 c = w >> 20; + if (w == 0x00000073) { s_str("ECALL"); return 4; } + if (w == 0x00100073) { s_str("EBREAK"); return 4; } + if (w == 0x30200073) { s_str("MRET"); return 4; } + if (w == 0x70200073) { s_str("MNRET"); return 4; } + if (w == 0x10500073) { s_str("WFI"); return 4; } + if (!csrin[f3]) break; + if (f3 == 2 && rs1 == 0) { s_mn("CSRR"); s_reg(rd); s_c(); s_csr(c); return 4; } + if (rd == 0) { + static const char *const sh[8] = { 0, "CSRW", "CSRS", "CSRC", 0, "CSRWI", "CSRSI", "CSRCI" }; + s_mn(sh[f3]); s_csr(c); s_c(); + if (f3 & 4) s_udec(rs1); else s_reg(rs1); + return 4; + } + s_mn(csrin[f3]); s_reg(rd); s_c(); s_csr(c); s_c(); + if (f3 & 4) s_udec(rs1); else s_reg(rs1); + return 4; + } + } + s_mn("DW"); s_lit(w); + return 4; +} + +#ifndef __riscv +#include "asm.c" + +/* Host test: "dis" reads hex words, one a line, and disassembles each as if + at address 1000h; "asm" assembles lines (at 1000h each, after a first pass + over all of them for labels) and prints the words. */ +int main(int argc, char **argv) +{ + char buf[200]; + if (argc > 1 && !strcmp(argv[1], "dis")) { + while (fgets(buf, sizeof buf, stdin)) { + u32 w = (u32)strtoul(buf, 0, 16); + hostmem[0x1000] = w; hostmem[0x1001] = w >> 8; hostmem[0x1002] = w >> 16; hostmem[0x1003] = w >> 24; + lp = line; + disasm(0x1000); + *lp = 0; + puts(line); + } + return 0; + } + if (argc > 1 && !strcmp(argv[1], "asm")) { + static char src[4000][100]; + int n = 0, i, p; + while (n < 4000 && fgets(src[n], sizeof src[n], stdin)) { + src[n][strcspn(src[n], "\n")] = 0; + n++; + } + nsym = 0; + for (p = 1; p <= 2; p++) { + a_pass = p; a_pc = 0x1000; a_end = 0; a_lo = 0xFFFFFFFF; a_hi = 0; + for (i = 0; i < n && !a_end; i++) { + u32 at = a_pc, k; + strcpy(buf, src[i]); + a_upper(buf); + a_undef = 0; + a_lnum = i + 1; + a_line(buf); + if (p == 2) { + if (a_err) printf("ERROR %s: %s\n", a_err, src[i]); + else { + for (k = at; k + 3 < a_pc; k += 4) + printf("%08X\n", rd(k) | rd(k + 1) << 8 | rd(k + 2) << 16 | (u32)rd(k + 3) << 24); + if ((a_pc - at) & 3) { + for (; k < a_pc; k++) printf("%02X", rd(k)); + printf("\n"); + } + } + } + } + } + return 0; + } + if (argc > 1 && !strcmp(argv[1], "asmbin")) { /* a whole program: the bytes it fills */ + static char src[4000][100]; + int n = 0, i, p, errs = 0; + u32 k; + while (n < 4000 && fgets(src[n], sizeof src[n], stdin)) { src[n][strcspn(src[n], "\n")] = 0; n++; } + nsym = 0; + for (p = 1; p <= 2; p++) { + a_pass = p; a_pc = 0x12000; a_end = 0; a_lo = 0xFFFFFFFF; a_hi = 0; + for (i = 0; i < n && !a_end; i++) { + strcpy(buf, src[i]); + a_upper(buf); + a_undef = 0; + a_lnum = i + 1; + a_line(buf); + if (a_err && (p == 2 || a_err[0] != 'U')) { printf("ERROR line %d: %s\n", i + 1, a_err); errs++; } + } + if (errs) return 1; + } + printf("%05X ", a_lo); + for (k = a_lo; k <= a_hi; k++) printf("%02X", rd(k)); + printf("\n"); + return 0; + } + fprintf(stderr, "monitor-host dis|asm|asmbin < input\n"); + return 1; +} +#else + +/* ------------------------------------------------------------- screen */ +static void puts_(const char *s) { while (*s) putc_(*s++); } +static void at(u8 r, u8 c) /* r, c from 0 */ +{ + char b[12], *p = b; + *p++ = 27; *p++ = '['; + if (r >= 9) *p++ = '0' + (r + 1) / 10; + *p++ = '0' + (r + 1) % 10; *p++ = ';'; + if (c >= 9) *p++ = '0' + (c + 1) / 10; + *p++ = '0' + (c + 1) % 10; *p++ = 'H'; *p = 0; + puts_(b); +} +static void sgr(const char *s) { putc_(27); putc_('['); puts_(s); putc_('m'); } +static void flush_line(void) { *lp = 0; puts_(line); } +static void clr_eol(void) { puts_("\033[K"); } + +/* --------------------------------------------------------------- state */ +#define REG_TOP 2 /* six rows of registers */ +#define DIS_ROWS 12 +#define MEM_ROWS 6 +#define DIS_TOP 9 +#define MEM_TOP 22 + +static u32 dis_a; /* first line of the disassembly window */ +static u32 mem_a; /* first line of the memory window */ +static u32 bp; /* the user's breakpoint */ +static u8 bp_set; +static u8 go_after; /* stepping off a breakpoint, then G */ +static u16 steps; /* more single steps to do */ +static char cmd[80]; +static u8 msg_err; +static const char *msg; +static u8 why_in; /* why the monitor was entered */ +static char load_msg[32]; + +/* ------------------------------------------------------------- drawing */ +/* " PC 00012000 ": 13 columns, six to a line */ +static void s_rv(const char *n, u32 v) +{ + u8 k = strlen(n); + while (k++ < 3) s_ch(' '); + s_str(n); s_ch(' '); s_h8(v); s_ch(' '); +} + +static void draw_regs(void) +{ + u8 r, i; + for (r = 0; r < 6; r++) { + lp = line; + for (i = 0; i < 6; i++) { + u8 k = r * 6 + i; + if (k == 0) s_rv("PC", u.pc); + else if (k < 32) s_rv(regn[k], u.x[k]); + } + at(REG_TOP + r, 0); flush_line(); clr_eol(); + } +} + +static void draw_dis(void) +{ + u32 a = dis_a, pc = u.pc; + u8 r; + for (r = 0; r < DIS_ROWS; r++) { + lp = line; + s_ch(a == pc ? '>' : ' '); + s_ch(bp_set && a == bp ? '*' : ' '); + s_hex(a, 5); s_str(" "); + s_h8(rd32(a)); s_str(" "); + disasm(a); + while (lp < line + 50) s_ch(' '); + at(DIS_TOP + r, 0); + if (a == pc) sgr("1;33;44"); + flush_line(); + if (a == pc) sgr("0"); + a += 4; + } +} + +static void draw_stack(void) +{ + u32 s = u.x[2]; + u8 r; + at(DIS_TOP - 1, 54); sgr("36"); puts_("STACK"); sgr("0"); + for (r = 0; r < DIS_ROWS; r++) { + lp = line; + s_hex(s, 5); s_str(" "); s_h8(rd32(s)); + at(DIS_TOP + r, 54); flush_line(); clr_eol(); + s += 4; + } +} + +static void draw_mem(void) +{ + u32 a = mem_a; + u8 r, j, c; + for (r = 0; r < MEM_ROWS; r++) { + lp = line; + s_ch(' '); s_hex(a, 5); s_str(" "); + for (j = 0; j < 16; j++) { s_h2(rd(a + j)); s_ch(j == 7 ? '-' : ' '); } + s_ch(' '); + for (j = 0; j < 16; j++) { c = rd(a + j); s_ch(c >= 32 && c < 127 ? c : '.'); } + at(MEM_TOP + r, 0); flush_line(); clr_eol(); + a += 16; + } +} + +static const char *why_text(void) +{ + static char t[32]; + if (u.how) { + u32 c = u.cause; + if (c >> 31) { lp = t; s_str("INTERRUPT "); s_udec(c & 31); *lp = 0; return t; } + switch (c) { + case 0: return "MISALIGNED JUMP"; + case 2: return "ILLEGAL INSTRUCTION"; + case 3: return "EBREAK"; + case 4: return "MISALIGNED LOAD"; + case 6: return "MISALIGNED STORE"; + case 11: return "ECALL"; + default: lp = t; s_str("TRAP "); s_udec(c); *lp = 0; return t; + } + } + switch (why_in) { + case 1: return "PAUSE KEY"; + case 2: return "MONITOR COMMAND"; + case 3: return "STEP"; + case 4: return "BREAKPOINT"; + case 5: return "STEP OVER"; + default: return ""; + } +} + +static void draw_all(void) +{ + puts_("\033[2J"); + at(0, 0); sgr("1;37;44"); + lp = line; + s_str(" RISC-V MONITOR"); + while (lp < line + 50) s_ch(' '); + s_str("STOPPED BY "); + s_str(why_text()); + while (lp < line + 80) s_ch(' '); + *lp = 0; + line[80] = 0; + puts_(line); sgr("0"); + draw_regs(); + at(DIS_TOP - 1, 0); sgr("36"); puts_(" ADDR WORD INSTRUCTION"); sgr("0"); + draw_dis(); + draw_stack(); + at(MEM_TOP - 1, 0); sgr("36"); puts_(" MEMORY"); sgr("0"); + draw_mem(); + at(28, 0); sgr("36"); + puts_(" ENTER step O over G go X exit B bp D/M addr E edit R reg ? help"); + sgr("0"); +} + +/* --------------------------------------------------------------- input */ +static u8 is_hex(char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'); } +static char *cp; +static void skip_sp(void) { while (*cp == ' ' || *cp == ',') cp++; } + +/* hex number at cp; 0 if none */ +static u8 get_hex(u32 *v) +{ + u8 n = 0; + skip_sp(); + *v = 0; + while (is_hex(*cp)) { + *v = *v << 4 | (*cp <= '9' ? *cp - '0' : *cp - 'A' + 10); + cp++; n++; + } + return n; +} + +static void show_msg(void) +{ + at(29, 40); clr_eol(); + if (msg) { sgr(msg_err ? "1;31" : "32"); puts_(msg); sgr("0"); } +} + +/* Read a command into cmd. Returns 1 for a line, or a key code for a key + that acts at once on an empty line: 'U', 'N' (up, down), 'P', 'Q' (page). */ +static const char *prompt = "> "; +static u8 read_cmd(void) +{ + u8 n = 0, c; + at(29, 0); puts_(prompt); clr_eol(); + show_msg(); + at(29, strlen(prompt)); + puts_("\033[?25h"); + for (;;) { + c = getk(); + if (c == 27) { + c = getk(); + if (c == '[' || c == 'O') { + u8 k = getk(), t = k; + while (t >= '0' && t <= '9') t = getk(); /* ESC [ 5 ~ */ + puts_("\033[?25l"); + if (k == 'A') return 'U'; + if (k == 'B') return 'N'; + if (k == '5') return 'P'; + if (k == '6') return 'Q'; + puts_("\033[?25h"); + } + continue; + } + if (c == '\r' || c == '\n') { cmd[n] = 0; puts_("\033[?25l"); return 1; } + if (c == 8 || c == 127) { if (n) { n--; puts_("\b \b"); } continue; } + if (c == 21) { while (n) { n--; puts_("\b \b"); } continue; } + if (c >= 'a' && c <= 'z') c -= 32; + if (c >= ' ' && c < 127 && n < sizeof cmd - 1) { cmd[n++] = c; putc_(c); } + } +} + +/* ------------------------------------------------------- flash files */ +/* The same file system as BASIC's (basic.c): 448 blocks of 4 KB from + 240000h, a directory in block 0 or 1 (the newer valid one). A memory file + holds its load address (4 bytes, low first) and then the bytes. */ +#define FS_BASE 0x240000UL +#define FS_BLOCKS 448 +#define MAXFILES 64 +#define FBLK 8 + +struct dirent { char name[8]; u16 len; u16 blk[FBLK]; u16 date[2]; }; +#define OLD_DIRENT 26 +static struct { + char magic[4]; + u16 seq, next; + struct dirent e[MAXFILES]; + u16 sum; +} dir; +static u8 dir_cur; +static u8 bmap[FS_BLOCKS / 8]; +static u8 page[256]; +static u16 w_pos; +static u16 w_blk[FBLK]; +static jmp_buf fs_jmp; +static const char *fs_msg; + +static void fs_fail(const char *m) { fs_msg = m; longjmp(fs_jmp, 1); } + +static i32 millis(void) { return (i32)IO_MS; } +static u32 now(void) +{ + u32 s = CLK_SEC; + return s ? s + (u32)(millis() - CLK_MS) / 1000 : 0; +} + +static u8 spi(u8 b) { fl_dat = b; while (fl_ctl & 1); return fl_dat; } +static void fl_open(u8 cmd) { fl_ctl = 1; spi(cmd); } +static void fl_close(void) { fl_ctl = 0; } +static void fl_addr(u32 a) { spi(a >> 16); spi(a >> 8); spi(a); } +static void fl_read(u32 a, u8 *p, u16 n) +{ + fl_open(0x03); fl_addr(a); + while (n--) *p++ = spi(0); + fl_close(); +} +static void fl_wait(void) +{ + i32 t = millis(); + u8 st; + do { + fl_open(0x05); st = spi(0); fl_close(); + if (millis() - t > 3000) fs_fail("FLASH ERROR"); + } while (st & 1); +} +static void fl_write_op(u8 cmd, u32 a, const u8 *p, u16 n) +{ + u8 ok; + fl_open(0x06); fl_close(); + fl_open(cmd); fl_addr(a); + while (n--) spi(*p++); + ok = !(fl_ctl & 2); + fl_close(); + if (!ok) fs_fail("FLASH ERROR"); + fl_wait(); +} +static u32 blk_addr(u16 b) { return FS_BASE + ((u32)b << 12); } +static u8 nblk(u16 len) { return (len + 4095) >> 12; } +static void fl_prog(u32 a, const u8 *p, u16 n) +{ + u8 chk[32]; + u16 i, k; + fl_write_op(0x02, a, p, n); + for (i = 0; i < n; i += k) { + k = n - i < 32 ? n - i : 32; + fl_read(a + i, chk, k); + if (memcmp(chk, p + i, k)) fs_fail("FLASH ERROR"); + } +} + +static u16 sum_of(u16 n) +{ + u8 *p = (u8 *)&dir; + u16 s = 0x5AA5; + while (n--) s = (s << 1 | s >> 15) + *p++; + return s; +} +static u8 load_dir(u8 b) +{ + u8 *p = (u8 *)&dir, i; + u16 old = 8 + MAXFILES * OLD_DIRENT; + fl_read(blk_addr(b), p, sizeof dir); + if (!memcmp(dir.magic, "BFS2", 4)) return dir.sum == sum_of(sizeof dir - 2); + if (memcmp(dir.magic, "BFS1", 4) || (p[old] | p[old + 1] << 8) != sum_of(old)) return 0; + for (i = MAXFILES; i--; ) { + memmove(&dir.e[i], p + 8 + i * OLD_DIRENT, OLD_DIRENT); + dir.e[i].date[0] = dir.e[i].date[1] = 0; + } + memcpy(dir.magic, "BFS2", 4); + return 1; +} +static void fs_mount(void) +{ + u8 va, vb; + u16 sa; + fl_open(0x9F); va = spi(0); vb = spi(0); sa = spi(0); fl_close(); + if (va != 0xC2 || vb != 0x20 || sa != 0x16) fs_fail("NO FLASH"); + va = load_dir(0); + sa = dir.seq; + vb = load_dir(1); + if (va && (!vb || (i16)(sa - dir.seq) > 0)) { load_dir(0); dir_cur = 0; } + else if (vb) dir_cur = 1; + else { + memset(&dir, 0, sizeof dir); + memcpy(dir.magic, "BFS2", 4); + dir.next = 2; + dir_cur = 1; + } +} +static void fs_commit(void) +{ + u8 b = dir_cur ^ 1, *p = (u8 *)&dir; + u16 i, n; + dir.seq++; + dir.sum = sum_of(sizeof dir - 2); + fl_write_op(0x20, blk_addr(b), 0, 0); + for (i = 0; i < sizeof dir; i += 256) { + n = sizeof dir - i < 256 ? sizeof dir - i : 256; + fl_prog(blk_addr(b) + i, p + i, n); + } + dir_cur = b; +} +static i16 find_file(const char *nm) +{ + u8 i; + for (i = 0; i < MAXFILES; i++) + if (!memcmp(dir.e[i].name, nm, 8)) return i; + return -1; +} +static u16 alloc_blk(void) +{ + u16 b = dir.next, k; + for (k = 0; k < FS_BLOCKS; k++, b++) { + if (b >= FS_BLOCKS) b = 2; + if (!(bmap[b >> 3] & (1 << (b & 7)))) { + bmap[b >> 3] |= 1 << (b & 7); + dir.next = b + 1; + return b; + } + } + fs_fail("DISK FULL"); + return 0; +} +static void build_bmap(void) +{ + u8 i, j, n; + memset(bmap, 0, sizeof bmap); + bmap[0] = 3; + for (i = 0; i < MAXFILES; i++) + if (dir.e[i].name[0]) + for (j = 0, n = nblk(dir.e[i].len); j < n; j++) + bmap[dir.e[i].blk[j] >> 3] |= 1 << (dir.e[i].blk[j] & 7); +} +static void put_b(u8 c) +{ + if (!(w_pos & 4095)) { + w_blk[w_pos >> 12] = alloc_blk(); + fl_write_op(0x20, blk_addr(w_blk[w_pos >> 12]), 0, 0); + } + page[w_pos & 255] = c; + w_pos++; + if (!(w_pos & 255)) + fl_prog(blk_addr(w_blk[(w_pos - 1) >> 12]) + ((w_pos - 256) & 4095), page, 256); +} + +/* "NAME" at cp: 1-8 letters and digits */ +static void get_fname(char *nm) +{ + u8 n = 0; + skip_sp(); + if (*cp++ != '"') fs_fail("NAME IN QUOTES"); + memset(nm, 0, 8); + while (*cp && *cp != '"') { + if (n == 8 || !((*cp >= 'A' && *cp <= 'Z') || (*cp >= '0' && *cp <= '9'))) fs_fail("BAD FILE NAME"); + nm[n++] = *cp++; + } + if (*cp) cp++; + if (!n) fs_fail("BAD FILE NAME"); +} + +/* SAVE "NAME" start end: memory start..end (inclusive) to a file */ +static void mem_save(void) +{ + char nm[8]; + u32 a, e, n; + i16 i; + get_fname(nm); + if (!get_hex(&a) || !get_hex(&e) || e < a) fs_fail("SAVE \"NAME\" START END"); + n = e - a + 1; + if (n > 32768U - 4) fs_fail("FILE TOO BIG"); + fs_mount(); + build_bmap(); + i = find_file(nm); + if (i < 0) { + for (i = 0; i < MAXFILES && dir.e[i].name[0]; i++); + if (i == MAXFILES) fs_fail("TOO MANY FILES"); + } + w_pos = 0; + put_b(a); put_b(a >> 8); put_b(a >> 16); put_b(a >> 24); + while (n--) put_b(rd(a++)); + if (w_pos & 255) + fl_prog(blk_addr(w_blk[(w_pos - 1) >> 12]) + ((w_pos - (w_pos & 255)) & 4095), page, w_pos & 255); + if (!dir.e[i].name[0] || !(dir.e[i].date[0] | dir.e[i].date[1])) { + u32 t = now(); + dir.e[i].date[0] = t; dir.e[i].date[1] = t >> 16; + } + memcpy(dir.e[i].name, nm, 8); + dir.e[i].len = w_pos; + memcpy(dir.e[i].blk, w_blk, sizeof w_blk); + fs_commit(); +} + +/* LOAD "NAME" [addr]: a memory file back, to its own address or addr */ +static u32 ld_first, ld_last; +static void mem_load(void) +{ + char nm[8]; + u32 a = 0, la = 0; + u16 pos, len; + i16 i; + u8 has; + get_fname(nm); + has = get_hex(&a); + fs_mount(); + i = find_file(nm); + if (i < 0) fs_fail("FILE NOT FOUND"); + len = dir.e[i].len; + if (len < 4) fs_fail("NOT A MEMORY FILE"); + for (pos = 0; pos < len; pos++) { + u8 c; + if (!(pos & 255)) + fl_read(blk_addr(dir.e[i].blk[pos >> 12]) + (pos & 4095), page, 256); + c = page[pos & 255]; + if (pos < 4) { + la |= (u32)c << (8 * pos); + if (pos == 3) { if (!has) a = la; ld_first = a; } + } else { + if (!wr(a, c)) fs_fail("CAN'T LOAD THERE"); + ld_last = a++; + } + } +} + +/* DIR: the files, four to a line, in the memory window */ +static void mem_dir(void) +{ + u8 i, n = 0, r; + fs_mount(); + for (r = 0; r < MEM_ROWS; r++) { at(MEM_TOP + r, 0); clr_eol(); } + for (i = 0; i < MAXFILES && n < MEM_ROWS * 4; i++) { + u8 j; + if (!dir.e[i].name[0]) continue; + lp = line; + for (j = 0; j < 8; j++) s_ch(dir.e[i].name[j] ? dir.e[i].name[j] : ' '); + s_ch(' '); s_hex(dir.e[i].len, 4); s_ch('H'); + at(MEM_TOP + n / 4, 1 + (n & 3) * 20); flush_line(); + n++; + } + if (!n) { at(MEM_TOP, 1); puts_("NO FILES"); } +} + +/* ------------------------------------------------------------ assembler */ +#include "asm.c" + +static char a_src[128]; +static u8 a_nerr; + +/* one error, in the memory window (six fit) */ +static void a_report(u16 ln) +{ + if (a_nerr < MEM_ROWS) { + lp = line; + s_str(" LINE "); s_udec(ln); + s_str(": "); s_str(a_err); + *lp = 0; + at(MEM_TOP + a_nerr, 0); flush_line(); clr_eol(); + } + a_nerr++; +} + +/* ASM "NAME": assemble a source file from flash into memory */ +static void mem_asm(void) +{ + char nm[8]; + i16 f; + u16 len, pos, ln; + u8 n, p, r; + get_fname(nm); + fs_mount(); + f = find_file(nm); + if (f < 0) fs_fail("FILE NOT FOUND"); + len = dir.e[f].len; + nsym = 0; + a_nerr = 0; + for (r = 0; r < MEM_ROWS; r++) { at(MEM_TOP + r, 0); clr_eol(); } + for (p = 1; p <= 2 && !a_nerr; p++) { + a_pass = p; a_pc = MC_FREE; a_end = 0; a_lo = 0xFFFFFFFF; a_hi = 0; + n = 0; ln = 0; + for (pos = 0; pos <= len && !a_end; pos++) { + u8 c = '\n'; + if (pos < len) { + if (!(pos & 255)) + fl_read(blk_addr(dir.e[f].blk[pos >> 12]) + (pos & 4095), page, 256); + c = page[pos & 255]; + } + if (c != '\n') { if (n < sizeof a_src - 1) a_src[n++] = c; continue; } + a_src[n] = 0; + n = 0; + ln++; + { + u16 num = 0; /* report BASIC's line number if there is one */ + char *t = a_src; + while (*t == ' ') t++; + while (*t >= '0' && *t <= '9') num = num * 10 + (*t++ - '0'); + a_upper(a_src); + a_undef = 0; + a_lnum = ln; + a_line(a_src); + if (a_err) a_report(num ? num : ln); + } + } + } + if (a_nerr) { + lp = line; s_udec(a_nerr); s_str(a_nerr == 1 ? " ERROR" : " ERRORS"); *lp = 0; + strcpy(load_msg, line); + fs_fail(load_msg); + } + if (a_lo > a_hi) fs_fail("NOTHING ASSEMBLED"); + lp = line; s_str("ASSEMBLED "); s_hex(a_lo, 5); s_ch('-'); s_hex(a_hi, 5); *lp = 0; + strcpy(load_msg, line); + dis_a = a_lo & ~3u; + mem_a = a_lo & ~15u; + draw_mem(); draw_dis(); +} + +static u8 dis_shows(u32 pc) { return pc >= dis_a && pc < dis_a + 4 * (DIS_ROWS - 2); } + +/* A addr: assemble lines typed at the bottom, one after another */ +static void line_asm(u32 a) +{ + static char pr[12]; + for (;;) { + lp = pr; s_ch('A'); s_ch(' '); s_hex(a, 5); s_str(": "); *lp = 0; + prompt = pr; + if (read_cmd() != 1) continue; + prompt = "> "; + if (!cmd[0]) { msg = 0; return; } + strcpy(a_src, cmd); + a_pass = 2; a_pc = a; a_undef = 0; a_lo = 0xFFFFFFFF; a_hi = 0; a_lnum = 0; + a_line(a_src); + if (a_err) { msg = a_err; msg_err = 1; continue; } + msg = 0; + if (!dis_shows(a)) dis_a = a & ~3u; + a = a_pc; + draw_dis(); draw_mem(); + } +} + +/* ---------------------------------------------------------- commands */ +/* JAL or JALR that saves the return address in RA: a call */ +static u8 op_is_call(u32 a) +{ + u32 w = rd32(a); + return (w >> 7 & 31) == 1 && ((w & 0x7F) == 0x6F || ((w & 0x7F) == 0x67 && !(w >> 12 & 7))); +} + +/* Leave the monitor. mode: 0 run, 2 one instruction */ +static void leave(u8 mode) +{ + IO_BP0 = bp; + mon_ctl = mode; +} + +static u8 reg_num(void) +{ + u8 i, k; + if (cp[0] == 'X' && cp[1] >= '0' && cp[1] <= '9') { + k = cp[1] - '0'; + cp += 2; + if (*cp >= '0' && *cp <= '9') k = k * 10 + (*cp++ - '0'); + return k < 32 ? k : 0xFF; + } + if (!memcmp(cp, "FP", 2)) { cp += 2; return 8; } + for (i = 31; i; i--) { /* longest names first: S10 before S1 */ + k = strlen(regn[i]); + if (!memcmp(cp, regn[i], k) && !(cp[k] >= 'A' && cp[k] <= 'Z') && !(cp[k] >= '0' && cp[k] <= '9')) { + cp += k; + return i; + } + } + return 0xFF; +} + +static u8 set_reg(void) +{ + u8 r; + u32 v; + skip_sp(); + if (cp[0] == 'P' && cp[1] == 'C') { cp += 2; r = 32; } + else if ((r = reg_num()) == 0xFF || r == 0) return 0; + skip_sp(); + if (*cp == '=') cp++; + if (!get_hex(&v)) return 0; + if (r == 32) { + if (v & 3) return 0; + u.pc = v; + } else u.x[r] = v; + return 1; +} + +/* :LLAAAATT data CC - an Intel HEX record, as tools/send-hex.py sends them. + Data records are written to memory; the end record reports the range. */ +static u32 hx_lo = 0xFFFFFFFF, hx_hi, hx_base; +static char hx_msg[32]; +static u8 hexv(char c) { return c <= '9' ? c - '0' : c - 'A' + 10; } +static u8 hex2(const char *s) { return (hexv(s[0]) << 4) | hexv(s[1]); } +static void hex_record(void) +{ + const char *p = cp + 1; + u8 n, t, sum, i, len = 0; + u32 a; + while (is_hex(p[len])) len++; + if (p[len] || len < 10 || (len & 1) || len != 10 + 2 * hex2(p)) { + msg = "BAD HEX RECORD"; msg_err = 1; return; + } + n = hex2(p); + for (sum = 0, i = 0; i < n + 5; i++) sum += hex2(p + 2 * i); + if (sum) { msg = "HEX CHECKSUM ERROR"; msg_err = 1; return; } + a = (u32)hex2(p + 2) << 8 | hex2(p + 4); + t = hex2(p + 6); + if (t == 1) { + if (hx_lo > hx_hi) { msg = "NO HEX DATA"; msg_err = 1; return; } + lp = line; s_str("HEX LOADED "); s_hex(hx_lo, 5); s_ch('-'); s_hex(hx_hi, 5); *lp = 0; + strcpy(hx_msg, line); + msg = hx_msg; + mem_a = hx_lo & ~15u; + hx_lo = 0xFFFFFFFF; hx_hi = 0; hx_base = 0; + draw_mem(); + return; + } + if (t == 4 && n == 2) { hx_base = (u32)hex2(p + 8) << 24 | (u32)hex2(p + 10) << 16; return; } + if (t == 2 && n == 2) { hx_base = ((u32)hex2(p + 8) << 8 | hex2(p + 10)) << 4; return; } + if (t != 0 || !n) return; + a += hx_base; + for (i = 0; i < n; i++) + if (!wr(a + i, hex2(p + 8 + 2 * i))) { msg = "ROM: NOT CHANGED"; msg_err = 1; return; } + if (a < hx_lo) hx_lo = a; + if (a + n - 1 > hx_hi) hx_hi = a + n - 1; +} + +/* Returns 1 when the monitor should be left. */ +static u8 command(void) +{ + u32 v, a; + u8 c; + cp = cmd; + skip_sp(); + msg = 0; msg_err = 0; + if (*cp == ':') { hex_record(); return 0; } + if (!memcmp(cp, "ASM", 3)) { + cp += 3; + if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; } + mem_asm(); + msg = load_msg; + return 0; + } + if (cp[0] == 'A' && (cp[1] == ' ' || !cp[1])) { + cp++; + if (!get_hex(&a)) { msg = "A ADDR, THEN INSTRUCTIONS; EMPTY LINE ENDS"; msg_err = 1; return 0; } + line_asm(a); + return 0; + } + if (!memcmp(cp, "SAVE", 4) || !memcmp(cp, "LOAD", 4) || !memcmp(cp, "DIR", 3)) { + c = *cp; + cp += c == 'D' ? 3 : 4; + if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; } + if (c == 'S') { mem_save(); msg = "SAVED"; } + else if (c == 'L') { + mem_load(); + lp = line; s_str("LOADED "); s_hex(ld_first, 5); s_ch('-'); s_hex(ld_last, 5); *lp = 0; + strcpy(load_msg, line); + msg = load_msg; + mem_a = ld_first & ~15u; + draw_mem(); draw_dis(); + } else { mem_dir(); msg = "M TO SHOW MEMORY AGAIN"; } + return 0; + } + c = *cp; + if (c) cp++; + switch (c) { + case 0: /* Enter: one step */ + case 'S': + steps = get_hex(&v) && v ? v - 1 : 0; + leave(2); + return 1; + case 'O': /* step over a call */ + a = u.pc; + if (!op_is_call(a)) { leave(2); return 1; } + IO_BP1 = a + 4; + bp_ctl = (bp_set && bp != a ? 1 : 0) | 2; + leave(0); + return 1; + case 'G': + case 'X': + if (get_hex(&v)) { + if (v & 3) { msg = "ADDRESS NOT ON A WORD"; msg_err = 1; return 0; } + u.pc = v; + } + if (bp_set && u.pc == bp) { go_after = 1; leave(2); return 1; } + bp_ctl = bp_set; + leave(0); + return 1; + case 'B': + if (get_hex(&v)) { bp = v; bp_set = 1; msg = "BREAKPOINT SET"; } + else { bp_set = 0; msg = "BREAKPOINT CLEARED"; } + draw_dis(); + return 0; + case 'D': + if (get_hex(&v)) dis_a = v & ~3u; else dis_a = u.pc; + draw_dis(); + return 0; + case 'M': + if (get_hex(&v)) mem_a = v; + draw_mem(); + return 0; + case 'E': /* E addr bytes... */ + if (!get_hex(&a)) { msg = "E ADDR BYTE BYTE ..."; msg_err = 1; return 0; } + while (get_hex(&v)) + if (!wr(a++, v)) { msg = "ROM: NOT CHANGED"; msg_err = 1; break; } + draw_all(); + return 0; + case 'R': + if (!set_reg()) { msg = "R PC|X1-X31|RA|SP|A0... = VALUE"; msg_err = 1; return 0; } + draw_regs(); draw_dis(); draw_stack(); + return 0; + case '?': + case 'H': + msg = "ASM \"N\" A ADDR SAVE \"N\" A B LOAD \"N\" [A] DIR"; + return 0; + default: + msg = "? TYPE ? FOR HELP"; msg_err = 1; + return 0; + } +} + +void mon_main(void) +{ + u8 why = mon_ctl, k; + + bp_ctl = 0; /* no breakpoints inside the monitor */ + if (u.how) { /* a trap: ebreak and ecall go on after themselves */ + u32 w = rd32(u.pc); + if ((u.cause == 3 && w == 0x00100073) || (u.cause == 11 && w == 0x00000073)) u.pc += 4; + steps = 0; + go_after = 0; + } else if (go_after && why == 3) { /* stepped off the breakpoint: now go */ + go_after = 0; + bp_ctl = bp_set; + leave(0); + return; + } else if (steps && why == 3) { + steps--; + leave(2); + return; + } + steps = 0; + go_after = 0; + if (!dis_shows(u.pc)) dis_a = u.pc; + + puts_("\0337\033[?47h\033[?25l"); /* save the cursor, alternate screen */ + why_in = why; + draw_all(); + for (;;) { + k = read_cmd(); + if (k == 1) { + if (command()) break; + continue; + } + if (k == 'U') dis_a -= 4; + else if (k == 'N') dis_a += 4; + else if (k == 'P') mem_a -= 16 * MEM_ROWS; + else if (k == 'Q') mem_a += 16 * MEM_ROWS; + if (k == 'U' || k == 'N') draw_dis(); else draw_mem(); + } + puts_("\033[?25h\033[?47l\0338"); +} +#endif diff --git a/monitor/monitor.ld b/monitor/monitor.ld new file mode 100644 index 0000000..b303885 --- /dev/null +++ b/monitor/monitor.ld @@ -0,0 +1,32 @@ +/* The monitor: ROM 20000-27FFF (writes ignored), RAM 28000-29FFF (data only) + with the saved registers at 29F00h (crt0.S) and the stack below them. */ +OUTPUT_ARCH("riscv") +ENTRY(_start) +MEMORY +{ + ROM (rx) : ORIGIN = 0x20000, LENGTH = 0x8000 + RAM (rw) : ORIGIN = 0x28000, LENGTH = 0x1B00 +} +SECTIONS +{ + .text : { + KEEP(*(.text.start)) + *(.text .text.*) + *(.rodata .rodata.* .srodata .srodata.*) + . = ALIGN(4); + } > ROM + .data : ALIGN(4) { + __data_start = .; + *(.data .data.* .sdata .sdata.*) + . = ALIGN(4); + __data_end = .; + } > RAM AT > ROM + __data_load = LOADADDR(.data); + .bss (NOLOAD) : ALIGN(4) { + __bss_start = .; + *(.sbss .sbss.* .bss .bss.* COMMON) + . = ALIGN(4); + __bss_end = .; + } > RAM + /DISCARD/ : { *(.comment) *(.riscv.attributes) } +} diff --git a/monitor/monitor.mem b/monitor/monitor.mem new file mode 100644 index 0000000..e9c1bb3 --- /dev/null +++ b/monitor/monitor.mem @@ -0,0 +1,8192 @@ +0080006f +0a40006f +74011073 +0002a137 +f0010113 +00112223 +00312623 +00412823 +00512a23 +00612c23 +00712e23 +02812023 +02912223 +02a12423 +02b12623 +02c12823 +02d12a23 +02e12c23 +02f12e23 +05012023 +05112223 +05212423 +05312623 +05412823 +05512a23 +05612c23 +05712e23 +07812023 +07912223 +07a12423 +07b12623 +07c12823 +07d12a23 +07e12c23 +07f12e23 +740022f3 +00512423 +00012023 +741022f3 +08512023 +08012223 +0c00006f +74447073 +74011073 +0002a137 +f0010113 +00112223 +00312623 +00412823 +00512a23 +00612c23 +00712e23 +02812023 +02912223 +02a12423 +02b12623 +02c12823 +02d12a23 +02e12c23 +02f12e23 +05012023 +05112223 +05212423 +05312623 +05412823 +05512a23 +05612c23 +05712e23 +07812023 +07912223 +07a12423 +07b12623 +07c12823 +07d12a23 +07e12c23 +07f12e23 +740022f3 +00512423 +00012023 +341022f3 +08512023 +00100293 +08512223 +342022f3 +08512423 +343022f3 +08512623 +300022f3 +08512823 +0002a137 +f0010113 +0002a2b7 +ffc28293 +0002a303 +0000a3b7 +5a538393 +04730c63 +00008517 +e7c50513 +00007597 +e3058593 +00008617 +e7460613 +00c57c63 +0005a303 +00652023 +00450513 +00458593 +fedff06f +00008517 +e5450513 +00009617 +75060613 +00c57863 +00052023 +00450513 +ff5ff06f +0072a023 +00005097 +748080e7 +0002a137 +f0010113 +08012283 +74129073 +08412283 +00028a63 +300022f3 +0802f293 +00028463 +30046073 +00412083 +00c12183 +01012203 +01412283 +01812303 +01c12383 +02012403 +02412483 +02812503 +02c12583 +03012603 +03412683 +03812703 +03c12783 +04012803 +04412883 +04812903 +04c12983 +05012a03 +05412a83 +05812b03 +05c12b83 +06012c03 +06412c83 +06812d03 +06c12d83 +07012e03 +07412e83 +07812f03 +07c12f83 +00812103 +70200073 +f0004783 +0027f793 +fe078ce3 +f0a000a3 +00008067 +f0004783 +0017f793 +fe078ce3 +f0104503 +00008067 +00054683 +00154783 +00254703 +00354503 +00879793 +01071713 +00e7e7b3 +00d7e7b3 +01851513 +00a7e533 +00008067 +0002a737 +8a472783 +00178693 +8ad72223 +00a78023 +00008067 +0002a737 +8a472783 +00000693 +00054603 +00061863 +00068463 +8af72223 +00008067 +00c78023 +00150513 +00178793 +00100693 +fddff06f +fe010113 +00812c23 +fff58413 +00912a23 +0ff47413 +000274b7 +01212823 +01312623 +00112e23 +00050913 +00241413 +fa848493 +ffc00993 +008957b3 +00f7f793 +00f487b3 +0007c503 +ffc40413 +00000097 +f6c080e7 +ff3412e3 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +fe010113 +00050793 +00112e23 +00010723 +00e10513 +00a00693 +00900613 +02d7f733 +fff50513 +03070713 +00e50023 +00078713 +02d7d7b3 +fee664e3 +00000097 +f24080e7 +01c12083 +02010113 +00008067 +ff010113 +00812423 +00112623 +00050413 +00055a63 +02d00513 +00000097 +ee0080e7 +40800433 +00040513 +00812403 +00c12083 +01010113 +00000317 +f8030067 +fe010113 +00812c23 +00112e23 +00455793 +00050413 +00100593 +02078263 +00800793 +00800693 +00158593 +0ff5f593 +00d58863 +00f45733 +00478793 +fe0716e3 +fff58793 +00279793 +00f457b3 +00f7f793 +00900713 +00f77c63 +03000513 +00b12623 +00000097 +e60080e7 +00c12583 +00040513 +00000097 +e9c080e7 +01812403 +01c12083 +04800513 +02010113 +00000317 +e3830067 +000277b7 +00251513 +f2878793 +00a787b3 +0007a503 +00000317 +e3430067 +02c00513 +00000317 +e1030067 +000277b7 +e4078793 +0047a703 +00071663 +00000317 +f3c30067 +0007d683 +00a69863 +00070513 +00000317 +dfc30067 +00878793 +fd9ff06f +ff010113 +00112623 +00000097 +de4080e7 +00c12083 +02000513 +01010113 +00000317 +db830067 +ff010113 +00812423 +00112623 +00050413 +00044503 +00051a63 +00c12083 +00812403 +01010113 +00008067 +00140413 +00000097 +d30080e7 +fddff06f +000067b7 +fe010113 +b1b78793 +00f11223 +00112e23 +00800693 +00150793 +00610713 +00a6fc63 +00a00713 +02e7c733 +03070713 +00e10323 +00710713 +00a00693 +02d7e7b3 +00800613 +03078793 +00f70023 +03b00793 +00f700a3 +00158793 +02b66e63 +00270613 +00a00713 +02e7e7b3 +00410513 +00060123 +03078793 +00f60023 +04800793 +00f600a3 +00000097 +f48080e7 +01c12083 +02010113 +00008067 +02d7c6b3 +00370613 +03068693 +00d70123 +fbdff06f +ff010113 +00812423 +00050413 +01b00513 +00112623 +00000097 +c68080e7 +05b00513 +00000097 +c5c080e7 +00040513 +00000097 +ef4080e7 +00812403 +00c12083 +06d00513 +01010113 +00000317 +c3830067 +0002a7b7 +8a47a783 +0002a537 +8a850513 +00078023 +00000317 +ec030067 +00026537 +d0c50513 +00000317 +eb030067 +fd010113 +0002a7b7 +02912223 +89c7a483 +01312e23 +0002a9b7 +02812423 +01412c23 +01512a23 +01612823 +01712623 +01812423 +02112623 +03212023 +01600413 +0002aab7 +8a898993 +00026b37 +00700b93 +01000a13 +05e00c13 +02000513 +8b3aa223 +00000097 +bfc080e7 +00500593 +00048513 +00000097 +c38080e7 +d10b0513 +00000097 +bf8080e7 +00000913 +009907b3 +0007c503 +00200593 +00000097 +c14080e7 +02000513 +01791463 +02d00513 +00190913 +00000097 +bb0080e7 +fd491ae3 +02000513 +00000097 +ba0080e7 +00000913 +009907b3 +0007c783 +0ff7f513 +fe078793 +0ff7f793 +00fc7463 +02e00513 +00190913 +00000097 +b74080e7 +fd491ce3 +00040513 +00000593 +00000097 +de8080e7 +00140413 +00000097 +ed0080e7 +00000097 +ee4080e7 +0ff47413 +01c00793 +01048493 +f2f41ae3 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +00c12b83 +00812c03 +03010113 +00008067 +0002a737 +81472783 +00000693 +02000513 +02c00593 +0007c603 +00a60a63 +00b60863 +00068463 +80f72a23 +00008067 +00178793 +00100693 +fe1ff06f +f4a000a3 +f4004783 +0017f793 +fe079ce3 +f4104503 +00008067 +ff010113 +00812423 +00050413 +01055513 +0ff57513 +00112623 +00000097 +fd0080e7 +00845513 +0ff57513 +00000097 +fc0080e7 +0ff47513 +00812403 +00c12083 +01010113 +00000317 +fa830067 +ff010113 +00112623 +00812423 +00912223 +01212023 +00100793 +00058413 +00060493 +00050913 +f4f00023 +00300513 +00000097 +f74080e7 +009404b3 +00090513 +01049493 +00000097 +f78080e7 +0104d493 +01041793 +0107d793 +02f49063 +f4000023 +00c12083 +00812403 +00412483 +00012903 +01010113 +00008067 +00000513 +00140413 +00000097 +f24080e7 +fea40fa3 +fc5ff06f +fff50793 +01079793 +00006537 +000296b7 +00010637 +0107d793 +aa550513 +08868693 +fff60613 +0006c583 +00151713 +00f55513 +00a76733 +fff78793 +00b70733 +01079793 +01071513 +0107d793 +00168693 +01055513 +fcc79ae3 +00008067 +000287b7 +1607a703 +00071463 +16a7a023 +00008067 +00028737 +15c72783 +00000693 +02000513 +00900593 +0007c603 +00a60a63 +00b60863 +00068463 +14f72e23 +00008067 +00178793 +00100693 +fe1ff06f +fbf50713 +0ff77713 +01900693 +00050793 +00e6fe63 +05f00713 +00100513 +00e78a63 +fd278793 +0017b513 +00008067 +00100513 +00008067 +ff010113 +00812423 +00112623 +00050413 +00000097 +fbc080e7 +00051e63 +fd040513 +00a53513 +00c12083 +00812403 +01010113 +00008067 +00100513 +fedff06f +000287b7 +1697c703 +ff010113 +00812423 +00912223 +00112623 +000284b7 +00200793 +1744a403 +04f71263 +ffff67b7 +00f407b3 +0000a737 +04e7e863 +00026537 +d1450513 +00000097 +f04080e7 +000287b7 +1707a703 +00e47463 +1687a823 +000287b7 +16c7a703 +00877463 +1687a623 +00140413 +1684aa23 +00c12083 +00812403 +00412483 +01010113 +00008067 +00a40023 +fc1ff06f +ff010113 +00812423 +00050413 +0ff57513 +00112623 +00000097 +f60080e7 +00845513 +0ff57513 +00000097 +f50080e7 +01045513 +0ff57513 +00000097 +f40080e7 +01845513 +00812403 +00c12083 +01010113 +00000317 +f2830067 +000287b7 +1747a783 +fe010113 +00912a23 +40f684b3 +000287b7 +1697c703 +00812c23 +01212823 +01312623 +00112e23 +00200793 +00050993 +00058913 +00060413 +04f71063 +0014f793 +00078a63 +00026537 +d2850513 +00000097 +e14080e7 +00001737 +000027b7 +00e48733 +ffe78793 +00e7fa63 +00026537 +d3450513 +00000097 +df0080e7 +01441793 +0137e7b3 +00f91913 +00c4d713 +0127e7b3 +01f71713 +00e7e7b3 +0044d713 +08077713 +000016b7 +00e7e7b3 +f0068693 +00749713 +01c12083 +01812403 +00d77733 +00e7e7b3 +01449513 +7e000737 +00e57533 +01412483 +01012903 +00c12983 +00a7e533 +02010113 +00008067 +000287b7 +1747a783 +ff010113 +00812423 +40f58433 +000287b7 +1697c703 +00912223 +00112623 +00200793 +00050493 +02f71e63 +00147793 +00078a63 +00026537 +d2850513 +00000097 +d40080e7 +001007b7 +00f407b3 +00200737 +00e7ea63 +00026537 +d4450513 +00000097 +d20080e7 +01441513 +7fe007b7 +00f57533 +00749493 +000ff7b7 +00f477b3 +00956533 +00f56533 +01445793 +01f79793 +00f56533 +00941413 +001007b7 +00f47433 +00c12083 +00856533 +00812403 +00412483 +06f56513 +01010113 +00008067 +000287b7 +0e07c783 +02a78263 +00a7fa63 +00026537 +d5450513 +00000317 +cac30067 +00026537 +d6450513 +ff1ff06f +00008067 +0002a7b7 +8987a783 +e0f02823 +f6a00023 +00008067 +fd010113 +00000593 +01d00513 +02112623 +02812423 +02912223 +03212023 +01312e23 +01412c23 +01512a23 +01612823 +01712623 +01812423 +01912223 +01a12023 +00000097 +854080e7 +000287b7 +0047a403 +00040513 +00000097 +808080e7 +00000097 +948080e7 +02800593 +01d00513 +00000097 +828080e7 +00000097 +930080e7 +0002a7b7 +83c7a483 +02048e63 +0002a7b7 +8407c783 +0a078463 +00026537 +d7850513 +00000097 +8a0080e7 +00048513 +fffff097 +7b4080e7 +00026537 +d8450513 +00000097 +884080e7 +00040513 +00005097 +e3c080e7 +0ff57593 +01d00513 +fffff097 +7c0080e7 +000264b7 +d8848513 +fffff097 +778080e7 +00000413 +01500913 +05e00993 +07a00a13 +06000a93 +01b00b13 +00a00b93 +00d00c13 +fffff097 +4c0080e7 +03251863 +00026cb7 +04040063 +fff40413 +d90c8513 +0ff47413 +fffff097 +730080e7 +fe9ff06f +00026537 +d8050513 +f5dff06f +02a96063 +0f750663 +0f850463 +00800793 +00f51e63 +12041c63 +00000413 +fadff06f +04aa6463 +12aaee63 +05650463 +fe050793 +0ff7f793 +f8f9eae3 +04e00793 +f887e6e3 +0002a7b7 +00140c93 +84478793 +008787b3 +0ffcfc93 +00a78023 +000c8413 +fffff097 +418080e7 +f65ff06f +07f00793 +fa5ff06f +fffff097 +418080e7 +05b00793 +00f50663 +04f00793 +f4f512e3 +fffff097 +400080e7 +00050c93 +00900d13 +fd050793 +0ff7f793 +04fd7263 +00026537 +3b850513 +fffff097 +66c080e7 +04100793 +0afc8a63 +04200793 +0afc8a63 +03500793 +0afc8a63 +03600793 +0afc8a63 +d8848513 +fffff097 +640080e7 +ee9ff06f +fffff097 +3a4080e7 +fadff06f +0002a7b7 +84478793 +00026537 +008787b3 +3b850513 +00078023 +fffff097 +610080e7 +00100513 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +00c12b83 +00812c03 +00412c83 +00012d03 +03010113 +00008067 +fff40413 +00026537 +0ff47413 +d9050513 +f7dff06f +fe050513 +0ff57513 +ec5ff06f +05500513 +fa5ff06f +04e00513 +f9dff06f +05000513 +f95ff06f +05100513 +f8dff06f +fe010113 +00912a23 +000294b7 +00812c23 +01212823 +01312623 +00112e23 +00050913 +09048493 +00000413 +04000993 +00800613 +00090593 +00048513 +00005097 +bc8080e7 +02051463 +01041513 +41055513 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00140413 +0ff47413 +01e48493 +fb341ce3 +fff00513 +fd1ff06f +fe010113 +000287b7 +01312623 +1787d983 +00912a23 +000284b7 +00812c23 +01212823 +00112e23 +00050913 +17c48493 +00000413 +00899663 +fff00513 +0280006f +00048513 +00800613 +00090593 +00005097 +b38080e7 +01048493 +02051463 +01041513 +41055513 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00140413 +01041413 +01045413 +fa9ff06f +fe010113 +01312623 +00800613 +00000593 +000289b7 +00812c23 +00912a23 +01212823 +01412423 +01612023 +00112e23 +01512223 +00050913 +00005097 +aa4080e7 +15c9a483 +00000a13 +00000413 +00700b13 +0004ca83 +000a8513 +00000097 +8d4080e7 +02051a63 +000a0463 +1499ae23 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +00012b03 +02010113 +00008067 +008b6a63 +00140793 +00890433 +01540023 +0ff7f413 +00148493 +00100a13 +fa1ff06f +fc010113 +02912a23 +03212823 +03312623 +03512223 +02112e23 +02812c23 +03412423 +03612023 +01712e23 +01812c23 +01912a23 +00100a93 +00028937 +02d00493 +02b00993 +fffff097 +7cc080e7 +15c92403 +00044503 +00951a63 +00140413 +41500ab3 +14892e23 +fe1ff06f +01351663 +00140413 +ff1ff06f +02800793 +06f51e63 +00140413 +14892e23 +00000097 +3d8080e7 +00050493 +fffff097 +780080e7 +15c92783 +02900713 +0007c683 +00178793 +12e68063 +00026537 +d9450513 +fffff097 +748080e7 +03c12083 +03812403 +029a8533 +03012903 +03412483 +02c12983 +02812a03 +02412a83 +02012b03 +01c12b83 +01812c03 +01412c83 +04010113 +00008067 +02700793 +06f51e63 +00144483 +00048863 +00244783 +00340413 +22a78063 +fffff097 +738080e7 +28050063 +00810513 +00000097 +e34080e7 +00810513 +00000097 +d9c080e7 +22054863 +000287b7 +1647d703 +000287b7 +17c78793 +00451513 +00070e63 +00a786b3 +00c6d683 +00d77863 +00028737 +00100693 +16d703a3 +00a787b3 +0087a483 +f4dff06f +02400793 +08f51a63 +00144703 +00140793 +14f92e23 +fd070693 +0ff6f693 +00900613 +02d66e63 +00000613 +00000493 +00900513 +00500593 +0007c683 +fd068713 +0ff77813 +05057863 +fbf68713 +0ff77713 +02e5f663 +ee060ce3 +14f92e23 +ef1ff06f +fbf70713 +0ff77713 +00500693 +fae6fee3 +000287b7 +1747a483 +ed5ff06f +00449493 +fc968713 +009704b3 +00178793 +00100613 +fa9ff06f +00449493 +fedff06f +fd050793 +0ff7f793 +00900713 +eef76ce3 +03000793 +00000493 +02f51c63 +00144703 +05800793 +02f71663 +00240413 +01000993 +00000493 +00900b13 +00500b93 +04200c13 +00200c93 +0b00006f +00148493 +0ff4f493 +009409b3 +0009c503 +fffff097 +618080e7 +fe0514e3 +fff9c783 +04800713 +01000993 +fce780e3 +04200713 +00a00993 +fae79ae3 +00000793 +fff48493 +00100693 +0297d263 +00f40733 +00074703 +00178793 +fd070713 +0ff77713 +fee6f4e3 +00a00993 +f85ff06f +00a00993 +f6979ee3 +00200993 +f75ff06f +fd0a0793 +0ff7f793 +00fb7e63 +fbfa0793 +0ff7f793 +02fbec63 +058a0863 +fc9a0a13 +0ffa7793 +0537fc63 +029984b3 +00140413 +009784b3 +00044a03 +000a0513 +fffff097 +574080e7 +fa051ee3 +0180006f +04800793 +02fa1663 +01000793 +02f99263 +00140413 +14892e23 +d8dff06f +03999463 +00144503 +fffff097 +540080e7 +fe0502e3 +00026537 +da050513 +fffff097 +4ac080e7 +fd5ff06f +00b00793 +f91ff06f +000287b7 +00100713 +16e78423 +000287b7 +1697c703 +00200793 +00f71a63 +00026537 +dac50513 +fffff097 +474080e7 +00000493 +d29ff06f +00026537 +dbc50513 +fe9ff06f +fe010113 +00812c23 +00912a23 +01212823 +01312623 +01412423 +00112e23 +00000097 +c44080e7 +00050413 +000284b7 +02a00993 +02f00a13 +00026937 +fffff097 +434080e7 +15c4a783 +0007c703 +01371e63 +00178793 +14f4ae23 +00000097 +c0c080e7 +02a40433 +fd9ff06f +03471863 +00178793 +14f4ae23 +00000097 +bf0080e7 +00050663 +02a45433 +fb9ff06f +dcc90513 +fffff097 +3d0080e7 +fa9ff06f +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +00812a03 +02010113 +00008067 +fe010113 +00812c23 +00912a23 +01212823 +01312623 +01412423 +01512223 +00112e23 +00000097 +f28080e7 +00050413 +000284b7 +02b00913 +02d00993 +02600a13 +07c00a93 +fffff097 +374080e7 +15c4a783 +0007c703 +01271e63 +00178793 +14f4ae23 +00000097 +eec080e7 +00a40433 +fd9ff06f +01371e63 +00178793 +14f4ae23 +00000097 +ed0080e7 +40a40433 +fbdff06f +01471e63 +00178793 +14f4ae23 +00000097 +eb4080e7 +00a47433 +fa1ff06f +01571e63 +00178793 +14f4ae23 +00000097 +e98080e7 +00a46433 +f85ff06f +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +02010113 +00008067 +fe010113 +00812c23 +00912a23 +01312623 +01412423 +01512223 +00112e23 +01212823 +01612023 +00050493 +00028437 +02200993 +00100a93 +02c00a13 +fffff097 +294080e7 +15c42783 +0007c703 +03371e63 +03549c63 +00178793 +14f42e23 +15c42783 +0007c503 +04050863 +00178793 +01351663 +14f42e23 +0400006f +14f42e23 +fffff097 +2fc080e7 +fd9ff06f +00000097 +e94080e7 +00050b13 +00000913 +00391793 +00fb57b3 +0ff7f513 +00190913 +fffff097 +2d0080e7 +fe9914e3 +fffff097 +21c080e7 +15c42783 +0007c703 +01471863 +00178793 +14f42e23 +f6dff06f +02070c63 +01812403 +01c12083 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +00012b03 +00026537 +dd850513 +02010113 +fffff317 +1b830067 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +00012b03 +02010113 +00008067 +ff010113 +00912223 +000284b7 +00112623 +00812423 +14a4ae23 +00000097 +dd0080e7 +00050413 +fffff097 +178080e7 +15c4a783 +0007c783 +00078a63 +00026537 +de450513 +fffff097 +148080e7 +00c12083 +00040513 +00812403 +00412483 +01010113 +00008067 +000287b7 +0e07c783 +02f57063 +02800793 +02f50533 +000287b7 +0e478793 +00a78533 +00000317 +f8030067 +00026537 +ff010113 +d5450513 +00112623 +fffff097 +0f0080e7 +00c12083 +00000513 +01010113 +00008067 +ff010113 +00800613 +00112623 +00004097 +3a8080e7 +00c12083 +00153513 +01010113 +00008067 +fe010113 +00912a23 +00112e23 +00812c23 +01212823 +01312623 +00054703 +05800793 +00050493 +06f71c63 +00154403 +00900693 +fd040413 +0ff47413 +0686e263 +00254703 +fd070793 +0ff7f793 +00f6ea63 +00354703 +02070863 +0ff00413 +0080006f +fe071ce3 +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +00a00713 +02e40433 +008787b3 +0ff7f413 +01f00793 +fc87e0e3 +fc9ff06f +000265b7 +df058593 +00048513 +00004097 +2a4080e7 +00800413 +fa0506e3 +00027937 +f2890913 +00000413 +02000993 +00092583 +00048513 +00004097 +27c080e7 +f80504e3 +00140413 +0ff47413 +00490913 +ff3410e3 +f69ff06f +000287b7 +0e07c783 +ff010113 +00112623 +02f57463 +02800793 +02f50533 +000287b7 +0e478793 +00a78533 +00000097 +ee8080e7 +0ff00793 +00f51c63 +00026537 +df450513 +fffff097 +f84080e7 +0ff00513 +00c12083 +01f57513 +01010113 +00008067 +000297b7 +ff010113 +e0a7a223 +00029537 +00100593 +e0850513 +00112623 +00004097 +2c0080e7 +ff010113 +00812423 +002407b7 +00029437 +00c51513 +78a00613 +08840593 +00f50533 +00112623 +00912223 +01212023 +fffff097 +e34080e7 +000265b7 +00400613 +e0458593 +08840513 +00004097 +14c080e7 +02051e63 +08840413 +78845403 +78800513 +fffff097 +e90080e7 +40a407b3 +0017b793 +00c12083 +00812403 +00412483 +00012903 +00078513 +01010113 +00008067 +000265b7 +00400613 +e0c58593 +08840513 +00004097 +0f8080e7 +00000793 +fc0514e3 +08840793 +6887d483 +68800513 +fffff097 +e38080e7 +08840413 +00000793 +fa9514e3 +000297b7 +000294b7 +7f278793 +6f648493 +fea40913 +00048593 +00078513 +01a00613 +00004097 +038080e7 +00051e23 +00051d23 +fe250793 +fe648493 +fd279ee3 +325347b7 +64278793 +00f42023 +00100793 +f59ff06f +fe010113 +00912a23 +01212823 +00112e23 +00812c23 +01312623 +00050913 +00058493 +fffff097 +4d8080e7 +000287b7 +1697c703 +00200793 +04f71463 +0a054663 +000287b7 +00451513 +17c78793 +00a787b3 +0087a783 +08978a63 +00026537 +e1450513 +01812403 +01c12083 +01412483 +01012903 +00c12983 +02010113 +fffff317 +db830067 +00054863 +00026537 +e2050513 +fd5ff06f +000289b7 +1789d403 +0c800793 +00f41863 +00026537 +e3050513 +fb9ff06f +00028737 +17c70713 +00441793 +00e787b3 +00800613 +00090593 +00078513 +00004097 +f20080e7 +00028737 +16475703 +00140413 +00952423 +16899c23 +00e51623 +01c12083 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +000287b7 +0e07c783 +ff010113 +00112623 +00812423 +00912223 +04f57e63 +40a00433 +000287b7 +02847413 +0e478793 +000274b7 +00f40433 +e4048493 +0044a583 +00040513 +04059e63 +00000097 +b60080e7 +000017b7 +00050413 +00f56a63 +00026537 +e4050513 +fffff097 +ccc080e7 +01041513 +01055513 +0180006f +00026537 +d5450513 +fffff097 +cb0080e7 +00000513 +00c12083 +00812403 +00412483 +01010113 +00008067 +00004097 +f28080e7 +00051663 +0004d503 +fddff06f +00848493 +f85ff06f +ff010113 +00812423 +00912223 +01212023 +00112623 +0002a937 +00050493 +fffff097 +adc080e7 +81492783 +0007c703 +00178413 +80892a23 +02200793 +00f70a63 +00026537 +e4850513 +00000097 +cc8080e7 +00800613 +00000593 +00048513 +00004097 +e4c080e7 +00040793 +00048513 +00000613 +00000713 +02200893 +00800313 +01900e13 +00900e93 +0007c683 +06069a63 +00060463 +80f92a23 +02070463 +00c12083 +00812403 +00412483 +00012903 +01010113 +00008067 +00671c63 +00060463 +80f92a23 +00026537 +e5850513 +f85ff06f +fbf68593 +0ff5f593 +00be7863 +fd068593 +0ff5f593 +fcbeece3 +00170713 +00d50023 +0ff77713 +00080793 +00150513 +00100613 +f8dff06f +00178813 +fb1698e3 +81092a23 +f8dff06f +000287b7 +fe010113 +0e07c703 +00112e23 +00812c23 +00912a23 +01212823 +01312623 +01412423 +00052023 +00100793 +02e7ee63 +00026537 +d5450513 +fffff097 +b34080e7 +00000413 +01c12083 +00040513 +01812403 +01412483 +01012903 +00c12983 +00812a03 +02010113 +00008067 +000289b7 +00050913 +10c98513 +00004097 +d74080e7 +02050a63 +fff50413 +10c98a13 +01440433 +00044703 +02900793 +00f71e63 +02800593 +10c98513 +00004097 +ddc080e7 +00050493 +00051863 +00026537 +e6850513 +f81ff06f +00040023 +00150513 +00000097 +9f4080e7 +0ff00793 +00050413 +00f51863 +00026537 +df450513 +f59ff06f +00048023 +f49a7ee3 +10c98513 +00000097 +8f4080e7 +00a92023 +f49ff06f +fb010113 +0002a7b7 +03412c23 +8a07aa03 +0002a7b7 +03a12023 +f807ad03 +0002a7b7 +8a878793 +00f12223 +000277b7 +e2078793 +00f12423 +000277b7 +03812423 +e0078793 +00027c37 +03712623 +01b12e23 +04112623 +04812423 +04912223 +05212023 +03312e23 +03512a23 +03612823 +03912223 +00900b93 +0002adb7 +df0c0c13 +00f12623 +00412783 +02000513 +8afda223 +014d1463 +03e00513 +ffffe097 +364080e7 +0002a7b7 +8977c783 +02000513 +00078a63 +0002a7b7 +8987a783 +01479463 +02a00513 +ffffe097 +33c080e7 +00500593 +000a0513 +ffffe097 +378080e7 +00026437 +d1040513 +ffffe097 +334080e7 +000a0513 +ffffe097 +2e4080e7 +00800593 +ffffe097 +350080e7 +d1040513 +ffffe097 +310080e7 +000a0513 +ffffe097 +2c0080e7 +00050993 +0149d593 +01f5f713 +00755b13 +00c9dc93 +07f57693 +00f9d413 +00e12023 +03300813 +0ffb7513 +01fb7493 +0ffcf613 +007cf793 +01f47413 +0199d913 +4149da93 +55068863 +0ad86063 +01300593 +3eb68863 +02d5e663 +00300613 +3cc68663 +00f00613 +62c68663 +00026537 +f5c50513 +ffffe097 +4a4080e7 +00098513 +1600006f +01700593 +1cb68e63 +02300593 +fcb69ee3 +00367613 +00261613 +00cc0633 +00062683 +fc0684e3 +00200693 +fcf6e0e3 +00279793 +00fc07b3 +0007a503 +ffffe097 +45c080e7 +00012503 +ffffe097 +3f4080e7 +ffffe097 +408080e7 +00591513 +00956533 +01451513 +41455513 +2880006f +06700813 +21068663 +0ad86263 +03700593 +0ab68e63 +06300593 +f6b694e3 +00812703 +00279693 +00d706b3 +0006a503 +f4050ae3 +00012703 +2a071a63 +00667613 +28061263 +26078a63 +00026537 +e8850513 +ffffe097 +3e0080e7 +00040513 +ffffe097 +378080e7 +ffffe097 +38c080e7 +0079d513 +00591913 +01e57513 +7e097913 +01f9d713 +000017b7 +01256533 +00c71713 +00bb1b13 +80078793 +00e56533 +00fb7b33 +01656533 +01351513 +41355513 +01450533 +04c0006f +06f00513 +0ca68a63 +07300513 +eca694e3 +50d99863 +00026537 +f3050513 +1640006f +00026537 +eb050513 +ffffe097 +358080e7 +00048513 +ffffe097 +2f0080e7 +ffffe097 +304080e7 +000c8513 +ffffe097 +250080e7 +0002a437 +8da40413 +8a4da783 +5e87e263 +00000593 +000b8513 +ffffe097 +374080e7 +5f4d0063 +ffffe097 +45c080e7 +001b8b93 +0ffbfb93 +01500793 +004a0a13 +d4fb98e3 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +02812c03 +02412c83 +02012d03 +01c12d83 +05010113 +00008067 +00026537 +eb450513 +f55ff06f +01f9d413 +000ff7b7 +00f9f7b3 +01441413 +00f46433 +000017b7 +00b59913 +80078793 +00f97933 +0149d713 +01246433 +7fe77713 +00e46433 +00b41413 +40b45413 +01440433 +00049e63 +00026537 +ebc50513 +ffffe097 +25c080e7 +00040513 +f19ff06f +00026537 +00100793 +ec050513 +fef482e3 +ffffe097 +23c080e7 +00048513 +ffffe097 +1d4080e7 +ffffe097 +1e8080e7 +fcdff06f +d60798e3 +02049263 +00100793 +50f41e63 +020a9e63 +00026537 +5f450513 +ffffe097 +fec080e7 +ec9ff06f +020a9263 +01e57793 +00079e63 +00026537 +e7c50513 +ffffe097 +1e0080e7 +00040513 +2ac0006f +00026537 +e7c50513 +ffffe097 +1c8080e7 +00048513 +ffffe097 +160080e7 +ffffe097 +174080e7 +000a8513 +ffffe097 +084080e7 +02800513 +ffffe097 +f70080e7 +00040513 +ffffe097 +134080e7 +02900513 +ffffe097 +f58080e7 +e4dff06f +00026537 +e9050513 +d91ff06f +00400693 +00d79863 +00026537 +ec450513 +d7dff06f +00500693 +04d79463 +00026537 +ecc50513 +d69ff06f +02041c63 +00400693 +00d79e63 +00026537 +ed450513 +ffffe097 +130080e7 +00012503 +d51ff06f +00500693 +00d79863 +00026537 +edc50513 +fe1ff06f +ffffe097 +10c080e7 +00040513 +ffffe097 +0a4080e7 +ffffe097 +0b8080e7 +fc9ff06f +00c12703 +00279793 +00f707b3 +0007a503 +f0051ae3 +c2dff06f +00100613 +3cc78663 +00500593 +06b79263 +00091863 +00026537 +ea850513 +0140006f +02000793 +c0f912e3 +00026537 +e9850513 +ffffe097 +0a4080e7 +00048513 +ffffe097 +03c080e7 +ffffe097 +050080e7 +00040513 +ffffe097 +028080e7 +ffffe097 +03c080e7 +00012503 +ffffe097 +f00080e7 +d39ff06f +00d99863 +00026537 +ee450513 +e59ff06f +06079463 +02041c63 +00026537 +ee850513 +ffffe097 +044080e7 +00048513 +ffffe097 +fdc080e7 +ffffe097 +ff0080e7 +000a8513 +ffffe097 +f00080e7 +cedff06f +060a9063 +00026537 +eec50513 +ffffe097 +00c080e7 +00048513 +ffffe097 +fa4080e7 +ffffe097 +fb8080e7 +e19ff06f +00400713 +00e79c63 +fff00713 +02ea9463 +00026537 +ef050513 +fc9ff06f +00300713 +00e79a63 +00ca9863 +00026537 +ef450513 +fb1ff06f +00027737 +00279693 +dd070793 +00d787b3 +0007a503 +ffffe097 +fa4080e7 +00048513 +ffffe097 +f3c080e7 +ffffe097 +f50080e7 +00040513 +f4dff06f +00100693 +00d91e63 +00027737 +00279693 +d9070793 +00d787b3 +0007a503 +0500006f +02000693 +08d91063 +06079463 +02041c63 +00026537 +efc50513 +ffffe097 +f48080e7 +00048513 +ffffe097 +ee0080e7 +ffffe097 +ef4080e7 +00012503 +ffffe097 +ecc080e7 +bf1ff06f +00026537 +f0050513 +ffffe097 +f14080e7 +00048513 +ffffe097 +eac080e7 +ffffe097 +ec0080e7 +00040513 +fb9ff06f +00500693 +a4d790e3 +00026537 +f0450513 +fcdff06f +a20918e3 +00300713 +00e79a63 +02041e63 +00026537 +f0850513 +f7dff06f +00200713 +02e79463 +00012703 +00071863 +00026537 +f1050513 +e9dff06f +00041863 +00026537 +f1850513 +f51ff06f +00027737 +00279693 +db070793 +f1dff06f +00079863 +00026537 +f2050513 +c79ff06f +00100693 +9cd792e3 +00026537 +f2850513 +c65ff06f +001006b7 +07368693 +00d99863 +00026537 +f3850513 +c4dff06f +302006b7 +07368693 +00d99863 +00026537 +f4050513 +c35ff06f +702006b7 +07368693 +00d99863 +00026537 +f4850513 +c1dff06f +105006b7 +07368693 +00d99863 +00026537 +f5050513 +c05ff06f +000276b7 +00279813 +d7068693 +010686b3 +0006a503 +940500e3 +01059913 +00200713 +01095913 +02e79e63 +02041c63 +00026537 +f5450513 +ffffe097 +dcc080e7 +00048513 +ffffe097 +d64080e7 +ffffe097 +d78080e7 +00090513 +ffffe097 +d78080e7 +a75ff06f +00467993 +02049e63 +000267b7 +7c078793 +010787b3 +0007a503 +ffffe097 +d88080e7 +00090513 +ffffe097 +d48080e7 +ffffe097 +d34080e7 +b8098ae3 +00040513 +cf5ff06f +ffffe097 +d60080e7 +00048513 +ffffe097 +cf8080e7 +ffffe097 +d0c080e7 +fc5ff06f +02000513 +ffffe097 +b10080e7 +a0dff06f +00026537 +f6050513 +ffffe097 +e2c080e7 +ffffe097 +e70080e7 +00026537 +d8450513 +ffffe097 +e14080e7 +a05ff06f +84091ce3 +00026537 +ea050513 +c55ff06f +b20a92e3 +00026537 +e8450513 +b09ff06f +ff010113 +00812423 +00112623 +00050413 +ffffe097 +fa4080e7 +0002a537 +81452583 +00042023 +00000813 +00058793 +00900893 +00500313 +03900e13 +0007c603 +fd060693 +0ff6f713 +02e8f863 +fbf60713 +0ff77713 +02e37263 +00080463 +80f52a23 +00c12083 +00812403 +40b78533 +0ff57513 +01010113 +00008067 +00042703 +00471713 +00ce7463 +fc960693 +00d76733 +00e42023 +00178793 +00100813 +fa5ff06f +00054783 +03900713 +02f76863 +fd078793 +00154503 +03900713 +0ff7f793 +02a76263 +fd050513 +00479793 +0ff57513 +00f56533 +0ff57513 +00008067 +fc978793 +fd5ff06f +fc950513 +fe1ff06f +000287b7 +1697c703 +fe010113 +00812c23 +00912a23 +01212823 +01312623 +00112e23 +00200793 +00050993 +00058913 +00060413 +00068493 +02f71463 +000017b7 +80078793 +00001737 +00f687b3 +00e7ea63 +00026537 +f6850513 +ffffe097 +ffc080e7 +00f41413 +01346433 +00791913 +01246433 +01449513 +01c12083 +00a46533 +01812403 +01412483 +01012903 +00c12983 +02010113 +00008067 +fa010113 +00028737 +05412423 +00028a37 +06070793 +04112e23 +04812c23 +04912a23 +05212823 +05312623 +05512223 +05612023 +03712e23 +03812c23 +03912a23 +03a12823 +160a2023 +00000613 +06070713 +02200513 +02700593 +03b00813 +0007c683 +04068063 +00a69863 +00164613 +00178793 +fedff06f +02b69063 +fe061ae3 +0017c683 +fe0686e3 +0027c683 +feb692e3 +00278793 +fddff06f +fd069ce3 +fc061ae3 +00078023 +000284b7 +14e4ae23 +ffffe097 +f30080e7 +15c4a783 +00900693 +00900613 +0007c703 +fd070713 +0ff77713 +02e6fe63 +ffffe097 +f0c080e7 +15c4a783 +0007c503 +0a050663 +ffffe097 +f30080e7 +02051e63 +00026537 +f7c50513 +ffffe097 +ed0080e7 +08c0006f +00178793 +0007c703 +fd070693 +0ff6f693 +fed678e3 +0df77713 +fa071ae3 +14f4ae23 +fadff06f +02010513 +ffffe097 +5f4080e7 +ffffe097 +ea8080e7 +15c4a403 +03a00793 +00044703 +0cf71a63 +02012783 +00140413 +1484ae23 +02f12423 +02412783 +02f12623 +ffffe097 +e78080e7 +15c4a783 +0007c503 +04051863 +000287b7 +1747a583 +02810513 +fffff097 +018080e7 +05c12083 +05812403 +05412483 +05012903 +04c12983 +04812a03 +04412a83 +04012b03 +03c12b83 +03812c03 +03412c83 +03012d03 +06010113 +00008067 +ffffe097 +e50080e7 +f20502e3 +02010513 +ffffe097 +54c080e7 +ffffe097 +e00080e7 +00100913 +000265b7 +f8c58593 +02010513 +fffff097 +cfc080e7 +0a050263 +fffff097 +a28080e7 +00050593 +06091663 +00026537 +f9050513 +ee1ff06f +000265b7 +00300613 +f8c58593 +00040513 +00003097 +078080e7 +00000913 +fa0518e3 +00344503 +ffffe097 +e08080e7 +fa0510e3 +02012783 +00340413 +1484ae23 +02f12423 +02412783 +02012223 +02f12623 +005557b7 +14578793 +02f12023 +f71ff06f +000287b7 +1687c783 +f00780e3 +000287b7 +1697c703 +00100793 +eef718e3 +00026537 +fa450513 +e5dff06f +00090c63 +000287b7 +1747a583 +02810513 +fffff097 +eec080e7 +000265b7 +fbc58593 +02010513 +fffff097 +c2c080e7 +00050c63 +fffff097 +958080e7 +000287b7 +16a7aa23 +eadff06f +000265b7 +fc058593 +02010513 +fffff097 +c00080e7 +00050a63 +000287b7 +00100713 +16e78323 +e85ff06f +000265b7 +fc458593 +02010513 +fffff097 +bd8080e7 +02051a63 +000265b7 +fc858593 +02010513 +fffff097 +bc0080e7 +00051e63 +000265b7 +fd058593 +02010513 +fffff097 +ba8080e7 +00050a63 +00100513 +fffff097 +9b8080e7 +e2dff06f +000265b7 +fd858593 +02010513 +fffff097 +b80080e7 +00050663 +00200513 +fd9ff06f +000265b7 +f5c58593 +02010513 +fffff097 +b60080e7 +00051e63 +000265b7 +fdc58593 +02010513 +fffff097 +b48080e7 +00050663 +00400513 +fa1ff06f +000265b7 +27058593 +02010513 +fffff097 +b28080e7 +00051e63 +000265b7 +fe458593 +02010513 +fffff097 +b10080e7 +02050063 +fffff097 +83c080e7 +00028737 +17472783 +00a787b3 +16f72a23 +d89ff06f +000265b7 +fec58593 +02010513 +fffff097 +adc080e7 +04050463 +fffff097 +808080e7 +02050863 +fff50413 +00857533 +02051263 +000284b7 +1744a783 +00f477b3 +d40784e3 +00000513 +ffffe097 +c38080e7 +fe9ff06f +00026537 +ff450513 +c99ff06f +00026ab7 +7e0a8413 +00000913 +7e0a8a93 +05900993 +00800613 +00040593 +02010513 +00003097 +e20080e7 +280504e3 +00190913 +01091913 +01095913 +01040413 +fd391ce3 +00026537 +04850513 +c4dff06f +0f971063 +00069e63 +00144683 +00068a63 +00244703 +00000693 +01971463 +00240413 +00140413 +00100613 +00044703 +0a071263 +00060463 +1484ae23 +40b407b3 +0ff7fc13 +0ff7f793 +00f587b3 +02000613 +00900693 +000c0863 +fff7c703 +08c70a63 +08d70863 +0e09cd03 +00300793 +00fd0463 +098cf863 +00026537 +d6450513 +ffffe097 +aa0080e7 +160a2783 +c4079ce3 +000287b7 +1747aa03 +00491913 +012a8933 +003a7793 +00c92403 +0c078663 +00026537 +00c50513 +b9dff06f +01071863 +00178793 +0ff7f793 +f65ff06f +f71710e3 +f4078ee3 +fff78793 +fedff06f +00f6e333 +f20316e3 +f5770ce3 +f39706e3 +fca718e3 +0016c693 +f39ff06f +fffc0c13 +0ffc7c13 +fff78793 +f59ff06f +02800793 +02fd07b3 +000c0613 +001d0d13 +016787b3 +00078513 +00003097 +bbc080e7 +018507b3 +00078023 +00044783 +0fa98023 +01779a63 +00140413 +1484ae23 +ffffe097 +9f4080e7 +15c4a583 +0005c783 +f2078ce3 +00058413 +00000693 +00000793 +00000613 +02200513 +02800813 +02900893 +ec1ff06f +00894783 +01e00713 +b6f764e3 +00026737 +00279793 +69870713 +00e787b3 +0007a783 +00078067 +00300513 +ffffe097 +cc0080e7 +00000513 +fffff097 +9b4080e7 +00050493 +00100513 +fffff097 +9a4080e7 +00050913 +00749493 +00f91913 +00200513 +0124e4b3 +fffff097 +988080e7 +0084e4b3 +01451513 +07c0006f +00300513 +ffffe097 +c70080e7 +00200513 +fffff097 +800080e7 +000287b7 +1697c703 +00200793 +00050493 +00f71e63 +01f00793 +00a7fa63 +00026537 +02850513 +ffffe097 +8fc080e7 +00000513 +fffff097 +92c080e7 +01f4f493 +00050913 +01449493 +00100513 +fffff097 +914080e7 +0084e4b3 +00791913 +0124e4b3 +00f51513 +00956533 +0dc0006f +00200513 +ffffe097 +bf0080e7 +00000513 +fffff097 +8e4080e7 +00a12423 +01c10513 +fffff097 +d2c080e7 +01c12683 +00812583 +00050613 +00040513 +00000097 +830080e7 +0980006f +00200513 +ffffe097 +bac080e7 +00000513 +fffff097 +8a0080e7 +00050913 +01c10513 +fffff097 +ce8080e7 +000287b7 +1697c703 +00200793 +01c12483 +00050993 +02f71463 +000017b7 +80078793 +00001737 +00f487b3 +00e7ea63 +00026537 +f6850513 +ffffe097 +818080e7 +00001737 +00749793 +f8070713 +0054d493 +00e7f7b3 +01949493 +0097e7b3 +0087e7b3 +00f99993 +0137e7b3 +01491513 +00a7e533 +ffffe097 +928080e7 +99dff06f +00300513 +ffffe097 +b0c080e7 +00000513 +fffff097 +800080e7 +00a12623 +00100513 +ffffe097 +7f0080e7 +00a12423 +00200513 +ffffe097 +67c080e7 +00812603 +00c12583 +00050693 +00040513 +ffffe097 +928080e7 +fa5ff06f +00200513 +ffffe097 +ab8080e7 +00000513 +ffffe097 +7ac080e7 +00050913 +00100513 +ffffe097 +638080e7 +000287b7 +1697c703 +00200793 +00050493 +00f71e63 +001007b7 +00f56a63 +00026537 +f6850513 +ffffd097 +734080e7 +00c49493 +0084e4b3 +00791513 +e61ff06f +0e09c703 +00100793 +00f71e63 +00000513 +ffffe097 +5e4080e7 +00050593 +00100513 +0340006f +00200513 +ffffe097 +a30080e7 +00000513 +ffffe097 +724080e7 +00050413 +00100513 +ffffe097 +5b0080e7 +00050593 +00040513 +ffffe097 +948080e7 +ee1ff06f +0e09c783 +00100713 +02e79063 +00000513 +ffffe097 +6e8080e7 +00050613 +00000693 +00100593 +e15ff06f +00200713 +dee782e3 +00300513 +ffffe097 +9c4080e7 +00000513 +ffffe097 +6b8080e7 +00a12623 +00100513 +ffffe097 +6a8080e7 +00a12423 +00200513 +ffffe097 +534080e7 +00812603 +00c12583 +00050693 +dc5ff06f +00300513 +ffffe097 +97c080e7 +00000513 +ffffe097 +670080e7 +00050493 +00200513 +ffffe097 +660080e7 +00f51513 +00749493 +00a4e4b3 +00100513 +fffff097 +8e0080e7 +0084e433 +01451513 +00856533 +e19ff06f +00300513 +ffffe097 +92c080e7 +00200513 +ffffe097 +4bc080e7 +000287b7 +1697c703 +00200793 +00050493 +00f71e63 +01f00793 +00a7fa63 +00026537 +03850513 +ffffd097 +5b8080e7 +00000513 +ffffe097 +5e8080e7 +00f49493 +000f87b7 +00f4f4b3 +00751513 +0084e4b3 +00a4e4b3 +00100513 +fffff097 +85c080e7 +c41ff06f +00000513 +ffffe097 +8b4080e7 +00040513 +d8dff06f +00200513 +ffffe097 +8a0080e7 +00000513 +ffffe097 +594080e7 +000284b7 +00028937 +00050413 +00100513 +160483a3 +16090423 +ffffe097 +410080e7 +16894783 +1674c703 +00050693 +00e7e7b3 +02079263 +80000793 +00f54e63 +7ff00793 +00a7ca63 +00000613 +00040593 +01300513 +c81ff06f +000017b7 +80078793 +00f687b3 +fffff737 +00e7f7b3 +00741713 +00e7e7b3 +0377e513 +00d12423 +ffffd097 +620080e7 +00812683 +00040613 +01469693 +4146d693 +00060593 +fb9ff06f +00200513 +ffffd097 +7f0080e7 +00000513 +ffffe097 +4e4080e7 +00050493 +00100513 +ffffe097 +370080e7 +000017b7 +41450a33 +80078793 +fffff737 +00fa07b3 +00e7f7b3 +00749713 +00e7e7b3 +0177e513 +ffffd097 +5b4080e7 +014a1693 +4146d693 +00048613 +f99ff06f +00200513 +ffffd097 +78c080e7 +00000513 +ffffe097 +480080e7 +00a12423 +00100513 +ffffe097 +470080e7 +00812583 +00050613 +00000693 +f1dff06f +00200513 +ffffd097 +754080e7 +00000513 +ffffe097 +448080e7 +00a12423 +00100513 +ffffe097 +438080e7 +00812583 +00050613 +fff00693 +00004537 +01350513 +b61ff06f +00200513 +ffffd097 +714080e7 +00000513 +ffffe097 +408080e7 +00050413 +00100513 +ffffe097 +3f8080e7 +01451513 +00741413 +00a46433 +40000537 +03350513 +da5ff06f +00200513 +ffffd097 +6d4080e7 +00000513 +ffffe097 +3c8080e7 +00a12423 +00100513 +ffffe097 +3b8080e7 +00050613 +00812583 +00100693 +00003537 +f81ff06f +00200513 +ffffd097 +698080e7 +00000513 +ffffe097 +38c080e7 +00050413 +00100513 +ffffe097 +37c080e7 +01451513 +00741413 +00a46433 +00003537 +f85ff06f +00200513 +ffffd097 +65c080e7 +00000513 +ffffe097 +350080e7 +00050413 +00100513 +ffffe097 +340080e7 +00741413 +00f51513 +00a46433 +00002537 +f49ff06f +00200513 +ffffd097 +620080e7 +00000513 +ffffe097 +314080e7 +00050413 +00100513 +ffffe097 +304080e7 +00741413 +01451513 +fc5ff06f +00100513 +ffffd097 +5ec080e7 +00000513 +ffffe097 +17c080e7 +00050593 +00000513 +bcdff06f +00100513 +ffffd097 +5c8080e7 +b75ff06f +00100513 +ffffd097 +5b8080e7 +00000513 +ffffe097 +2ac080e7 +00050613 +00000693 +00000593 +06700513 +9d9ff06f +00000513 +ffffd097 +58c080e7 +00008537 +06750513 +a61ff06f +00200513 +ffffd097 +574080e7 +00000513 +ffffe097 +268080e7 +00a12423 +00100513 +ffffe097 +0f4080e7 +00050693 +00000613 +00812583 +a79ff06f +00200513 +ffffd097 +53c080e7 +00000513 +ffffe097 +230080e7 +00a12423 +00100513 +ffffe097 +0bc080e7 +00812603 +00050693 +00000593 +a41ff06f +00300513 +ffffd097 +504080e7 +00000513 +ffffe097 +1f8080e7 +00a12623 +00100513 +ffffe097 +1e8080e7 +00a12423 +00200513 +ffffe097 +074080e7 +00c12603 +00050693 +f81ff06f +00200513 +ffffd097 +4c0080e7 +00000513 +ffffe097 +1b4080e7 +00050413 +00100513 +ffffe097 +43c080e7 +01451513 +00741413 +00a46433 +00002537 +07350513 +b51ff06f +00200513 +ffffd097 +480080e7 +00100513 +ffffe097 +174080e7 +00050493 +00000513 +ffffe097 +3fc080e7 +00f49493 +01451513 +00a4e533 +b19ff06f +00200513 +ffffd097 +448080e7 +00100513 +ffffe097 +fd8080e7 +000287b7 +1697c703 +00200793 +00050493 +00f71e63 +01f00793 +00a7fa63 +00026537 +03850513 +ffffd097 +0d4080e7 +00f49493 +000f87b7 +00f4f4b3 +0084e4b3 +00000513 +b31ff06f +000289b7 +00028b37 +0e098023 +02c00b93 +ffffd097 +0b8080e7 +02700c93 +0e4b0b13 +ebcff06f +fe010113 +00112e23 +00812c23 +00912a23 +01212823 +01312623 +01412423 +00100a13 +00050993 +f5400023 +00600513 +00058913 +00060413 +00068493 +ffffd097 +f14080e7 +f4000023 +f5400023 +00098513 +ffffd097 +f00080e7 +009404b3 +00090513 +01049493 +ffffd097 +f04080e7 +0104d493 +01041793 +0107d793 +02f49263 +f4004783 +f4000023 +0027f793 +02078463 +00026537 +05c50513 +ffffe097 +098080e7 +00044503 +00140413 +ffffd097 +eac080e7 +fc5ff06f +e0002483 +00001437 +00100913 +bb840413 +f5200023 +00500513 +ffffd097 +e88080e7 +00000513 +ffffd097 +e7c080e7 +f4000023 +e0002783 +409787b3 +faf442e3 +00157513 +fc0518e3 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +02010113 +00008067 +fb010113 +04912223 +05212023 +03312e23 +03512a23 +00060693 +00050913 +00058993 +00060493 +00010ab7 +00058613 +00050593 +00200513 +04812423 +03712623 +04112623 +03412c23 +03612823 +00000413 +00000097 +ea4080e7 +02000b93 +fffa8a93 +02946863 +04c12083 +04812403 +04412483 +04012903 +03c12983 +03812a03 +03412a83 +03012b03 +02c12b83 +05010113 +00008067 +40848a33 +014bd463 +02000a13 +010a1b13 +010b5b13 +000b0613 +00010593 +01240533 +ffffd097 +df0080e7 +015a7633 +008985b3 +00010513 +00002097 +10c080e7 +00050a63 +00026537 +05c50513 +ffffe097 +f44080e7 +01640433 +01041413 +01045413 +f75ff06f +ff010113 +01212023 +00029937 +00812423 +f4895403 +00912223 +00112623 +01441793 +00050493 +0a079663 +00029737 +08870793 +0067d783 +000298b7 +00c45513 +1c000693 +08870613 +1bf00e93 +04c88893 +00200593 +00fee463 +00078593 +0035d713 +01071713 +01075713 +00e88733 +00074803 +0075fe13 +00158793 +41c85333 +01079793 +00137313 +0107d793 +0c031a63 +00f61323 +000297b7 +00151513 +f3878793 +00a787b3 +00100693 +01c696b3 +00b79023 +00c59593 +002407b7 +00d86833 +00000613 +00000693 +00f585b3 +02000513 +01070023 +00000097 +d3c080e7 +0ff47713 +000295b7 +00140413 +f4c58793 +01041413 +00e787b3 +01045413 +00978023 +f4891423 +0ff47793 +08079063 +fff40713 +000297b7 +40c75713 +00171713 +f3878793 +00e787b3 +0007d503 +f0040413 +01441413 +01445413 +002407b7 +00f40433 +00c51513 +00850533 +00812403 +00c12083 +00412483 +00012903 +10000613 +f4c58593 +01010113 +00000317 +dc430067 +fff68693 +01069693 +0106d693 +ee0694e3 +00026537 +06850513 +ffffe097 +dbc080e7 +00c12083 +00812403 +00412483 +00012903 +01010113 +00008067 +fe010113 +00112e23 +00100793 +00812c23 +00912a23 +01212823 +01312623 +f4f00023 +09f00513 +ffffd097 +b9c080e7 +00000513 +ffffd097 +b90080e7 +00050493 +00000513 +ffffd097 +b80080e7 +00050413 +00000513 +ffffd097 +b70080e7 +0c200713 +f4000023 +00e49a63 +02000713 +00e41663 +01600713 +00e50a63 +00026537 +07450513 +ffffe097 +d20080e7 +00000513 +ffffe097 +d38080e7 +000299b7 +00050913 +08898493 +00100513 +0044d403 +ffffe097 +d1c080e7 +04090863 +00050c63 +0044d783 +40f40433 +01041413 +41045413 +02805e63 +00000513 +ffffe097 +cf4080e7 +00000793 +01c12083 +01812403 +00029737 +08f70223 +01412483 +01012903 +00c12983 +02010113 +00008067 +00050663 +00100793 +fd5ff06f +78a00613 +00000593 +08898513 +00002097 +e20080e7 +325347b7 +64278793 +00f4a023 +00200793 +00f49323 +fd1ff06f +fe010113 +00812c23 +00912a23 +01212823 +01312623 +00112e23 +00050913 +00058493 +00002097 +e2c080e7 +0ff57413 +00200993 +0489f863 +00090513 +ffffc097 +538080e7 +02000513 +ffffc097 +514080e7 +00048513 +00800593 +ffffc097 +550080e7 +01812403 +01c12083 +01412483 +01012903 +00c12983 +02000513 +02010113 +ffffc317 +4e030067 +02000513 +00140413 +ffffc097 +4d0080e7 +0ff47413 +f9dff06f +fd010113 +01312e23 +01412c23 +01512a23 +0002aa37 +0002a9b7 +00027ab7 +02812423 +03212023 +01712623 +01812423 +02112623 +02912223 +01612823 +01912223 +00000413 +00000913 +0002abb7 +8a8a0a13 +f0098993 +f28a8a93 +00026c37 +01800493 +029904b3 +00640b13 +8b4ba223 +01f00c93 +0ffb7b13 +08041463 +0809a583 +080c0513 +00000097 +eec080e7 +00140413 +0ff47413 +00448493 +ff6410e3 +00290513 +00000593 +0ff57513 +ffffc097 +6a8080e7 +ffffc097 +794080e7 +ffffc097 +7a8080e7 +02400793 +00190913 +f8f41ce3 +02c12083 +02812403 +02412483 +02012903 +01c12983 +01812a03 +01412a83 +01012b03 +00c12b83 +00812c03 +00412c83 +03010113 +00008067 +f88ce6e3 +01348733 +015487b3 +00072583 +0007a503 +f71ff06f +fe010113 +0002a7b7 +03600593 +00800513 +00112e23 +00812c23 +00912a23 +01212823 +f087a483 +01312623 +01412423 +01512223 +ffffc097 +608080e7 +00026537 +08450513 +ffffc097 +6a0080e7 +00026537 +08850513 +ffffc097 +5b0080e7 +00026537 +d8450513 +0002a937 +ffffc097 +67c080e7 +00900413 +0002aab7 +8a890913 +00026a37 +01500993 +00500593 +00048513 +8b2aa223 +ffffc097 +370080e7 +d10a0513 +ffffc097 +330080e7 +00048513 +ffffc097 +2e0080e7 +00800593 +ffffc097 +34c080e7 +00040513 +00140413 +03600593 +0ff47413 +ffffc097 +570080e7 +00448493 +ffffc097 +658080e7 +ffffc097 +66c080e7 +f9341ee3 +01c12083 +01812403 +01412483 +01012903 +00c12983 +00812a03 +00412a83 +02010113 +00008067 +00026537 +fe010113 +0d850513 +00112e23 +00812c23 +00912a23 +01212823 +01312623 +ffffc097 +4d4080e7 +00000593 +00000513 +ffffc097 +4fc080e7 +00026537 +0e050513 +ffffc097 +594080e7 +0002a4b7 +00026537 +8a848793 +0002a437 +0e850513 +0002a9b7 +8af42223 +8a848913 +ffffc097 +254080e7 +8da98993 +8a442783 +0737e463 +00026537 +0f850513 +ffffc097 +238080e7 +0002a7b7 +f0078793 +0847a703 +1e070a63 +0887a983 +0409d863 +000287b7 +00026537 +01478793 +10450513 +8af42223 +ffffc097 +204080e7 +01f9f513 +ffffc097 +29c080e7 +8a442783 +00028537 +01450513 +00078023 +03c0006f +02000513 +ffffc097 +1c0080e7 +f89ff06f +00b00793 +1737ea63 +00026737 +00299793 +71470713 +00e787b3 +0007a783 +00078067 +00026537 +09050513 +0002a9b7 +ffffc097 +1a0080e7 +8f898993 +8a442783 +1b37e463 +00078023 +8a848513 +00026437 +04090823 +ffffc097 +3b4080e7 +d8440513 +ffffc097 +488080e7 +00000097 +c90080e7 +00000593 +00800513 +ffffc097 +3c8080e7 +000264b7 +08448513 +ffffc097 +460080e7 +00026537 +11850513 +ffffc097 +370080e7 +d8440513 +ffffc097 +444080e7 +ffffe097 +d18080e7 +00000097 +d54080e7 +00000593 +01500513 +ffffc097 +37c080e7 +08448513 +ffffc097 +418080e7 +00026537 +13850513 +ffffc097 +328080e7 +d8440513 +ffffc097 +3fc080e7 +ffffc097 +46c080e7 +00000593 +01c00513 +ffffc097 +33c080e7 +08448513 +ffffc097 +3d8080e7 +00026537 +14050513 +ffffc097 +2e8080e7 +d8440513 +01812403 +01c12083 +01412483 +01012903 +00c12983 +02010113 +ffffc317 +3a430067 +00026537 +f3850513 +ed9ff06f +00026537 +0b450513 +ecdff06f +00026537 +0c450513 +ec1ff06f +00026537 +f3050513 +eb5ff06f +000287b7 +00026537 +01478793 +11050513 +8af42223 +ffffc097 +040080e7 +00098513 +e3dff06f +0002a7b7 +8387c783 +00400713 +fff78793 +0ff7f793 +02f76463 +00026737 +00279793 +7ac70713 +00f707b3 +0007a503 +e61ff06f +00026537 +0a050513 +e55ff06f +00026537 +e7850513 +e49ff06f +02000513 +ffffc097 +fcc080e7 +e49ff06f +f7010113 +0002a7b7 +84478793 +08912223 +0002a4b7 +08812423 +09212023 +07312e23 +80f4aa23 +08112623 +07412c23 +07512a23 +07612823 +07712623 +07812423 +07912223 +07a12023 +05b12e23 +ffffc097 +474080e7 +8144a403 +0002a9b7 +0002a937 +00044783 +8209ae23 +84090023 +00f12223 +00412703 +03a00793 +30f71663 +00140a13 +00000993 +00900713 +00500693 +013a07b3 +0007c903 +fd090793 +0ff7f793 +00f77863 +fbf90793 +0ff7f793 +00f6e863 +00198993 +0ff9f993 +fd9ff06f +07377663 +0019f793 +00f96933 +06091063 +000a0513 +ffffe097 +4d8080e7 +00550793 +00179793 +00050493 +04f99263 +000a0993 +00450a93 +00000a13 +00098513 +ffffe097 +4b0080e7 +01250933 +001a0a13 +0ff97913 +00298993 +ff4ad2e3 +02090463 +000267b7 +0002a737 +1c878793 +0100006f +000267b7 +0002a737 +1b878793 +82f72e23 +2980006f +00340513 +ffffe097 +468080e7 +00050913 +00540513 +ffffe097 +458080e7 +00050993 +00740513 +ffffe097 +448080e7 +00100793 +10f51863 +000289b7 +00028937 +0009a403 +05892a83 +048afe63 +000267b7 +1dc78793 +0002a737 +82f72e23 +0002a7b7 +84a78023 +00000513 +08c12083 +08812403 +08412483 +08012903 +07c12983 +07812a03 +07412a83 +07012b03 +06c12b83 +06812c03 +06412c83 +06012d03 +05c12d83 +09010113 +00008067 +0002a4b7 +00026537 +8a848793 +0002aa37 +1e850513 +8afa2223 +ffffc097 +dec080e7 +00500593 +00040513 +ffffc097 +e10080e7 +02d00513 +ffffc097 +db8080e7 +00500593 +000a8513 +ffffc097 +df4080e7 +8a4a2783 +8a848593 +000284b7 +00078023 +03448513 +00001097 +6c4080e7 +0002a7b7 +03448493 +8297ae23 +ff047413 +0002a7b7 +8887ae23 +fff00793 +00f9a023 +000287b7 +04092c23 +0407aa23 +ffffc097 +100080e7 +f25ff06f +00400793 +04f51063 +00200793 +f0f49ae3 +00940513 +ffffe097 +318080e7 +00050493 +00b40513 +ffffe097 +308080e7 +01849493 +01051513 +00a4e4b3 +000287b7 +0497aa23 +ee1ff06f +00200793 +02f51a63 +eca49ae3 +00940513 +ffffe097 +2d8080e7 +00050493 +00b40513 +ffffe097 +2c8080e7 +00849493 +00a4e4b3 +00449493 +fc1ff06f +ea0512e3 +ea0480e3 +000287b7 +0547a783 +00891913 +01396933 +00f90933 +00940413 +00990a33 +00090993 +ffff6ab7 +0000ab37 +00040513 +ffffe097 +27c080e7 +015987b3 +0167ea63 +000267b7 +0002a737 +1f478793 +dedff06f +00a98023 +00198993 +00240413 +fd4998e3 +000287b7 +0007a703 +00e97463 +0127a023 +000287b7 +0587a703 +fff48493 +012484b3 +e29770e3 +0497ac23 +e19ff06f +000265b7 +00300613 +20858593 +00040513 +00001097 +4f4080e7 +4e051063 +00029537 +00340413 +e0850513 +8084aa23 +00001097 +5c0080e7 +02050263 +000297b7 +e047a703 +0002a7b7 +82e7ae23 +0002a7b7 +00100713 +84e78023 +dc1ff06f +03810513 +ffffd097 +5e8080e7 +fffff097 +550080e7 +03810513 +ffffd097 +894080e7 +00050493 +00055863 +00026537 +20c50513 +2940006f +01e00713 +02e50733 +000297b7 +08878793 +01600413 +01c00913 +00e787b3 +0107d783 +00f12423 +000287b7 +16079c23 +000287b7 +04078e23 +00040513 +00140413 +00000593 +0ff47413 +ffffc097 +df8080e7 +ffffc097 +f00080e7 +ff2410e3 +0002a7b7 +00028a37 +8a878793 +00100993 +00028937 +060a0b93 +0002ac37 +00f12823 +05c94d03 +1a0d1663 +00028737 +000126b7 +173704a3 +00028737 +16d72a23 +00029ab7 +00028737 +fff00693 +00028cb7 +16d72823 +088a8793 +00028737 +160c8323 +16072623 +00000413 +00000d93 +00f12623 +166cc803 +14081c63 +00812783 +02fdf263 +0ffdfa93 +0c0a8263 +00029737 +f4c70713 +01570733 +00074703 +00a00613 +10c71263 +00140413 +01ab87b3 +01041413 +00078023 +01045413 +060a0793 +02000713 +0007c603 +18e60263 +00000b13 +00900893 +00a00313 +0007c603 +fd060713 +0ff77713 +16e8f863 +00080613 +060a0713 +02200893 +02700513 +01900313 +00900e13 +02000e93 +00074d03 +160d1463 +000287b7 +16078423 +000287b7 +16879223 +ffffe097 +104080e7 +000287b7 +1607a603 +08060a63 +000b1463 +00040b13 +05c94a83 +00500513 +19557a63 +001a8713 +04e90e23 +0740006f +00f00713 +02e48733 +00c12783 +00cdd613 +000295b7 +f4c58593 +01012a23 +00c70733 +00171713 +00e78733 +01275503 +014d9713 +00240637 +01475713 +00c70733 +00c51513 +10000613 +00e50533 +ffffc097 +f64080e7 +01412803 +eedff06f +07e00613 +01a66a63 +01ab87b3 +001d0613 +00e78023 +0ff67d13 +001d8693 +00812783 +01069d93 +010ddd93 +ebb7f4e3 +00100793 +16f98a63 +000287b7 +05c7c403 +16040e63 +0002a7b7 +8a878793 +0002a737 +00040513 +8af72223 +ffffc097 +a28080e7 +00100793 +14f41663 +00026537 +1d450513 +ffffc097 +96c080e7 +0002a7b7 +8a47a783 +0002a437 +0002a5b7 +00078023 +8a858593 +81840513 +00001097 +268080e7 +81840513 +ffffd097 +034080e7 +00178793 +e75ff06f +026b0533 +00178793 +fd050513 +00c50533 +01051b13 +010b5b13 +e6dff06f +031d1063 +00164613 +0ff67613 +00074783 +01c79463 +01d70023 +00170713 +e79ff06f +00174f03 +02ad1263 +fe0612e3 +000f1663 +00080613 +fd9ff06f +00274783 +fea79ae3 +00270713 +fc9ff06f +fc0612e3 +f9fd0613 +0ff67613 +fcc36ee3 +fe0d0793 +00f70023 +fd1ff06f +01012783 +00026537 +21c50513 +8afc2223 +00c12c23 +ffffc097 +898080e7 +000b0513 +ffffc097 +930080e7 +00026537 +22450513 +ffffc097 +87c080e7 +01812603 +00060513 +ffffc097 +86c080e7 +8a4c2603 +016a8513 +00000593 +00060023 +0ff57513 +ffffc097 +ac0080e7 +ffffc097 +bac080e7 +ffffc097 +bc0080e7 +dfdff06f +00200993 +cddff06f +00026537 +18c50513 +eb9ff06f +000287b7 +1707a403 +000287b7 +16c7a983 +0089f863 +00026537 +22850513 +ec9ff06f +0002a4b7 +00026537 +8a848793 +0002a937 +23c50513 +8af92223 +ffffb097 +7e8080e7 +00500593 +00040513 +ffffc097 +80c080e7 +02d00513 +ffffb097 +7b4080e7 +00500593 +00098513 +ffffb097 +7f0080e7 +8a492783 +8a848593 +0002a4b7 +00078023 +81848513 +00001097 +0c0080e7 +ffc47713 +0002a7b7 +8ae7a023 +ff047413 +0002a7b7 +8887ae23 +ffffc097 +b10080e7 +ffffd097 +36c080e7 +81848493 +0002a7b7 +8297ae23 +921ff06f +00412703 +04100793 +18f71463 +00144783 +0df7f793 +16079e63 +00140413 +02410513 +8084aa23 +ffffe097 +c6c080e7 +00051e63 +000267b7 +24878793 +82f9ae23 +00100793 +84f90023 +8d9ff06f +02412403 +000284b7 +00026937 +0002a9b7 +00028a37 +00848493 +27490913 +00028b37 +00200b93 +00026c37 +00100a93 +04100513 +8a99a223 +ffffb097 +6cc080e7 +02000513 +ffffb097 +6c0080e7 +00500593 +00040513 +ffffb097 +6fc080e7 +224c0513 +ffffb097 +6bc080e7 +8a49a783 +009a2223 +00078023 +ffffc097 +088080e7 +fb551ae3 +0002a5b7 +8445c783 +012a2223 +00079863 +0002a7b7 +8207ae23 +841ff06f +00028537 +84458593 +06050513 +00001097 +f94080e7 +000287b7 +1687aa23 +000287b7 +16078423 +fff00713 +000287b7 +16e7a823 +000287b7 +1607a623 +000287b7 +16079223 +177b04a3 +ffffe097 +cdc080e7 +000287b7 +1607a783 +00078c63 +0002a737 +82f72e23 +0002a7b7 +85578023 +f25ff06f +0002a7b7 +8207ae23 +0002a7b7 +8a07a783 +00f46663 +02878793 +00f46863 +ffc47413 +0002a7b7 +8a87a023 +000287b7 +1747a403 +ffffd097 +1d8080e7 +ffffc097 +96c080e7 +ee1ff06f +000265b7 +00400613 +27858593 +00040513 +00001097 +e6c080e7 +02050e63 +000265b7 +00400613 +28058593 +00040513 +00001097 +e50080e7 +02050063 +000265b7 +00300613 +28858593 +00040513 +00001097 +e34080e7 +72051263 +00412683 +04400713 +00400793 +00e69463 +00300793 +00029537 +00f407b3 +0002a737 +e0850513 +80f72a23 +00001097 +ee8080e7 +920516e3 +00412703 +05300793 +3af71463 +04010513 +ffffd097 +f24080e7 +02810513 +ffffe097 +a5c080e7 +00051863 +00026537 +28c50513 +bddff06f +02c10513 +ffffe097 +a40080e7 +fe0504e3 +02c12483 +02812983 +fd34eee3 +00148493 +000087b7 +413484b3 +ffc78793 +0097f863 +00026537 +2a450513 +ba1ff06f +fffff097 +e34080e7 +00029437 +04c40513 +03800613 +00000593 +00001097 +d50080e7 +04c40913 +00300793 +00f90023 +000297b7 +08878913 +00001537 +78090893 +08878793 +fff50513 +00000313 +04c40413 +00100e13 +0087c703 +0e071863 +01e78793 +fef89ae3 +04010513 +ffffc097 +120080e7 +00050413 +12054063 +000297b7 +0ff9f513 +f4079423 +fffff097 +c24080e7 +0089d513 +0ff57513 +fffff097 +c14080e7 +0109d513 +0ff57513 +fffff097 +c04080e7 +0189d513 +fffff097 +bf8080e7 +fff00993 +fff48493 +11349863 +000297b7 +f487da03 +0ffa7613 +10061e63 +01e00713 +02e40733 +000297b7 +08878793 +00040493 +00e787b3 +0087c703 +14071463 +000147b7 +ff878793 +0007a783 +02078263 +000146b7 +ffc68693 +e0002703 +0006a683 +40d70733 +3e800693 +02d75733 +00e787b3 +01e00693 +02d486b3 +00029737 +08870713 +00d70733 +02f71123 +0107d793 +02f71223 +1040006f +0107d683 +00078813 +00030613 +00a686b3 +40c6d693 +0ff6f693 +00280813 +eec68ce3 +01085703 +00160613 +0ff67613 +00375593 +00b405b3 +0005ce83 +00777713 +00ee1733 +01d76733 +00e58023 +fd1ff06f +00090793 +00000413 +04000693 +0087c703 +ec070ae3 +00140413 +01041713 +01075713 +01041413 +41045413 +01e78793 +fed710e3 +00026537 +3a050513 +9d5ff06f +02812783 +0007c503 +00178713 +02e12423 +fffff097 +ac8080e7 +ed5ff06f +fffa0713 +000297b7 +40c75713 +00171713 +f3878793 +00e787b3 +0007d503 +000017b7 +f0078793 +00fa77b3 +00240737 +00e787b3 +00c51513 +000295b7 +f4c58593 +00f50533 +fffff097 +990080e7 +ea1ff06f +0227d703 +0247d783 +00f767b3 +ea0788e3 +01e00a93 +035484b3 +000299b7 +08898993 +00800613 +04010593 +03540433 +009984b3 +00848513 +00001097 +a88080e7 +00029537 +000295b7 +09a50513 +01000613 +f3858593 +01449823 +00850533 +00001097 +a64080e7 +000297b7 +0847c483 +0049d783 +78800513 +0014c493 +00178793 +00f99223 +ffffc097 +830080e7 +78a99423 +002405b7 +00c49993 +00b985b3 +00000693 +00000613 +02000513 +ffffe097 +7d4080e7 +002407b7 +78a78793 +78a00413 +10000a13 +00f989b3 +f8a00a93 +00040613 +008a7463 +000a0613 +01061613 +00090593 +40898533 +01065613 +f0040413 +fffff097 +8a4080e7 +10090913 +fd541ae3 +000297b7 +08978223 +000267b7 +0002a737 +2b478793 +82f72e23 +b58ff06f +00412703 +04c00793 +1ef71a63 +04810513 +02012823 +ffffd097 +b70080e7 +03010513 +ffffd097 +6a8080e7 +00050413 +fffff097 +ac8080e7 +04810513 +ffffc097 +e0c080e7 +d8054063 +01e00713 +02e50733 +000299b7 +08898793 +00000493 +00000a13 +00e787b3 +0107db03 +00300793 +1167fc63 +00f00793 +02f50933 +00001ab7 +08898993 +fffa8a93 +00029bb7 +00029c37 +01049713 +0ff4fc93 +01075713 +0e0c8c63 +f4cb8793 +019787b3 +0007c703 +00300793 +1297e063 +00349693 +00d71733 +00ea6a33 +00f49c63 +00041463 +03412823 +03012703 +000297b7 +e0e7a023 +00148493 +01049793 +0107d793 +fb67e6e3 +0002a4b7 +00026537 +8a848793 +0002a937 +1ec50513 +8af92223 +ffffb097 +0a0080e7 +000297b7 +e007a403 +00500593 +00040513 +ffffb097 +0bc080e7 +02d00513 +ffffb097 +064080e7 +000297b7 +dfc7a503 +00500593 +ff047413 +ffffb097 +098080e7 +8a492783 +8a848593 +0002a4b7 +00078023 +81848513 +00001097 +968080e7 +0002a7b7 +81848493 +8297ae23 +0002a7b7 +8887ae23 +ffffb097 +3bc080e7 +ffffd097 +c18080e7 +9d8ff06f +00026537 +2bc50513 +ed4ff06f +00c75793 +00f907b3 +00179793 +00f987b3 +0127d503 +01577733 +002407b7 +00f70733 +00c51513 +10000613 +f4cb8593 +00e50533 +ffffb097 +558080e7 +ed5ff06f +03012783 +ffff66b7 +0000a637 +00d786b3 +00c6e863 +00026537 +2d050513 +e78ff06f +00e78023 +00178713 +02e12823 +defc2e23 +ed9ff06f +fffff097 +8f8080e7 +01600413 +01c00493 +00040513 +00140413 +00000593 +0ff47413 +ffffb097 +1ec080e7 +ffffb097 +2f4080e7 +fe9410e3 +00029437 +08840413 +0002a937 +76240993 +00000493 +0002aa37 +8a890913 +00000a93 +02000b13 +00800b93 +02000c13 +00844783 +00040d13 +08078863 +8b2a2223 +00040d93 +000a8c93 +008dc503 +00051463 +000c0513 +001c8c93 +0ffcfc93 +ffffb097 +ef8080e7 +001d8d93 +ff7c90e3 +000b0513 +ffffb097 +ee4080e7 +010d5503 +00400593 +ffffb097 +f20080e7 +04800513 +ffffb097 +ec8080e7 +01400793 +0034f593 +02f585b3 +0024d513 +01650513 +00148493 +0ff4f493 +00158593 +0ff5f593 +ffffb097 +124080e7 +ffffb097 +210080e7 +03340063 +01800793 +01e40413 +f4f49ee3 +000267b7 +0002a737 +2e478793 +ce9ff06f +fe0498e3 +00100593 +01600513 +ffffb097 +0e8080e7 +00026537 +2fc50513 +ffffb097 +0a0080e7 +fcdff06f +00412783 +02078e63 +0002a7b7 +00140413 +8087aa23 +00412783 +01900713 +fc178793 +0ff7f793 +44f76a63 +00026737 +00279793 +74470713 +00e787b3 +0007a783 +00078067 +02010513 +ffffd097 +348080e7 +00000713 +00050c63 +02012783 +00078863 +fff78793 +01079713 +01075713 +0002a7b7 +88e79a23 +00200513 +ffffb097 +7b4080e7 +00100513 +f9dfe06f +0002a7b7 +f807a403 +00040513 +02812223 +ffffb097 +d84080e7 +000017b7 +f8078793 +00f577b3 +08000713 +fce792e3 +07f57793 +06f00713 +00e78c63 +06700713 +fae798e3 +00c55793 +0077f793 +fa0792e3 +00440793 +e0f02a23 +0002a7b7 +8977c783 +00000513 +00078a63 +0002a7b7 +8987a503 +40850533 +00a03533 +00256513 +f6a003a3 +00000513 +f71ff06f +02010513 +ffffd097 +280080e7 +02050463 +02012783 +0037f713 +00070a63 +000267b7 +0002a737 +30878793 +e81fe06f +0002a737 +f8f72023 +0002a7b7 +8977c783 +02078463 +0002a737 +f8072683 +0002a737 +89872703 +00e69a63 +0002a7b7 +00100713 +88e78b23 +f09ff06f +f6f003a3 +f91ff06f +02010513 +ffffd097 +214080e7 +02050863 +02012703 +0002a7b7 +00100513 +88e7ac23 +000267b7 +19478793 +0002a737 +88a70ba3 +0002a737 +82f72e23 +c8dff06f +000267b7 +1a478793 +fe5ff06f +02010513 +ffffd097 +1cc080e7 +00050c63 +02012783 +ffc7f793 +0002a737 +8af72023 +c5dff06f +0002a7b7 +f807a783 +fedff06f +02010513 +ffffd097 +19c080e7 +00051463 +ef1fe06f +02012703 +0002a7b7 +88e7ae23 +ee1fe06f +02410513 +ffffd097 +178080e7 +04050e63 +ffff6437 +0000a4b7 +02010513 +ffffd097 +160080e7 +02050c63 +02412783 +00178713 +02e12223 +008786b3 +02012703 +0296ee63 +000267b7 +0002a737 +1f478793 +82f72e23 +0002a7b7 +00100713 +84e78023 +fffff097 +934080e7 +da5fe06f +000267b7 +0002a737 +32078793 +d2dfe06f +0ff77713 +00e78023 +f99ff06f +ffffb097 +0ac080e7 +0002a737 +81472483 +05000693 +0004c783 +08d79463 +0014c683 +04300793 +0cf69c63 +00248493 +80972a23 +02000413 +ffffb097 +078080e7 +0002a737 +81472783 +03d00693 +0007c603 +00d61663 +00178793 +80f72a23 +03410513 +ffffd097 +09c080e7 +14050463 +02000793 +03412703 +14f41663 +00377793 +12079a63 +0002a7b7 +f8e7a023 +ffffe097 +66c080e7 +ffffc097 +730080e7 +ffffe097 +76c080e7 +ce9fe06f +05800693 +04d79c63 +0014c403 +00900693 +fd040413 +0ff47413 +0486e263 +00248793 +80f72a23 +0024c783 +fd078793 +0ff7f793 +02f6e263 +00348493 +80972a23 +00a00713 +02e40733 +00e787b3 +0ff7f413 +01f00793 +0a87ee63 +0a040c63 +f3dff06f +000265b7 +00200613 +df058593 +00048513 +00000097 +368080e7 +00051c63 +00248493 +0002a7b7 +8097aa23 +00800413 +f0dff06f +000279b7 +f2898993 +01f00413 +01900a13 +00900a93 +07c9a583 +00058513 +00b12e23 +00000097 +358080e7 +01c12583 +0ff57913 +00090613 +00048513 +00000097 +310080e7 +02051863 +01248933 +00094783 +fbf78713 +0ff77713 +00ea7e63 +fd078793 +0ff7f793 +00faf863 +0002a7b7 +8127aa23 +e9dff06f +fff40413 +0ff47413 +ffc98993 +f8041ce3 +000267b7 +0002a737 +33878793 +b65fe06f +0002a7b7 +00241413 +f0078793 +008787b3 +00e7a023 +eb5ff06f +000267b7 +0002a737 +35878793 +849ff06f +000267b7 +0002a737 +38c78793 +b2dfe06f +fe010113 +00812c23 +01312623 +00112e23 +00912a23 +01212823 +01412423 +0002a437 +f6004483 +f0040793 +f60003a3 +0847a783 +0ff4f493 +f0040413 +0002a9b7 +0e078063 +08042903 +00090513 +ffffb097 +948080e7 +08842783 +00300713 +0ae79a63 +001007b7 +07378793 +00f51663 +00490913 +09242023 +0002a7b7 +08042703 +0002a437 +88079a23 +8a042783 +88098b23 +00f76663 +02878793 +00f76463 +8ae42023 +00026537 +3b050513 +ffffb097 +b6c080e7 +0002a7b7 +82978c23 +05500913 +ffffe097 +664080e7 +00100493 +04e00993 +05000a13 +ffffb097 +2ec080e7 +0a951c63 +fffff097 +928080e7 +fe0506e3 +01812403 +01c12083 +01412483 +01012903 +00c12983 +00812a03 +00026537 +3c050513 +02010113 +ffffb317 +b0830067 +00b00713 +f6e790e3 +07300793 +f4dff06f +8969c783 +04078263 +00300793 +02f49e63 +0002a7b7 +8977c783 +88098b23 +00000513 +f6f003a3 +01812403 +01c12083 +01412483 +01012903 +00c12983 +00812a03 +02010113 +ffffb317 +24430067 +0002a737 +89475783 +f00782e3 +00300693 +eed49ee3 +fff78793 +88f71a23 +00200513 +fbdff06f +01251e63 +8a042783 +ffc78793 +8af42023 +ffffc097 +430080e7 +f29ff06f +01351863 +8a042783 +00478793 +fe5ff06f +03451063 +0002a737 +89c72783 +fa078793 +88f72e23 +ffffb097 +b9c080e7 +ef9ff06f +05100793 +fef518e3 +0002a737 +89c72783 +06078793 +fddff06f +00000793 +00f61463 +00008067 +00f58733 +00074683 +00f50733 +00178793 +00d70023 +fe5ff06f +02b56a63 +fff64693 +00000793 +fff78793 +02d79663 +00008067 +00f58733 +00074683 +00f50733 +00178793 +00d70023 +fef616e3 +00008067 +00000793 +ff5ff06f +00f60733 +00e58833 +00084803 +00e50733 +01070023 +fbdff06f +00c50633 +00050793 +00c79463 +00008067 +00178793 +feb78fa3 +ff1ff06f +00000713 +00e61663 +00000513 +00008067 +00e507b3 +00170713 +00e586b3 +0007c783 +fff6c683 +fed780e3 +40d78533 +00008067 +00050793 +0007c703 +00071663 +40a78533 +00008067 +00178793 +fedff06f +00054783 +00078663 +0005c703 +00f70863 +0005c503 +40a78533 +00008067 +00150513 +00158593 +fddff06f +00050793 +0005c703 +00158593 +00178793 +fee78fa3 +fe0718e3 +00008067 +00000713 +00e61663 +00000513 +00008067 +00e507b3 +00e586b3 +0007c783 +0006c683 +00d79663 +00170713 +fc079ee3 +40d78533 +00008067 +00050793 +0ff5f593 +00000513 +0007c703 +00b71463 +00078513 +00178793 +fe0718e3 +00008067 +00152023 +00252223 +00852423 +00952623 +01252823 +01352a23 +01452c23 +01552e23 +03652023 +03752223 +03852423 +03952623 +03a52823 +03b52a23 +00000513 +00008067 +00052083 +00452103 +00852403 +00c52483 +01052903 +01452983 +01852a03 +01c52a83 +02052b03 +02452b83 +02852c03 +02c52c83 +03052d03 +03452d83 +0015b513 +00b50533 +00008067 +004b5b1b +00002020 +274e4143 +52572054 +20455449 +52454854 +00000045 +2044444f +47524154 +00005445 +4e415242 +54204843 +46204f4f +00005241 +504d554a +4f4f5420 +52414620 +00000000 +5353494d +20474e49 +5245504f +00444e41 +204f4f54 +594e414d +45504f20 +444e4152 +00000053 +31333b31 +00000000 +00003233 +00000030 +323f5b1b +00006835 +00082008 +5353494d +20474e49 +00000029 +20444142 +424d554e +00005245 +45444e55 +454e4946 +414c2044 +004c4542 +20444142 +52505845 +49535345 +00004e4f +49564944 +42204544 +00302059 +20444142 +41544144 +00000000 +20444142 +5245504f +00444e41 +00005046 +20444142 +49474552 +52455453 +00000000 +32534642 +00000000 +31534642 +00000000 +53414850 +52452045 +00524f52 +4c505544 +54414349 +414c2045 +004c4542 +204f4f54 +594e414d +42414c20 +00534c45 +20444142 +00525343 +454d414e +204e4920 +544f5551 +00005345 +20444142 +454c4946 +4d414e20 +00000045 +5346464f +52285445 +53494745 +29524554 +00000000 +524c414a +00000000 +0000524a +5a454e42 +00000000 +5a514542 +00000000 +49415253 +00000000 +494c4c53 +00000000 +494c5253 +00000000 +0049554c +50495541 +00000043 +0000004a +004c414a +5a544c42 +00000000 +5a454742 +00000000 +5a544742 +00000000 +5a454c42 +00000000 +00504f4e +0000494c +0000564d +00544f4e +5a514553 +00000000 +0047454e +00425553 +00415253 +5a454e53 +00000000 +5a544c53 +00000000 +5a544753 +00000000 +434e4546 +00000045 +434e4546 +00492e45 +4c414345 +0000004c +45524245 +00004b41 +5445524d +00000000 +45524e4d +00000054 +00494657 +52525343 +00000000 +00005744 +33333b31 +0034343b +554c4156 +554f2045 +464f2054 +4e415220 +00004547 +544e5953 +45205841 +524f5252 +00000000 +00555145 +20555145 +4445454e +20412053 +454d414e +00000000 +20555145 +4f464542 +49204552 +56205354 +45554c41 +00000000 +0047524f +00444e45 +00004244 +42464544 +00000000 +4d464544 +00000000 +00004844 +57464544 +00000000 +53464544 +00000000 +47494c41 +0000004e +47494c41 +4f54204e +50204120 +5245574f +20464f20 +00000032 +20544f4e +41204e4f +524f5720 +55203a44 +41204553 +4e47494c +00003420 +46494853 +564f2054 +33205245 +00000031 +554c4156 +564f2045 +33205245 +00000031 +4e4b4e55 +204e574f +54534e49 +54435552 +004e4f49 +53414c46 +52452048 +00524f52 +4b534944 +4c554620 +0000004c +46204f4e +4853414c +00000000 +00004350 +00003633 +43415453 +0000004b +4153494d +4e47494c +4a204445 +00504d55 +454c4c49 +204c4147 +54534e49 +54435552 +004e4f49 +4153494d +4e47494c +4c204445 +0044414f +4153494d +4e47494c +53204445 +45524f54 +00000000 +4a325b1b +00000000 +37333b31 +0034343b +53495220 +20562d43 +494e4f4d +00524f54 +504f5453 +20444550 +00205942 +45544e49 +50555252 +00002054 +50415254 +00000020 +41202020 +20524444 +4f572020 +20204452 +20202020 +54534e49 +54435552 +004e4f49 +4d454d20 +0059524f +544e4520 +73205245 +20706574 +6f204f20 +20726576 +67204720 +5820206f +69786520 +42202074 +20706220 +4d2f4420 +64646120 +45202072 +69646520 +52202074 +67657220 +203f2020 +706c6568 +00000000 +52524520 +0053524f +41455242 +494f504b +5320544e +00005445 +41455242 +494f504b +4320544e +5241454c +00004445 +20444142 +20584548 +4f434552 +00004452 +20584548 +43454843 +4d55534b +52524520 +0000524f +48204f4e +44205845 +00415441 +20584548 +44414f4c +00204445 +3a4d4f52 +544f4e20 +41484320 +4445474e +00000000 +004d5341 +454c4946 +544f4e20 +554f4620 +0000444e +4e494c20 +00002045 +0000203a +48544f4e +20474e49 +45535341 +454c424d +00000044 +45535341 +454c424d +00002044 +44412041 +202c5244 +4e454854 +534e4920 +43555254 +4e4f4954 +45203b53 +5954504d +4e494c20 +4e452045 +00005344 +0000203e +45564153 +00000000 +44414f4c +00000000 +00524944 +45564153 +414e2220 +2022454d +52415453 +4e452054 +00000044 +454c4946 +4f4f5420 +47494220 +00000000 +45564153 +00000044 +20544f4e +454d2041 +59524f4d +4c494620 +00000045 +274e4143 +4f4c2054 +54204441 +45524548 +00000000 +4f54204d +4f485320 +454d2057 +59524f4d +41474120 +00004e49 +46204f4e +53454c49 +00000000 +52444441 +20535345 +20544f4e +41204e4f +524f5720 +00000044 +44412045 +42205244 +20455459 +45545942 +2e2e2e20 +00000000 +43502052 +2d31587c +7c313358 +537c4152 +30417c50 +202e2e2e +4156203d +0045554c +204d5341 +20224e22 +41204120 +20524444 +56415320 +4e222045 +20412022 +4c202042 +2044414f +20224e22 +205d415b +52494420 +00000000 +5954203f +3f204550 +524f4620 +4c454820 +00000050 +204f4f54 +594e414d +4c494620 +00005345 +5b1b371b +6837343f +323f5b1b +00006c35 +323f5b1b +5b1b6835 +6c37343f +0000381b +53554150 +454b2045 +00000059 +494e4f4d +20524f54 +4d4d4f43 +00444e41 +50455453 +00000000 +41455242 +494f504b +0000544e +50455453 +45564f20 +00000052 +57525343 +00000000 +53525343 +00000000 +43525343 +00000000 +57525343 +00000049 +53525343 +00000049 +43525343 +00000049 +52525343 +00000057 +52525343 +00000053 +52525343 +00000043 +52525343 +00004957 +52525343 +00004953 +52525343 +00004943 +004c554d +484c554d +00000000 +484c554d +00005553 +484c554d +00000055 +00564944 +55564944 +00000000 +004d4552 +554d4552 +00000000 +00444441 +004c4c53 +00544c53 +55544c53 +00000000 +00524f58 +004c5253 +49444441 +00000000 +49544c53 +00000000 +49544c53 +00000055 +49524f58 +00000000 +0049524f +49444e41 +00000000 +00004253 +00004853 +00005753 +0000424c +0000484c +0000574c +0055424c +0055484c +00514542 +00454e42 +00544c42 +00454742 +55544c42 +00000000 +55454742 +00000000 +4154534d +00535554 +4153494d +00000000 +0045494d +4556544d +00000043 +5243534d +48435441 +00000000 +4350454d +00000000 +5541434d +00004553 +4156544d +0000004c +0050494d +43534e4d +43544152 +00000048 +50454e4d +00000043 +41434e4d +00455355 +54534e4d +53555441 +00000000 +4c455354 +00544345 +54414454 +00003141 +54414454 +00003241 +4e4f4354 +4c4f5254 +00000000 +4359434d +0000454c +534e494d +54455254 +00000000 +4359434d +0048454c +534e494d +54455254 +00000048 +4c435943 +00000045 +454d4954 +00000000 +54534e49 +00544552 +4c435943 +00004845 +454d4954 +00000048 +54534e49 +48544552 +00000000 +5241484d +00444954 +4f52455a +00000000 +00004152 +00005053 +00005047 +00005054 +00003054 +00003154 +00003254 +00003053 +00003153 +00003041 +00003341 +00003441 +00003541 +00003641 +00003741 +00003253 +00003353 +00003453 +00003553 +00003653 +00003753 +00003853 +00003953 +00303153 +00313153 +00003354 +00003454 +00003554 +00003654 +00022fcc +000232c8 +0002301c +0002309c +000230e0 +00023180 +000231d4 +00023238 +00023298 +00023310 +00023360 +000233d8 +000233ec +0002349c +00023500 +00023538 +00023578 +000235b8 +000235f4 +00023630 +0002366c +000236a0 +000236d4 +00023700 +000236c4 +00023718 +00023750 +00023788 +000237cc +0002380c +00023844 +00024148 +000242a0 +000242f4 +00024270 +0002427c +000242a0 +00024288 +000242a0 +000242a0 +000242a0 +000242a0 +00024294 +00025900 +00025910 +00025910 +0002560c +00025910 +00025654 +000256a8 +00025910 +000255a0 +00025900 +00025910 +00025910 +00025910 +00025910 +00025684 +00025910 +0002551c +00025910 +00025910 +0002572c +000254d8 +00025910 +00025910 +00025910 +00025910 +000255a0 +000263d0 +000263dc +000263ec +000263f4 +00026400 +00000000 +0002640c +00026414 +0002641c +00000000 +00026424 +0002642c +00026434 +00444441 +00000000 +00000000 +00000033 +00425553 +00000000 +00000000 +40000033 +004c4c53 +00000000 +00000000 +00001033 +00544c53 +00000000 +00000000 +00002033 +55544c53 +00000000 +00000000 +00003033 +00524f58 +00000000 +00000000 +00004033 +004c5253 +00000000 +00000000 +00005033 +00415253 +00000000 +00000000 +40005033 +0000524f +00000000 +00000000 +00006033 +00444e41 +00000000 +00000000 +00007033 +004c554d +00000000 +00000000 +02000033 +484c554d +00000000 +00000000 +02001033 +484c554d +00005553 +00000000 +02002033 +484c554d +00000055 +00000000 +02003033 +00564944 +00000000 +00000000 +02004033 +55564944 +00000000 +00000000 +02005033 +004d4552 +00000000 +00000000 +02006033 +554d4552 +00000000 +00000000 +02007033 +49444441 +00000000 +00000001 +00000013 +49544c53 +00000000 +00000001 +00002013 +49544c53 +00000055 +00000001 +00003013 +49524f58 +00000000 +00000001 +00004013 +0049524f +00000000 +00000001 +00006013 +49444e41 +00000000 +00000001 +00007013 +494c4c53 +00000000 +00000002 +00001013 +494c5253 +00000000 +00000002 +00005013 +49415253 +00000000 +00000002 +40005013 +0000424c +00000000 +00000003 +00000003 +0000484c +00000000 +00000003 +00001003 +0000574c +00000000 +00000003 +00002003 +0055424c +00000000 +00000003 +00004003 +0055484c +00000000 +00000003 +00005003 +00004253 +00000000 +00000004 +00000023 +00004853 +00000000 +00000004 +00001023 +00005753 +00000000 +00000004 +00002023 +00514542 +00000000 +00000005 +00000063 +00454e42 +00000000 +00000005 +00001063 +00544c42 +00000000 +00000005 +00004063 +00454742 +00000000 +00000005 +00005063 +55544c42 +00000000 +00000005 +00006063 +55454742 +00000000 +00000005 +00007063 +0049554c +00000000 +00000006 +00000037 +50495541 +00000043 +00000006 +00000017 +004c414a +00000000 +00000007 +00000000 +524c414a +00000000 +00000008 +00000067 +52525343 +00000057 +00000009 +00001073 +52525343 +00000053 +00000009 +00002073 +52525343 +00000043 +00000009 +00003073 +52525343 +00004957 +0000000a +00005073 +52525343 +00004953 +0000000a +00006073 +52525343 +00004943 +0000000a +00007073 +4c414345 +0000004c +0000000b +00000073 +45524245 +00004b41 +0000000b +00100073 +5445524d +00000000 +0000000b +30200073 +45524e4d +00000054 +0000000b +70200073 +00494657 +00000000 +0000000b +10500073 +434e4546 +00000045 +0000000b +0ff0000f +434e4546 +00492e45 +0000000b +0000100f +00504f4e +00000000 +0000000b +00000013 +0000494c +00000000 +0000000c +00000000 +0000414c +00000000 +0000000d +00000000 +0000564d +00000000 +0000000e +00000000 +00544f4e +00000000 +0000000f +00000000 +0047454e +00000000 +00000010 +00000000 +5a514553 +00000000 +00000011 +00000000 +5a454e53 +00000000 +00000012 +00000000 +5a544c53 +00000000 +00000013 +00000000 +5a544753 +00000000 +00000014 +00000000 +0000004a +00000000 +00000015 +00000000 +0000524a +00000000 +00000016 +00000000 +00544552 +00000000 +00000017 +00000000 +4c4c4143 +00000000 +00000018 +00000000 +5a514542 +00000000 +00000019 +00000063 +5a454e42 +00000000 +00000019 +00001063 +5a544c42 +00000000 +00000019 +00004063 +5a454742 +00000000 +00000019 +00005063 +5a544742 +00000000 +0000001a +00004063 +5a454c42 +00000000 +0000001a +00005063 +00544742 +00000000 +0000001b +00004063 +00454c42 +00000000 +0000001b +00005063 +55544742 +00000000 +0000001b +00006063 +55454c42 +00000000 +0000001b +00007063 +52525343 +00000000 +0000001c +00000000 +57525343 +00000000 +0000001d +00001073 +53525343 +00000000 +0000001d +00002073 +43525343 +00000000 +0000001d +00003073 +57525343 +00000049 +0000001e +00005073 +53525343 +00000049 +0000001e +00006073 +43525343 +00000049 +0000001e +00007073 +00000000 +0002643c +00026444 +0002644c +00000000 +00026454 +0002645c +00026464 +0002646c +00026470 +00026478 +00026480 +00026488 +0002648c +00026494 +00026498 +000264a0 +000264a4 +000264a8 +000264ac +000264b4 +000264b8 +000261d8 +000263e8 +000264bc +00025ea0 +000264c4 +000264cc +000264d4 +00000000 +000264dc +000264e0 +000264e8 +000264ec +000264f0 +00000000 +000264f4 +000264f8 +000264fc +00000000 +00026500 +00026504 +00000000 +00000000 +00026508 +0002650c +00000000 +00000000 +00026510 +00026514 +00026518 +00026520 +00000300 +00026528 +00000301 +00026530 +00000304 +00026538 +00000305 +0002653c +00000340 +00026544 +00000341 +00026550 +00000342 +00026558 +00000343 +00026560 +00000344 +00026568 +00000740 +0002656c +00000741 +00026578 +00000742 +00026580 +00000744 +00026588 +000007a0 +00026594 +000007a1 +0002659c +000007a2 +000265a4 +000007a5 +000265ac +00000b00 +000265b8 +00000b02 +000265c0 +00000b80 +000265cc +00000b82 +000265d4 +00000c00 +000265e0 +00000c01 +000265e8 +00000c02 +000265f0 +00000c80 +000265f8 +00000c81 +00026600 +00000c82 +00026608 +00000f14 +00026614 +00000000 +00000000 +0002661c +00026624 +00026628 +0002662c +00026630 +00026634 +00026638 +0002663c +00026640 +00026644 +00026648 +000265a0 +000265a8 +0002664c +00026650 +00026654 +00026658 +0002665c +00026660 +00026664 +00026668 +0002666c +00026670 +00026674 +00026678 +0002667c +00026680 +00026684 +00026688 +0002668c +00026690 +00026694 +33323130 +37363534 +42413938 +46454443 +00000000 +ffffffff +00026274 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 diff --git a/monitor/test-asm.py b/monitor/test-asm.py new file mode 100644 index 0000000..49f5503 --- /dev/null +++ b/monitor/test-asm.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 +"""Assemble a test program with the monitor's assembler (out/monitor-host) +and with GNU as, and check the bytes are the same. + + python3 test-asm.py +""" +import os +import re +import subprocess +import sys +import tempfile + +HERE = os.path.dirname(os.path.abspath(__file__)) + +# the monitor's syntax; to_gnu() below turns it into GNU as's +SRC = r""" + ORG 12000H +COUNT EQU 10 +START: LA A1,MSG ; the message + LI A2,COUNT + LI A3,BIG ; defined further on: LUI and ADDI + LI T0,-2048 + LI T1,2047 +LOOP: LBU A0,0(A1) + BEQZ A0,DONE +WAIT: LBU T0,-256(ZERO) + ANDI T0,T0,2 + BEQZ T0,WAIT + SB A0,-255(ZERO) + ADDI A1,A1,1 + J LOOP +DONE: ADDI A2,A2,-1 + BNEZ A2,START + MUL A4,A2,A3 + DIVU A5,A4,A3 + REMU A6,A4,A3 + SLLI A7,A6,3 + SRAI S2,A7,1 + SUB S3,S2,A7 + NEG S4,S3 + NOT S5,S4 + SEQZ S6,S5 + SNEZ S7,S5 + BGT S6,S7,DONE + BLEU S6,S7,LOOP + BGTZ S6,LOOP + BLEZ S6,LOOP + JAL RA,DONE + JAL DONE + JALR T0 + JALR RA,4(T0) + JR T0 + CSRR A0,MSTATUS + CSRW MSCRATCH,A0 + CSRSI MSTATUS,8 + CSRRW A1,0x305,A2 + LUI S8,0x12345 + AUIPC S9,1 + SW S9,-4(SP) + SH S9,2(SP) + LH S10,2(SP) + LHU S11,2(SP) + LW S11,0(SP) + ECALL + EBREAK + MRET + WFI + FENCE + FENCE.I + NOP + RET +MSG: DB "HI",13,10,0 + ALIGN 4 +TAB: DW START,DONE,0x12345678 + DH 1234,0xFFFF + DS 6 + DB 'A' +BIG EQU 0x12345 +""" + + +def to_gnu(src): + out = [".text", ".option norelax", ".option norvc", "_start:"] + for line in src.strip().splitlines(): + line = line.split(";")[0] + line = line.replace("$", ".") + m = re.match(r"(\w+)\s+EQU\s+(.*)", line.strip()) + if m: + out.append(".equ %s, %s" % (m.group(1).lower(), m.group(2).lower())) + continue + if line.strip().startswith("ORG"): + continue + line = re.sub(r'\bDB "(\w+)",', r'.ascii "\1"\n .byte ', line) + line = re.sub(r"\bDB\b", ".byte", line) + line = re.sub(r"\bDH\b", ".half", line) + line = re.sub(r"\bDW\b", ".word", line) + line = re.sub(r"\bDS\s+(\d+)", r".skip \1", line) + line = re.sub(r"\bALIGN (\d+)", r".balign \1, 0", line) + line = re.sub(r"\bJAL DONE\b", "jal ra,DONE", line) + line = re.sub(r"\bJALR T0\b", "jalr ra,0(t0)", line) + line = re.sub(r"\bLI A3,BIG\b", "lui a3,%hi(BIG)\n addi a3,a3,%lo(BIG)", line) + out.append(line.lower().replace("'a'", "'A'").replace('"hi"', '"HI"')) + return "\n".join(out) + "\n" + + +def main(): + pre = subprocess.run(["bash", "-c", "source %s/../scripts/rv_env.sh; echo $RV_PREFIX" % HERE], + capture_output=True, text=True).stdout.strip() + ours = subprocess.run([os.path.join(HERE, "out", "monitor-host"), "asmbin"], input=SRC, + capture_output=True, text=True).stdout.strip() + if not re.fullmatch(r"[0-9A-F]{5} [0-9A-F]+", ours): + print("FAIL the monitor's assembler: " + ours) + sys.exit(1) + start, ours = ours.split() + tmp = tempfile.mkdtemp() + open(os.path.join(tmp, "t.s"), "w").write(to_gnu(SRC)) + subprocess.run([pre + "as", "-march=rv32im_zicsr_zifencei", "-mno-relax", "-o", os.path.join(tmp, "t.o"), + os.path.join(tmp, "t.s")], check=True) + subprocess.run([pre + "ld", "-m", "elf32lriscv", "--no-relax", "-e", "0x12000", "-Ttext=0x12000", "-o", os.path.join(tmp, "t.elf"), + os.path.join(tmp, "t.o")], check=True) + subprocess.run([pre + "objcopy", "-O", "binary", os.path.join(tmp, "t.elf"), os.path.join(tmp, "t.bin")], + check=True) + gnu = open(os.path.join(tmp, "t.bin"), "rb").read().hex().upper() + # GNU pads the section's end to a word + if len(gnu) > len(ours) and set(gnu[len(ours):]) <= {"0"}: + gnu = gnu[:len(ours)] + ok = start == "12000" and ours == gnu + if not ok: + for i in range(0, max(len(ours), len(gnu)), 8): + if ours[i:i + 8] != gnu[i:i + 8]: + print("first difference at %05X: monitor %s, GNU %s" % (0x12000 + i // 2, ours[i:i + 8], gnu[i:i + 8])) + break + print("lengths: monitor %d bytes, GNU %d" % (len(ours) // 2, len(gnu) // 2)) + print(("PASS" if ok else "FAIL") + " %d bytes from 12000h the same as GNU as" % (len(ours) // 2)) + sys.exit(0 if ok else 1) + + +if __name__ == "__main__": + main() diff --git a/monitor/test-disasm.py b/monitor/test-disasm.py new file mode 100644 index 0000000..ad5fe91 --- /dev/null +++ b/monitor/test-disasm.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python3 +"""Check the monitor's disassembler and assembler (out/monitor-host, built by +build.sh) on random instructions of every kind: + + - each word disassembles to the same instruction GNU objdump shows (same + mnemonic, registers and values), and + - the monitor's assembler turns that text back into the same word. + + python3 test-disasm.py [count per kind] +""" +import os +import random +import re +import subprocess +import sys +import tempfile + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "tools")) +HOST = os.path.join(HERE, "out", "monitor-host") +N = int(sys.argv[1]) if len(sys.argv) > 1 else 300 +random.seed(1) + + +def prefix(): + out = subprocess.run(["bash", "-c", "source %s/../scripts/rv_env.sh; echo $RV_PREFIX" % HERE], + capture_output=True, text=True).stdout.strip() + return out + + +def r(): + return random.randrange(32) + + +def words(): + """Random valid RV32IM / Zicsr / system instructions.""" + ws = [] + csrs = [0x300, 0x301, 0x304, 0x305, 0x340, 0x341, 0x342, 0x343, 0x344, 0x744, 0xB00, + 0xC00, 0xC01, 0xC82, 0xF14, 0x7A0, 0x123] + for _ in range(N): + imm = random.randrange(4096) + ws.append(0x37 | r() << 7 | random.randrange(1 << 20) << 12) # lui + ws.append(0x17 | r() << 7 | random.randrange(1 << 20) << 12) # auipc + j = random.randrange(1 << 20) << 1 # jal + v = j + ws.append(0x6F | r() << 7 | (v >> 12 & 0xFF) << 12 | (v >> 11 & 1) << 20 | + (v >> 1 & 0x3FF) << 21 | (v >> 20 & 1) << 31) + ws.append(0x67 | r() << 7 | r() << 15 | imm << 20) # jalr + b = random.randrange(1 << 12) << 1 + f3 = random.choice([0, 1, 4, 5, 6, 7]) + ws.append(0x63 | f3 << 12 | r() << 15 | r() << 20 | (b >> 11 & 1) << 7 | + (b >> 1 & 15) << 8 | (b >> 5 & 0x3F) << 25 | (b >> 12 & 1) << 31) + ws.append(0x03 | random.choice([0, 1, 2, 4, 5]) << 12 | r() << 7 | r() << 15 | imm << 20) + s = random.randrange(4096) + ws.append(0x23 | random.choice([0, 1, 2]) << 12 | (s & 31) << 7 | r() << 15 | r() << 20 | + (s >> 5) << 25) + ws.append(0x13 | random.choice([0, 2, 3, 4, 6, 7]) << 12 | r() << 7 | r() << 15 | imm << 20) + ws.append(0x13 | random.choice([(1, 0), (5, 0), (5, 0x20)])[0] << 12 | r() << 7 | r() << 15 | + random.randrange(32) << 20) + f = random.choice([(0, 0), (0, 0x20), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (5, 0x20), + (6, 0), (7, 0)] + [(k, 1) for k in range(8)]) + ws.append(0x33 | f[0] << 12 | f[1] << 25 | r() << 7 | r() << 15 | r() << 20) + ws.append(0x73 | random.choice([1, 2, 3, 5, 6, 7]) << 12 | r() << 7 | r() << 15 | + random.choice(csrs) << 20) + # the special cases the disassembler shortens + ws.append(0x13 | r() << 7 | 0 << 15 | imm << 20) # li + ws.append(0x13 | r() << 7 | r() << 15) # mv + ws.append(0x00008067) # ret + ws += [0x13, 0x73, 0x00100073, 0x30200073, 0x70200073, 0x10500073, 0x0FF0000F, 0x100F] + return ws + + +def norm_gnu(text, addr): + """objdump's operand text -> list of tokens to compare.""" + text = re.sub(r"<[^>]*>|#.*", "", text).strip() + m = text.split(None, 1) + mn = m[0].upper() + ops = m[1].split(",") if len(m) > 1 else [] + return mn, [o.strip().upper() for o in ops] + + +def val(tok, base10_ok=True): + tok = tok.strip() + if re.fullmatch(r"-?0X[0-9A-F]+", tok): + return int(tok, 16) + if re.fullmatch(r"-?[0-9A-F]+H", tok): + return int(tok[:-1], 16) + if re.fullmatch(r"-?\d+", tok): + return int(tok) + return None + + +CSRN = {"MSTATUS": 0x300, "MISA": 0x301, "MIE": 0x304, "MTVEC": 0x305, "MSCRATCH": 0x340, + "MEPC": 0x341, "MCAUSE": 0x342, "MTVAL": 0x343, "MIP": 0x344, "MNSCRATCH": 0x740, + "MNEPC": 0x741, "MNCAUSE": 0x742, "MNSTATUS": 0x744, "TSELECT": 0x7A0, "TDATA1": 0x7A1, + "TDATA2": 0x7A2, "TCONTROL": 0x7A5, "MCYCLE": 0xB00, "MINSTRET": 0xB02, "MCYCLEH": 0xB80, + "MINSTRETH": 0xB82, "CYCLE": 0xC00, "TIME": 0xC01, "INSTRET": 0xC02, "CYCLEH": 0xC80, + "TIMEH": 0xC81, "INSTRETH": 0xC82, "MHARTID": 0xF14} + + +def same(gnu_mn, gnu_ops, our): + m = our.split(None, 1) + mn = m[0] + ops = [o.strip() for o in m[1].split(",")] if len(m) > 1 else [] + # objdump's other spellings of the same instructions + if gnu_mn == "JR" and gnu_ops and "(" in gnu_ops[0]: + gnu_mn, gnu_ops = "JALR", ["ZERO"] + gnu_ops + elif gnu_mn == "JALR" and len(gnu_ops) == 1 and "(" in gnu_ops[0]: + gnu_ops = ["RA"] + gnu_ops + elif gnu_mn.startswith("RD") and gnu_mn[2:] in CSRN: + gnu_mn, gnu_ops = "CSRR", gnu_ops + [gnu_mn[2:]] + gnu_ops = [str(CSRN[o]) if o in CSRN else o for o in gnu_ops] + ops = [str(CSRN[o]) if o in CSRN else o for o in ops] + alias = {"FENCE.I": "FENCE.I", "UNIMP": "DW"} + if alias.get(gnu_mn, gnu_mn) != mn: + return False + # objdump writes "fence iorw,iorw" + if mn == "FENCE": + return True + if len(ops) != len(gnu_ops): + return False + for a, b in zip(gnu_ops, ops): + if a == b: + continue + ma, mb = re.fullmatch(r"(.*)\((\w+)\)", a), re.fullmatch(r"(.*)\((\w+)\)", b) + if ma and mb: + if ma.group(2) != mb.group(2) or val(ma.group(1) or "0") != val(mb.group(1) or "0"): + return False + continue + va, vb = val(a), val(b) + if va is None or vb is None: + return False + if va & 0xFFFFFFFF != vb & 0xFFFFFFFF: + return False + return True + + +def main(): + pre = prefix() + ws = words() + tmp = tempfile.mkdtemp() + with open(os.path.join(tmp, "w.bin"), "wb") as f: + for w in ws: + f.write(w.to_bytes(4, "little")) + dump = subprocess.run([pre + "objdump", "-D", "-b", "binary", "-m", "riscv:rv32", + "-M", "numeric", "--adjust-vma=0x1000", os.path.join(tmp, "w.bin")], + capture_output=True, text=True).stdout + gnu = {} + for line in dump.splitlines(): + mm = re.match(r"\s*([0-9a-f]+):\s+([0-9a-f]{8})\s+(.*)", line) + if mm and int(mm.group(1), 16) >= 0x1000: + gnu[int(mm.group(1), 16) - 0x1000] = mm.group(3) + ours = subprocess.run([HOST, "dis"], input="".join("%08X\n" % w for w in ws), + capture_output=True, text=True).stdout.splitlines() + regn = ["ZERO", "RA", "SP", "GP", "TP", "T0", "T1", "T2", "S0", "S1"] + \ + ["A%d" % i for i in range(8)] + ["S%d" % i for i in range(2, 12)] + ["T3", "T4", "T5", "T6"] + bad_dis = 0 + for i, (w, o) in enumerate(zip(ws, ours)): + g = gnu.get(4 * i) + if g is None or w == 0x70200073: # (binutils doesn't know MNRET) + continue + gm, gops = norm_gnu(g, 0x1000) + # objdump -M numeric prints x registers: map to ABI names; and its + # branch/jump targets are relative to this word (we disassemble at 1000h) + gops = [re.sub(r"\bX(\d+)\b", lambda q: regn[int(q.group(1))], t) for t in gops] + if gm in ("J", "JAL", "BEQ", "BNE", "BLT", "BGE", "BLTU", "BGEU", "BEQZ", "BNEZ", "BLTZ", + "BGEZ", "BLEZ", "BGTZ"): + v = val(gops[-1]) + if v is not None: + gops[-1] = str((v - 4 * i) & 0xFFFFFFFF) + if not same(gm, gops, o): + bad_dis += 1 + if bad_dis <= 15: + print("DIS %08X: objdump '%s', monitor '%s'" % (w, g, o)) + # round trip through the monitor's assembler, one instruction at 1000h each + bad_asm = 0 + back = subprocess.run([HOST, "asm"], input="".join("ORG 1000H\n%s\n" % o for o in ours), + capture_output=True, text=True).stdout.splitlines() + for w, o, b in zip(ws, ours, back): + want = 0x0FF0000F if (w & 0x707F) == 0x0F else w + if b.startswith("ERROR") or int(b, 16) != want: + bad_asm += 1 + if bad_asm <= 15: + print("ASM %08X -> '%s' -> %s" % (w, o, b)) + print("%d instructions: %d disassembled differently from objdump, %d assembled back wrong" + % (len(ws), bad_dis, bad_asm)) + sys.exit(1 if bad_dis or bad_asm else 0) + + +if __name__ == "__main__": + main() diff --git a/rtl/basys3_terminal.v b/rtl/basys3_terminal.v new file mode 100644 index 0000000..5079ed2 --- /dev/null +++ b/rtl/basys3_terminal.v @@ -0,0 +1,502 @@ +`timescale 1ns / 1ps + +// Basys 3 VT220 terminal with ANSI colour, and a RISC-V computer running BASIC. +// SW15 down: keyboard (USB HID port) -> UART TX (USB-UART port), +// UART RX -> 80x30 colour text on VGA +// SW15 up: the terminal is the computer's console +// +// SW1:0 baud rate: 00 115200, 01 9600, 10 921600, 11 3000000 (8N1) +// SW2 local echo +// SW3 received LF also does CR +// SW5:4 default text colour: 00 green, 01 yellow, 10 white, 11 cyan +// SW6 Backspace sends DEL (7F) instead of BS (08) +// SW7 Enter sends CR LF instead of CR +// SW8 smooth scrolling (also turned on by ESC [ ? 4 h) +// SW9 fast smooth scrolling +// SW14 in computer mode, link the PC's UART too: bytes from the PC also go to the +// computer, and the computer's output is copied to the PC +// SW15 computer mode +// BTNC reset BTNU clear screen BTND reset the computer only +// LED7:0 last byte received LED11:8 VT220 LEDs L4..L1 (DECLL) +// LED12 bell LED13 Caps Lock LED14 UART RX activity LED15 keyboard activity +// 7-seg last scan code (left), last byte sent (right); in computer mode, ports 21h/20h +// +// The terminal sends XOFF when its input buffer passes 256 bytes and XON when +// it drains below 32, so smooth scrolling can hold the host back. In computer mode +// it does the same for the computer's input buffer, for text pasted over the UART. + +module basys3_terminal #( + parameter FONT_FILE = "font.mem", + parameter MEM_FILE = "basic.mem", + parameter MEM_HI_FILE = "basic-hi.mem", + parameter MON_FILE = "monitor.mem", + parameter CLK_HZ = 100_000_000, + parameter real CPU_MULT = 9.0, // CPU clock = 100 MHz * CPU_MULT / CPU_DIV + parameter real CPU_DIV = 10.0, + parameter CPU_HZ = 90_000_000, + parameter ROM_TOP = 32'h0000_A000 // BASIC's code is below; writes there are ignored +) ( + input clk, + input btnC, + input btnU, + input btnD, + input [15:0] sw, + output [15:0] led, + output [6:0] seg, + output dp, + output [3:0] an, + output [3:0] vgaRed, + output [3:0] vgaGreen, + output [3:0] vgaBlue, + output Hsync, + output Vsync, + input RsRx, + output RsTx, + input PS2Clk, + input PS2Data, + output QspiCSn, + inout [3:0] QspiDB, + output [3:0] JA // PmodAMP2: audio in, gain, -, shutdown (low) +); + localparam [7:0] XON = 8'h11, XOFF = 8'h13; + + // ---------------------------------------------------------------- reset + reg [1:0] btn_sync; + reg [15:0] por = 16'd0; + reg rst = 1'b1; + always @(posedge clk) begin + btn_sync <= {btn_sync[0], btnC}; + if (btn_sync[1]) por <= 16'd0; + else if (!por[15]) por <= por + 1'b1; + rst <= !por[15]; + end + + reg [15:0] sw_r; + reg [1:0] clr_sync, zrst_sync; + always @(posedge clk) begin + sw_r <= sw; + clr_sync <= {clr_sync[0], btnU}; + zrst_sync <= {zrst_sync[0], btnD}; + end + wire rv_mode = sw_r[15]; + wire rv_link = sw_r[14]; + + reg [13:0] baud_div; + always @(posedge clk) + case (sw_r[1:0]) + 2'b00: baud_div <= CLK_HZ / 115200; + 2'b01: baud_div <= CLK_HZ / 9600; + 2'b10: baud_div <= CLK_HZ / 921600; // 108: 0.5% fast + 2'b11: baud_div <= CLK_HZ / 3000000; // 33: 1% fast + endcase + + reg [3:0] def_fg; + always @(posedge clk) + case (sw_r[5:4]) + 2'b00: def_fg <= 4'd10; // bright green + 2'b01: def_fg <= 4'd11; // yellow + 2'b10: def_fg <= 4'd7; // white + 2'b11: def_fg <= 4'd14; // bright cyan + endcase + + // ------------------------------------------------------------- keyboard + wire [7:0] scan; + wire scan_valid; + wire [7:0] key; + wire key_valid; + wire caps; + wire cursor_app, keypad_app, lnm; + + ps2_rx kbd_rx ( + .clk(clk), .rst(rst), .ps2_clk(PS2Clk), .ps2_data(PS2Data), + .code(scan), .valid(scan_valid) + ); + + wire cad; + ps2_keymap kbd_map ( + .clk(clk), .rst(rst), .code(scan), .code_valid(scan_valid), + .bs_del(sw_r[6]), .enter_crlf(sw_r[7] | lnm), + .cursor_app(cursor_app), .keypad_app(keypad_app), + .ascii(key), .ascii_valid(key_valid), .caps(caps), .cad(cad) + ); + + // keys held down, for the computer's game ports (nothing is held outside computer mode) + wire [255:0] keys_down; + ps2_keystate kbd_state ( + .clk(clk), .rst(rst | ~rv_mode), .code(scan), .code_valid(scan_valid), .down(keys_down) + ); + + // Ctrl-Alt-Del in computer mode restarts the computer, like BTND (held 1 us) + reg [6:0] cad_t = 7'd0; + always @(posedge clk) cad_t <= cad && rv_mode ? 7'd100 : cad_t - (cad_t != 0); + + // ----------------------------------------------------------- host input + // Keyboard bytes and terminal replies go to the host: the PC's UART, or in + // computer mode the computer's input FIFO. The keyboard/reply choice sticks until + // that queue is empty, so multi-byte sequences are never interleaved. + // Flow control bytes for the PC go first. + wire [7:0] kq, rq; + wire kq_empty, rq_empty, rq_full; + wire [7:0] resp_byte; + wire resp_wr; + wire tx_busy; + reg tx_start, kq_rd, rq_rd, from_resp; + reg [7:0] tx_byte; + reg flow_pend; + reg [7:0] flow_byte; + + fifo #(.W(8), .A(4)) key_fifo ( + .clk(clk), .rst(rst), .din(key), .wr(key_valid), + .rd(kq_rd), .dout(kq), .empty(kq_empty), .full(), .count() + ); + + fifo #(.W(8), .A(4)) resp_fifo ( + .clk(clk), .rst(rst), .din(resp_byte), .wr(resp_wr), + .rd(rq_rd), .dout(rq), .empty(rq_empty), .full(rq_full), .count() + ); + + wire [7:0] h_byte = from_resp ? rq : kq; + wire h_avail = from_resp ? !rq_empty : !kq_empty; + wire pop_pend = kq_rd | rq_rd; // last byte taken pops this clock + + // computer input FIFO: keyboard/replies, and the PC's UART when linked + wire [7:0] rx_byte; + wire rx_valid; + wire [7:0] zin; + wire zin_empty, zin_full; + wire [10:0] zin_count; + reg zin_rd; + wire rx_to_z = rv_mode && rv_link && rx_valid; + wire take_z = rv_mode && h_avail && !zin_full && !rx_to_z && !pop_pend; + + fifo #(.W(8), .A(10)) rv_in_fifo ( + .clk(clk), .rst(rst), .din(rx_to_z ? rx_byte : h_byte), .wr(rx_to_z || take_z), + .rd(zin_rd), .dout(zin), .empty(zin_empty), .full(zin_full), .count(zin_count) + ); + + // computer output copied to the PC when linked + wire [7:0] mq; + wire mq_empty; + wire [10:0] mq_count; + reg mq_rd; + wire rv_out; // a computer byte is going to the screen + wire [7:0] rv_out_byte; + + fifo #(.W(8), .A(10)) mirror_fifo ( + .clk(clk), .rst(rst), .din(rv_out_byte), .wr(rv_out && rv_link), + .rd(mq_rd), .dout(mq), .empty(mq_empty), .full(), .count(mq_count) + ); + + wire [10:0] tq_count; + wire [10:0] flow_count = rv_mode ? zin_count : tq_count; + reg xoff_sent; + + always @(posedge clk) begin + tx_start <= 1'b0; + kq_rd <= 1'b0; + rq_rd <= 1'b0; + mq_rd <= 1'b0; + if (rst) begin + from_resp <= 1'b0; + flow_pend <= 1'b0; + xoff_sent <= 1'b0; + end else begin + if (!flow_pend && !xoff_sent && flow_count >= 256) begin + flow_pend <= 1'b1; flow_byte <= XOFF; xoff_sent <= 1'b1; + end else if (!flow_pend && xoff_sent && flow_count < 32) begin + flow_pend <= 1'b1; flow_byte <= XON; xoff_sent <= 1'b0; + end + + if (take_z) begin + kq_rd <= !from_resp; + rq_rd <= from_resp; + end else if (!h_avail) + from_resp <= !from_resp; + + if (!tx_busy && !tx_start) begin + if (flow_pend) begin + tx_byte <= flow_byte; + tx_start <= 1'b1; + flow_pend <= 1'b0; + end else if (!rv_mode && h_avail && !pop_pend) begin + tx_byte <= h_byte; + tx_start <= 1'b1; + kq_rd <= !from_resp; + rq_rd <= from_resp; + end else if (rv_mode && !mq_empty && !mq_rd) begin + tx_byte <= mq; + tx_start <= 1'b1; + mq_rd <= 1'b1; + end + end + end + end + + uart_tx utx ( + .clk(clk), .rst(rst), .div(baud_div), .data(tx_byte), + .start(tx_start), .tx(RsTx), .busy(tx_busy) + ); + + // -------------------------------------------------------------- receive + uart_rx urx ( + .clk(clk), .rst(rst), .div(baud_div), .rx(RsRx), + .data(rx_byte), .valid(rx_valid) + ); + + // Start-up banner, fed in like received text. Bytes are read from the + // high end of the string; the unused high bytes are zero and skipped. + localparam [8*200-1:0] BANNER = { + "\033[1mBasys 3 VT220 Terminal\033[0m 80x32 ", + "\033[31mc\033[33mo\033[32ml\033[36mo\033[34mu\033[35mr\033[0m ", + "\033[4munderline\033[0m\015\012", + "UART RX -> screen, keyboard -> UART TX TERM=basys3 or vt220\015\012\012"}; + // (not shown in computer mode, where BASIC prints its own) + reg [7:0] ban_i; + wire [7:0] ban_c = BANNER[ban_i*8 +: 8]; + + // ---------------------------------------------------------------- RISC-V + wire cpu_clk, locked; +`ifdef SIMULATION + assign cpu_clk = clk; + assign locked = 1'b1; +`else + wire cpu_fb, cpu_clk_mmcm; + MMCME2_BASE #( + .CLKIN1_PERIOD(10.0), .DIVCLK_DIVIDE(1), + .CLKFBOUT_MULT_F(CPU_MULT), .CLKOUT0_DIVIDE_F(CPU_DIV) + ) cpu_mmcm ( + .CLKIN1(clk), .CLKFBIN(cpu_fb), .CLKFBOUT(cpu_fb), .CLKFBOUTB(), + .CLKOUT0(cpu_clk_mmcm), .CLKOUT0B(), .CLKOUT1(), .CLKOUT1B(), .CLKOUT2(), + .CLKOUT2B(), .CLKOUT3(), .CLKOUT3B(), .CLKOUT4(), .CLKOUT5(), .CLKOUT6(), + .LOCKED(locked), .PWRDWN(1'b0), .RST(1'b0) + ); + BUFG cpu_bufg (.I(cpu_clk_mmcm), .O(cpu_clk)); +`endif + + // ------------------------------------------------- pixel clock, 108 MHz + // 1280x1024 at 60 Hz: 100 MHz x 10.125 / 9.375 + wire pix_clk; +`ifdef SIMULATION + assign pix_clk = clk; +`else + wire pix_fb, pix_clk_mmcm; + MMCME2_BASE #( + .CLKIN1_PERIOD(10.0), .DIVCLK_DIVIDE(1), + .CLKFBOUT_MULT_F(10.125), .CLKOUT0_DIVIDE_F(9.375) + ) pix_mmcm ( + .CLKIN1(clk), .CLKFBIN(pix_fb), .CLKFBOUT(pix_fb), .CLKFBOUTB(), + .CLKOUT0(pix_clk_mmcm), .CLKOUT0B(), .CLKOUT1(), .CLKOUT1B(), .CLKOUT2(), + .CLKOUT2B(), .CLKOUT3(), .CLKOUT3B(), .CLKOUT4(), .CLKOUT5(), .CLKOUT6(), + .LOCKED(), .PWRDWN(1'b0), .RST(1'b0) + ); + BUFG pix_bufg (.I(pix_clk_mmcm), .O(pix_clk)); +`endif + (* ASYNC_REG = "TRUE" *) reg [1:0] pix_rst_s; + always @(posedge pix_clk) pix_rst_s <= {pix_rst_s[0], rst}; + + (* ASYNC_REG = "TRUE" *) reg [2:0] cpu_rst_s; + always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | (cad_t != 0) | !locked}; + + // computer input: one byte at a time from rv_in_fifo + reg zrx_req, zrx_pend; + reg [7:0] zrx_data; + wire zrx_ack; + (* ASYNC_REG = "TRUE" *) reg [1:0] zrx_ack_s; + always @(posedge clk) begin + zin_rd <= 1'b0; + zrx_ack_s <= {zrx_ack_s[0], zrx_ack}; + if (rst) + zrx_pend <= 1'b0; + else if (!zrx_pend && !zin_empty && !zin_rd) begin + zrx_data <= zin; + zin_rd <= 1'b1; + zrx_req <= ~zrx_req; + zrx_pend <= 1'b1; + end else if (zrx_pend && zrx_ack_s[1] == zrx_req) + zrx_pend <= 1'b0; + end + initial zrx_req = 1'b0; + + // computer output + wire ztx_req; + wire [7:0] ztx_data; + reg ztx_ack = 1'b0; + (* ASYNC_REG = "TRUE" *) reg [1:0] ztx_req_s; + always @(posedge clk) ztx_req_s <= {ztx_req_s[0], ztx_req}; + + wire [15:0] rv_seg; + wire fl_sck; + wire [16:0] gfx_addr; + wire [3:0] gfx_pix; + wire sp_go, sp_buf, sp_on, pix_frame; + wire [8:0] scroll_x; + wire [7:0] scroll_y; + wire g_border; + wire [7:0] sp_line; + wire [8:0] sp_x; + wire [3:0] sp_pix; + + // The Pause key (its scan codes start E1, used by nothing else) enters the + // monitor: a toggle crosses to the CPU clock. + reg brk_t = 1'b0; + always @(posedge clk) if (scan_valid && scan == 8'hE1 && rv_mode) brk_t <= ~brk_t; + (* ASYNC_REG = "TRUE" *) reg [2:0] brk_s = 3'd0; + always @(posedge cpu_clk) brk_s <= {brk_s[1:0], brk_t}; + + rv32_system #(.MEM_FILE(MEM_FILE), .MEM_HI_FILE(MEM_HI_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ), .ROM_TOP(ROM_TOP)) sys ( + .clk(cpu_clk), .rst(cpu_rst_s[2]), + .rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack), + .tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack), + .seg_val(rv_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]), + .vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix), + .scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border), + .sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on), + .sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down), + .fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1]), + .audio(JA[0]) + ); + + // PmodAMP2 on JA's top row: gain high is 6 dB (low would be 12 dB), and + // the amplifier is on unless its shutdown pin is low. + assign JA[3:1] = 3'b101; + + // The flash clock is the configuration clock pin, reached through STARTUPE2. + // DQ2/DQ3 (write protect, hold) stay high. + assign QspiDB[1] = 1'bz; + assign QspiDB[3:2] = 2'b11; +`ifndef SIMULATION + STARTUPE2 #(.PROG_USR("FALSE"), .SIM_CCLK_FREQ(0.0)) startup ( + .CFGCLK(), .CFGMCLK(), .EOS(), .PREQ(), + .CLK(1'b0), .GSR(1'b0), .GTS(1'b0), .KEYCLEARB(1'b1), .PACK(1'b0), + .USRCCLKO(fl_sck), .USRCCLKTS(1'b0), .USRDONEO(1'b1), .USRDONETS(1'b1) + ); +`endif + + // terminal input: computer output or received bytes, local echo, banner + reg echo_pend; + reg [7:0] echo_byte; + reg [7:0] tin; + reg tin_wr; + wire tin_full; + + assign rv_out = rv_mode && ztx_req_s[1] != ztx_ack && !tin_wr && tq_count < 1000 && + (!rv_link || mq_count < 1000); + assign rv_out_byte = ztx_data; + + always @(posedge clk) begin + tin_wr <= 1'b0; + if (kq_rd && sw_r[2] && !rv_mode) begin + echo_pend <= 1'b1; + echo_byte <= kq; + end + if (rst) begin + echo_pend <= 1'b0; + ban_i <= rv_mode ? 8'hFF : 8'd199; + end else if (rv_mode) begin + if (rv_out) begin + tin <= ztx_data; + tin_wr <= 1'b1; + ztx_ack <= ~ztx_ack; + end + end else if (rx_valid) begin + tin <= rx_byte; + tin_wr <= 1'b1; + end else if (echo_pend && !tin_full) begin + tin <= echo_byte; + tin_wr <= 1'b1; + echo_pend <= kq_rd && sw_r[2] && !rv_mode; + end else if (ban_i != 8'hFF && !tin_full && !tin_wr) begin + ban_i <= ban_i - 1'b1; + if (ban_c != 0) begin + tin <= ban_c; + tin_wr <= 1'b1; + end + end + end + + wire [7:0] tq; + wire tq_empty; + wire tq_rd; + + fifo #(.W(8), .A(10)) term_fifo ( + .clk(clk), .rst(rst), .din(tin), .wr(tin_wr), + .rd(tq_rd), .dout(tq), .empty(tq_empty), .full(tin_full), .count(tq_count) + ); + + // ------------------------------------------------------------- terminal + wire [13:0] t_addr; + wire alt_scr, wide; + wire t_we; + wire [17:0] t_wdata, t_rdata; + wire [5:0] cur_row, stop, sbot; + wire [4:0] sm_off; + wire [7:0] cur_col; + wire cur_vis, sm_on, sm_dir; + wire [3:0] dec_leds; + wire bell; + wire frame_tick; + + // start of vertical blanking, from the pixel clock to this one + reg frame_t = 1'b0; + always @(posedge pix_clk) if (pix_frame) frame_t <= ~frame_t; + (* ASYNC_REG = "TRUE" *) reg [2:0] frame_s = 3'd0; + always @(posedge clk) frame_s <= {frame_s[1:0], frame_t}; + assign frame_tick = frame_s[2] ^ frame_s[1]; + + term_ctrl term ( + .clk(clk), .rst(rst), .in_byte(tq), .in_empty(tq_empty), .in_rd(tq_rd), + .lf_cr(sw_r[3]), .clear_req(clr_sync[1]), .def_fg(def_fg), + .smooth_sw(sw_r[8]), .smooth_fast(sw_r[9]), .frame_tick(frame_tick), + .addr(t_addr), .we(t_we), .wdata(t_wdata), .rdata(t_rdata), + .row(cur_row), .col(cur_col), .cur_vis(cur_vis), + .stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off), + .resp_byte(resp_byte), .resp_wr(resp_wr), .resp_full(rq_full), + .cursor_app(cursor_app), .keypad_app(keypad_app), .lnm(lnm), + .dec_leds(dec_leds), .bell(bell), .alt_scr(alt_scr), .wide(wide) + ); + + wire [13:0] v_addr; + wire [17:0] v_data; + + // The display reads the terminal's cursor and modes across clocks: they + // change rarely and a stale value lasts one pixel. + // The alternate screen (the monitor uses it) has no graphics layer. + char_ram screen ( + .clk(clk), .a_alt(alt_scr), + .a_addr(t_addr), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata), + .vclk(pix_clk), .b_alt(alt_scr), .b_addr(v_addr), .b_rdata(v_data) + ); + + text_display #(.FONT_FILE(FONT_FILE)) video ( + .clk(pix_clk), .rst(pix_rst_s[1]), .wide(wide), + .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis), + .stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off), + .ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(alt_scr ? 4'd0 : gfx_pix), + .scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border), + .sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on), + .sp_pix(alt_scr ? 4'd0 : sp_pix), + .red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync), + .frame_tick(pix_frame) + ); + + // ----------------------------------------------------- status displays + reg [7:0] last_rx; + reg [7:0] last_scan; + reg [7:0] last_tx; + reg [22:0] rx_led, kb_led, bell_led; // ~84 ms pulse stretchers + + always @(posedge clk) begin + if (rv_mode ? tin_wr : rx_valid) last_rx <= rv_mode ? tin : rx_byte; + if (scan_valid) last_scan <= scan; + if (tx_start) last_tx <= tx_byte; + rx_led <= (rv_mode ? tin_wr : rx_valid) ? 23'h7FFFFF : rx_led - (rx_led != 0); + kb_led <= scan_valid ? 23'h7FFFFF : kb_led - (kb_led != 0); + bell_led <= bell ? 23'h7FFFFF : bell_led - (bell_led != 0); + end + + assign led = {kb_led != 0, rx_led != 0, caps, bell_led != 0, dec_leds[3:0], last_rx}; + assign dp = 1'b1; + + sevenseg digits (.clk(clk), .value(rv_mode ? rv_seg : {last_scan, last_tx}), + .seg(seg), .an(an)); +endmodule diff --git a/rtl/fifo.v b/rtl/fifo.v new file mode 100644 index 0000000..6ec8cd5 --- /dev/null +++ b/rtl/fifo.v @@ -0,0 +1,38 @@ +`timescale 1ns / 1ps + +// Small synchronous first-word-fall-through FIFO (dout is valid while !empty). +module fifo #( + parameter W = 8, + parameter A = 4 // depth = 2**A +) ( + input clk, + input rst, + input [W-1:0] din, + input wr, + input rd, + output [W-1:0] dout, + output empty, + output full, + output [A:0] count +); + reg [W-1:0] mem [0:(1<= "a" && km[15:8] <= "z"; + wire [7:0] ch = (letter ? shift ^ caps : shift) ? km[7:0] : km[15:8]; + wire [7:0] ckey = cursor_app ? "O" : "["; + wire [7:0] kpa = kp_app(code); + + // bytes a key press produces, first byte in k_seq[47:40] + reg [2:0] k_len; + reg [47:0] k_seq; + always @* begin + k_len = 3'd0; + k_seq = 48'd0; + if (e0) case (code) + 8'h75: {k_len, k_seq} = {3'd3, ESC, ckey, "A", 24'd0}; // up + 8'h72: {k_len, k_seq} = {3'd3, ESC, ckey, "B", 24'd0}; // down + 8'h74: {k_len, k_seq} = {3'd3, ESC, ckey, "C", 24'd0}; // right + 8'h6B: {k_len, k_seq} = {3'd3, ESC, ckey, "D", 24'd0}; // left + 8'h6C: {k_len, k_seq} = {3'd4, ESC, "[1~", 16'd0}; // home (Find) + 8'h70: {k_len, k_seq} = {3'd4, ESC, "[2~", 16'd0}; // insert + 8'h71: {k_len, k_seq} = {3'd4, ESC, "[3~", 16'd0}; // delete (Remove) + 8'h69: {k_len, k_seq} = {3'd4, ESC, "[4~", 16'd0}; // end (Select) + 8'h7D: {k_len, k_seq} = {3'd4, ESC, "[5~", 16'd0}; // page up + 8'h7A: {k_len, k_seq} = {3'd4, ESC, "[6~", 16'd0}; // page down + 8'h4A: {k_len, k_seq} = keypad_app ? {3'd3, ESC, "Oo", 24'd0} : {3'd1, "/", 40'd0}; + 8'h5A: {k_len, k_seq} = keypad_app ? {3'd3, ESC, "OM", 24'd0} : + enter_crlf ? {3'd2, 8'h0D, 8'h0A, 32'd0} : {3'd1, 8'h0D, 40'd0}; + default: ; + endcase + else case (code) + 8'h66: {k_len, k_seq} = {3'd1, bs_del ? 8'h7F : 8'h08, 40'd0}; + 8'h5A: {k_len, k_seq} = enter_crlf ? {3'd2, 8'h0D, 8'h0A, 32'd0} : {3'd1, 8'h0D, 40'd0}; + 8'h05: {k_len, k_seq} = {3'd3, ESC, "OP", 24'd0}; // F1 + 8'h06: {k_len, k_seq} = {3'd3, ESC, "OQ", 24'd0}; // F2 + 8'h04: {k_len, k_seq} = {3'd3, ESC, "OR", 24'd0}; // F3 + 8'h0C: {k_len, k_seq} = {3'd3, ESC, "OS", 24'd0}; // F4 + 8'h03: {k_len, k_seq} = {3'd5, ESC, "[15~", 8'd0}; // F5 + 8'h0B: {k_len, k_seq} = {3'd5, ESC, "[17~", 8'd0}; // F6 + 8'h83: {k_len, k_seq} = {3'd5, ESC, "[18~", 8'd0}; // F7 + 8'h0A: {k_len, k_seq} = {3'd5, ESC, "[19~", 8'd0}; // F8 + 8'h01: {k_len, k_seq} = {3'd5, ESC, "[20~", 8'd0}; // F9 + 8'h09: {k_len, k_seq} = {3'd5, ESC, "[21~", 8'd0}; // F10 + 8'h78: {k_len, k_seq} = {3'd5, ESC, "[23~", 8'd0}; // F11 + 8'h07: {k_len, k_seq} = {3'd5, ESC, "[24~", 8'd0}; // F12 + default: + if (keypad_app && kpa != 0) + {k_len, k_seq} = {3'd3, ESC, "O", kpa, 24'd0}; + else if (ch != 0) begin + k_len = 3'd1; + if (!ctrl) k_seq[47:40] = ch; + else if (ch == " ") k_seq[47:40] = 8'h00; + else if (ch >= 8'h40) k_seq[47:40] = ch & 8'h1F; // ^A..^Z, ^[ ^\ ^] ^^ ^_ + else k_seq[47:40] = ch; + end + endcase + end + + always @(posedge clk) begin + ascii_valid <= 1'b0; + cad <= 1'b0; + if (rst) begin + {e0, f0, lsh, rsh, lct, rct, alt, caps} <= 8'd0; + skip <= 3'd0; + cnt <= 3'd0; + end else begin + if (cnt != 0) begin + ascii <= sq[47:40]; + ascii_valid <= 1'b1; + sq <= sq << 8; + cnt <= cnt - 1'b1; + end + if (code_valid) begin + if (skip != 0) + skip <= skip - 1'b1; + else if (code == 8'hE1) + skip <= 3'd7; // Pause: E1 14 77 E1 F0 14 F0 77 + else if (code == 8'hE0) + e0 <= 1'b1; + else if (code == 8'hF0) + f0 <= 1'b1; + else begin + e0 <= 1'b0; + f0 <= 1'b0; + cad <= !f0 && code == 8'h71 && (lct || rct) && alt; // Delete or keypad . + if (code == 8'h12 && !e0) lsh <= !f0; // E0 12 / E0 59 are fake shifts + else if (code == 8'h59 && !e0) rsh <= !f0; + else if (code == 8'h14) begin + if (e0) rct <= !f0; else lct <= !f0; + end else if (code == 8'h11) + alt <= !f0; + else if (code == 8'h58 && !e0) begin + if (!f0) caps <= !caps; + end else if (!f0 && k_len != 0) begin + if (alt && k_len != 3'd6) begin + sq <= {ESC, k_seq[47:8]}; + cnt <= k_len + 1'b1; + end else begin + sq <= k_seq; + cnt <= k_len; + end + end + end + end + end + end +endmodule + +// Which keys are held down, for games: one bit per set-2 scan code, 128 plain +// codes ({0, code}) and 128 after the E0 prefix ({1, code}). The Pause key's +// E1 sequence is skipped. +module ps2_keystate ( + input clk, + input rst, + input [7:0] code, + input code_valid, + output reg [255:0] down +); + reg ext, brk, pause; + reg [2:0] skip; + always @(posedge clk) + if (rst) begin + down <= 256'd0; + ext <= 1'b0; brk <= 1'b0; skip <= 3'd0; + end else if (code_valid) begin + if (skip != 3'd0) skip <= skip - 1'b1; // rest of E1 14 77 E1 F0 14 F0 77 + else if (code == 8'hE1) skip <= 3'd7; + else if (code == 8'hE0) ext <= 1'b1; + else if (code == 8'hF0) brk <= 1'b1; + else begin + if (!code[7]) down[{ext, code[6:0]}] <= !brk; + ext <= 1'b0; + brk <= 1'b0; + end + end +endmodule diff --git a/rtl/rv32_cpu.v b/rtl/rv32_cpu.v new file mode 100644 index 0000000..5e4d5be --- /dev/null +++ b/rtl/rv32_cpu.v @@ -0,0 +1,551 @@ +`timescale 1ns / 1ps + +// RV32IM processor, machine mode only. +// +// A multi-cycle core with one instruction in flight. Each instruction is +// decoded in one cycle (D) and executed in the next (E); the decode cycle +// fetches the following word, so straight-line code takes 2 clocks per +// instruction. Taken branches and jumps take 3, loads and stores 3 (more if +// the bus waits), multiplies 4 and divides 35. +// +// Instruction port: synchronous read. i_rdata is the word at the i_addr given +// in the last cycle with i_en high, and must hold while i_en is low. +// +// Data port: d_req is high for one cycle with d_addr, d_we, d_wstrb and +// d_wdata; the bus answers with d_ack (and d_rdata for a read) one or more +// cycles later. d_addr is word-aligned for words, halfword-aligned for +// halfwords (misaligned accesses trap); d_rdata is the whole word. +// d_addr and d_wdata come early in the cycle (an adder from registers), but +// d_req comes late (after the alignment and breakpoint checks): register it, +// and the store, before it reaches block RAM write enables. A read with no +// request is harmless for RAM, so RAM can be read from d_addr every cycle. +// +// Exceptions that depend on the branch comparison or the load/store address +// (a taken branch to a misaligned target, a misaligned load/store, a load/store +// breakpoint) are raised one cycle late, from registers, to keep the long +// paths out of the trap logic; the instruction has no effect either way. +// +// Speed: 90 MHz with 1.5 ns to spare on the XC7A35T-1 (bench/), about 2100 +// LUTs, 900 flip-flops and 4 DSP slices. +// +// Implemented: RV32I, M, Zicsr, Zicntr (cycle, time = cycle, instret), Zifencei, +// mret and wfi (a no-op). Machine-mode CSRs: mstatus (MIE, MPIE; MPP reads 3), +// misa, mie, mip, mtvec (direct mode), mscratch, mepc, mcause, mtval, mcycle, +// minstret, mhartid etc. (read 0), and two Sdtrig match triggers (tselect, +// tdata1, tdata2, tinfo, tcontrol) for execute, load and store address +// breakpoints. Triggers fire while tcontrol.MTE is set; a trap clears it +// (saving it in MPTE) and mret restores it. +// +// Resumable NMI (after the Smrnmi extension, for a debug monitor): while +// mnstatus.NMIE is set, `nmi` (checked as each instruction starts; it may come +// straight from comparators on dbg_pc) or `nmi_step` (after one instruction +// has completed with NMIE set) saves the pc in mnepc, clears NMIE and jumps to +// NMI_VEC; mnret goes back and sets NMIE again. nmi_taken pulses as it is +// taken. Unlike Smrnmi, NMIE resets to 1, software may clear it, and traps +// still go to mtvec while it is clear. CSRs: mnscratch, mnepc, mncause, mnstatus. +// +// Interrupts: mip.MSIP (irq_soft), MTIP (irq_timer), MEIP (irq_ext) and local +// interrupts 16-31 (irq_local), all level-sensitive. Priority: external, +// software, timer, then local 16 upward. +module rv32_cpu #( + parameter [31:0] RESET_PC = 32'h0000_0000, + parameter [31:0] NMI_VEC = 32'h0000_0000 +) ( + input clk, + input rst, // synchronous + output i_en, + output [31:0] i_addr, + input [31:0] i_rdata, + output d_req, + output d_we, + output [3:0] d_wstrb, + output [31:0] d_addr, + output [31:0] d_wdata, + input [31:0] d_rdata, + input d_ack, + input irq_soft, + input irq_timer, + input irq_ext, + input [15:0] irq_local, + input nmi, + input nmi_step, + output reg nmi_taken, + output [31:0] dbg_pc, // address of the instruction being run + output dbg_decode, // high in an instruction's first cycle + output reg retire // pulse: an instruction completed +); + localparam S_IF = 3'd0, S_D = 3'd1, S_E = 3'd2, S_MEM = 3'd3, + S_MUL = 3'd4, S_DIV = 3'd5, S_DIVF = 3'd6, S_XT = 3'd7; + reg [2:0] state; + reg [31:0] pc; + + assign i_en = state == S_IF || state == S_D; + assign i_addr = state == S_D ? pc + 32'd4 : pc; + assign dbg_pc = pc; + assign dbg_decode = state == S_D; + + // ------------------------------------------------------------------ + // Registers: distributed RAM, two asynchronous read ports. + reg [31:0] rf [0:31]; + integer k; + initial for (k = 0; k < 32; k = k + 1) rf[k] = 32'd0; + reg rf_we; + reg [4:0] rf_wa; + reg [31:0] rf_wd; + always @(posedge clk) if (rf_we && rf_wa != 5'd0) rf[rf_wa] <= rf_wd; + + // ------------------------------------------------------------------ + // Decode (state D): inst is the fetched word. + wire [31:0] inst = i_rdata; + wire [6:0] opc = inst[6:0]; + wire [2:0] f3 = inst[14:12]; + wire [6:0] f7 = inst[31:25]; + wire [4:0] rs1 = inst[19:15], rs2 = inst[24:20]; + wire [31:0] rv1 = rs1 == 5'd0 ? 32'd0 : rf[rs1]; + wire [31:0] rv2 = rs2 == 5'd0 ? 32'd0 : rf[rs2]; + + wire [31:0] imm_i = {{20{inst[31]}}, inst[31:20]}; + wire [31:0] imm_s = {{20{inst[31]}}, inst[31:25], inst[11:7]}; + wire [31:0] imm_b = {{20{inst[31]}}, inst[7], inst[30:25], inst[11:8], 1'b0}; + wire [31:0] imm_u = {inst[31:12], 12'd0}; + wire [31:0] imm_j = {{12{inst[31]}}, inst[19:12], inst[20], inst[30:21], 1'b0}; + + wire is_lui = opc == 7'b0110111; + wire is_auipc = opc == 7'b0010111; + wire is_jal = opc == 7'b1101111; + wire is_jalr = opc == 7'b1100111 && f3 == 3'd0; + wire is_br = opc == 7'b1100011 && f3[2:1] != 2'b01; + wire is_ld = opc == 7'b0000011 && (f3 == 3'd0 || f3 == 3'd1 || f3 == 3'd2 || + f3 == 3'd4 || f3 == 3'd5); + wire is_st = opc == 7'b0100011 && f3[2] == 1'b0 && f3[1:0] != 2'b11; + wire is_opi = opc == 7'b0010011 && + (f3 == 3'd1 ? f7 == 7'd0 : + f3 == 3'd5 ? (f7 == 7'd0 || f7 == 7'b0100000) : 1'b1); + wire is_op = opc == 7'b0110011 && + (f7 == 7'd0 || (f7 == 7'b0100000 && (f3 == 3'd0 || f3 == 3'd5))); + wire is_mdv = opc == 7'b0110011 && f7 == 7'b0000001; + wire is_fence = opc == 7'b0001111 && f3 == 3'd0; + wire is_fencei= opc == 7'b0001111 && f3 == 3'd1; + wire is_sys = opc == 7'b1110011; + wire is_csr = is_sys && f3[1:0] != 2'b00; + wire is_ecall = inst == 32'h0000_0073; + wire is_ebrk = inst == 32'h0010_0073; + wire is_mret = inst == 32'h3020_0073; + wire is_wfi = inst == 32'h1050_0073; + wire is_mnret = inst == 32'h7020_0073; + wire legal = is_lui | is_auipc | is_jal | is_jalr | is_br | is_ld | is_st | + is_opi | is_op | is_mdv | is_fence | is_fencei | is_csr | + is_ecall | is_ebrk | is_mret | is_wfi | is_mnret; + + // ------------------------------------------------------------------ + // Execute-stage registers, loaded at the end of D. + reg [31:0] ir; // the instruction + reg [31:0] a, b; // ALU operands + reg [31:0] sv; // store data / rs2 + reg [31:0] tgt; // branch or jal target + reg [31:0] pc4; + reg e_tmis; // branch / jal target is misaligned + reg x_trap; // the deferred trap, below + reg [31:0] x_cause, x_val; + reg e_alu, e_sub, e_jal, e_jalr, e_br, e_ld, e_st, e_mul, e_div, + e_csr, e_ecall, e_ebrk, e_mret, e_mnret, e_fencei, e_ill; + wire [2:0] e_f3 = ir[14:12]; + wire [4:0] e_rd = ir[11:7]; + reg [2:0] alu_fn; + reg alu_alt; // sra rather than srl + + // multiplier (DSP), fed straight from decode + reg signed [32:0] m_a, m_b; + reg signed [65:0] m_p, m_p2; + reg m_hi, m_cnt; + always @(posedge clk) begin + m_p <= m_a * m_b; + m_p2 <= m_p; + end + + // ------------------------------------------------------------------ + // Execute (state E) + wire [31:0] sum = a + b; + wire eq = a == b; + wire lt = $signed(a) < $signed(b); + wire ltu = a < b; + wire [31:0] sra_out = $signed(a) >>> b[4:0]; + reg [31:0] alu_out; + always @* begin + case (alu_fn) + 3'd0: alu_out = e_sub ? a - b : sum; + 3'd1: alu_out = a << b[4:0]; + 3'd2: alu_out = {31'd0, lt}; + 3'd3: alu_out = {31'd0, ltu}; + 3'd4: alu_out = a ^ b; + 3'd5: alu_out = alu_alt ? sra_out : a >> b[4:0]; + 3'd6: alu_out = a | b; + default: alu_out = a & b; + endcase + end + reg taken; + always @* begin + case (e_f3) + 3'd0: taken = eq; + 3'd1: taken = !eq; + 3'd4: taken = lt; + 3'd5: taken = !lt; + 3'd6: taken = ltu; + default: taken = !ltu; + endcase + end + wire [31:0] jtarget = e_jalr ? {sum[31:1], 1'b0} : tgt; + wire jump = e_jal | e_jalr | (e_br & taken); + + // loads and stores + wire [1:0] sz = e_f3[1:0]; + wire [1:0] lo = a[1:0] + b[1:0]; + wire mis = (sz == 2'd1 && lo[0]) || (sz == 2'd2 && lo != 2'd0); + + // ------------------------------------------------------------------ + // CSRs + reg mie_b, mpie_b; // mstatus + reg [31:0] mie_r, mtvec, mscratch, mepc, mcause, mtval; + reg [63:0] mcycle, minstret; + reg tsel, mte, mpte; + reg nmie, stepped; + reg [31:0] mnscratch, mnepc, mncause; + reg [1:0] t_m, t_x, t_s, t_l; + reg [31:0] t_a0, t_a1; + reg [31:0] irq_r; + localparam [31:0] MIE_MASK = 32'hFFFF_0888; + + wire [11:0] csr_a = ir[31:20]; + reg [31:0] csr_rd; + reg csr_ok; + always @* begin + csr_ok = 1'b1; + case (csr_a) + 12'h300: csr_rd = {19'd0, 2'b11, 3'd0, mpie_b, 3'd0, mie_b, 3'd0}; + 12'h301: csr_rd = 32'h4000_1100; // RV32 I M + 12'h304: csr_rd = mie_r; + 12'h305: csr_rd = mtvec; + 12'h310: csr_rd = 32'd0; // mstatush + 12'h340: csr_rd = mscratch; + 12'h341: csr_rd = mepc; + 12'h342: csr_rd = mcause; + 12'h343: csr_rd = mtval; + 12'h344: csr_rd = irq_r; + 12'h740: csr_rd = mnscratch; + 12'h741: csr_rd = mnepc; + 12'h742: csr_rd = mncause; + 12'h744: csr_rd = {19'd0, 2'b11, 7'd0, nmie, 3'd0}; + 12'h7A0: csr_rd = {31'd0, tsel}; + 12'h7A1: csr_rd = {4'd2, 21'd0, t_m[tsel], 3'd0, t_x[tsel], t_s[tsel], t_l[tsel]}; + 12'h7A2: csr_rd = tsel ? t_a1 : t_a0; + 12'h7A4: csr_rd = 32'h0000_0004; // tinfo: match triggers + 12'h7A5: csr_rd = {24'd0, mpte, 3'd0, mte, 3'd0}; + 12'hB00, 12'hC00, 12'hC01: csr_rd = mcycle[31:0]; + 12'hB80, 12'hC80, 12'hC81: csr_rd = mcycle[63:32]; + 12'hB02, 12'hC02: csr_rd = minstret[31:0]; + 12'hB82, 12'hC82: csr_rd = minstret[63:32]; + 12'hF11, 12'hF12, 12'hF13, 12'hF14, 12'hF15: csr_rd = 32'd0; + default: begin csr_rd = 32'd0; csr_ok = 1'b0; end + endcase + end + wire csr_imm = e_f3[2]; + wire [31:0] csr_src = csr_imm ? {27'd0, ir[19:15]} : a; + wire csr_wr = e_f3[1:0] == 2'b01 || ir[19:15] != 5'd0; + wire [31:0] csr_wv = e_f3[1:0] == 2'b01 ? csr_src : + e_f3[1:0] == 2'b10 ? csr_rd | csr_src : csr_rd & ~csr_src; + wire csr_bad = !csr_ok || (csr_wr && csr_a[11:10] == 2'b11); + wire csr_go = state == S_E && e_csr && !csr_bad && csr_wr; + + // triggers + wire fire_x = mte && ((t_m[0] && t_x[0] && pc == t_a0) || (t_m[1] && t_x[1] && pc == t_a1)); + // a + b == k without waiting for the carries: bit i of the sum matches k + // exactly when the carry into it is x[i] = a^b^k, and that carry is the + // majority of a, b and x one bit down (and 0 into bit 0). + function addeq(input [31:0] a, input [31:0] b, input [31:0] k); + reg [31:0] x, c; + begin + x = a ^ b ^ k; + c = (a & b) | (a & x) | (b & x); + addeq = !x[0] && x[31:1] == c[30:0]; + end + endfunction + wire hit0 = addeq(a, b, t_a0), hit1 = addeq(a, b, t_a1); + wire fire_l = mte && ((t_m[0] && t_l[0] && hit0) || (t_m[1] && t_l[1] && hit1)); + wire fire_s = mte && ((t_m[0] && t_s[0] && hit0) || (t_m[1] && t_s[1] && hit1)); + + // interrupts + wire [31:0] pend = irq_r & mie_r; + wire irq_take = mie_b && pend != 32'd0; + reg [4:0] irq_code; + integer j; + always @* begin + irq_code = 5'd16; + for (j = 31; j >= 16; j = j - 1) if (pend[j]) irq_code = j[4:0]; + if (pend[7]) irq_code = 5'd7; + if (pend[3]) irq_code = 5'd3; + if (pend[11]) irq_code = 5'd11; + end + + // ------------------------------------------------------------------ + // Data bus + wire ls_bad = (e_ld && fire_l) || (e_st && fire_s) || mis; + wire mem_go = state == S_E && (e_ld || e_st) && !ls_bad; + assign d_req = mem_go; + assign d_we = e_st; + assign d_addr = sum; + assign d_wstrb = sz == 2'd0 ? 4'b0001 << sum[1:0] : + sz == 2'd1 ? (sum[1] ? 4'b1100 : 4'b0011) : 4'b1111; + assign d_wdata = sz == 2'd0 ? {4{sv[7:0]}} : sz == 2'd1 ? {2{sv[15:0]}} : sv; + reg [1:0] la; // address bits of the load + wire [31:0] lw_sh = d_rdata >> {la, 3'b000}; + wire [31:0] ld_val = e_f3 == 3'd0 ? {{24{lw_sh[7]}}, lw_sh[7:0]} : + e_f3 == 3'd1 ? {{16{lw_sh[15]}}, lw_sh[15:0]} : + e_f3 == 3'd4 ? {24'd0, lw_sh[7:0]} : + e_f3 == 3'd5 ? {16'd0, lw_sh[15:0]} : d_rdata; + + // divider + reg [31:0] dq, dr, dd, da; + reg [5:0] dcnt; + reg dneg_q, dneg_r, dzero; + wire [32:0] dtmp = {dr, dq[31]}; + wire [33:0] dsub = {1'b0, dtmp} - {2'b0, dd}; + + // ------------------------------------------------------------------ + // Traps + wire nmi_go = state == S_D && nmie && (nmi || (nmi_step && stepped)); + reg trap; + reg [31:0] t_cause, t_val; + always @* begin + trap = 1'b0; t_cause = 32'd0; t_val = 32'd0; + if (state == S_D) begin + if (nmi_go) begin + trap = 1'b1; // to NMI_VEC; see below + end else if (irq_take) begin + trap = 1'b1; t_cause = {1'b1, 26'd0, irq_code}; + end else if (fire_x) begin + trap = 1'b1; t_cause = 32'd3; t_val = pc; + end + end else if (state == S_XT) begin + // Traps that depend on the branch comparison or the load/store + // address are taken a cycle late, from registers, to keep those + // long paths out of the trap logic: a taken branch to a misaligned + // target, a load/store breakpoint, a misaligned load/store. + if (x_trap) begin + trap = 1'b1; t_cause = x_cause; t_val = x_val; + end + end else if (state == S_E) begin + if (e_ill || (e_csr && csr_bad)) begin + trap = 1'b1; t_cause = 32'd2; t_val = ir; + end else if ((e_jal && e_tmis) || (e_jalr && lo[1])) begin + trap = 1'b1; t_cause = 32'd0; t_val = jtarget; + end else if (e_ecall) begin + trap = 1'b1; t_cause = 32'd11; + end else if (e_ebrk) begin + trap = 1'b1; t_cause = 32'd3; t_val = pc; + end + end + end + + // ------------------------------------------------------------------ + // Register write-back + always @* begin + rf_we = 1'b0; rf_wa = e_rd; rf_wd = alu_out; + case (state) + S_E: begin + rf_we = !trap && (e_alu || e_jal || e_jalr || e_csr); + rf_wd = e_csr ? csr_rd : (e_jal || e_jalr) ? pc4 : alu_out; + end + S_MEM: begin rf_we = d_ack && e_ld; rf_wd = ld_val; end + S_MUL: begin rf_we = m_cnt; rf_wd = m_hi ? m_p2[63:32] : m_p2[31:0]; end + S_DIVF: begin + rf_we = 1'b1; + if (e_f3[1]) // rem, remu + rf_wd = dzero ? da : dneg_r ? -dr : dr; + else + rf_wd = dzero ? 32'hFFFF_FFFF : dneg_q ? -dq : dq; + end + default: ; + endcase + end + + // an instruction completes (counted by instret unless it writes instret) + reg count_i; + wire done = (state == S_E && !trap && !e_ld && !e_st && !e_mul && !e_div) || + (state == S_MEM && d_ack) || (state == S_MUL && m_cnt) || + state == S_DIVF || (state == S_XT && !x_trap); + + // ------------------------------------------------------------------ + always @(posedge clk) begin + irq_r <= {irq_local, 4'd0, irq_ext, 3'd0, irq_timer, 3'd0, irq_soft, 3'd0}; + retire <= done; + // a write to either half replaces the count for this cycle + if (!(csr_go && (csr_a == 12'hB00 || csr_a == 12'hB80))) mcycle <= mcycle + 64'd1; + // instret counts a cycle late (instructions take at least two, so the + // next one still reads the right count) + count_i <= done && !(csr_go && (csr_a == 12'hB02 || csr_a == 12'hB82)); + if (count_i) minstret <= minstret + 64'd1; + + if (csr_go) begin + case (csr_a) + 12'h300: begin mie_b <= csr_wv[3]; mpie_b <= csr_wv[7]; end + 12'h304: mie_r <= csr_wv & MIE_MASK; + 12'h305: mtvec <= {csr_wv[31:2], 2'b00}; + 12'h340: mscratch <= csr_wv; + 12'h341: mepc <= {csr_wv[31:2], 2'b00}; + 12'h342: mcause <= csr_wv; + 12'h343: mtval <= csr_wv; + 12'h740: mnscratch <= csr_wv; + 12'h741: mnepc <= {csr_wv[31:2], 2'b00}; + 12'h742: mncause <= csr_wv; + 12'h744: nmie <= csr_wv[3]; + 12'h7A0: if (csr_wv[31:1] == 31'd0) tsel <= csr_wv[0]; + 12'h7A1: begin + t_m[tsel] <= csr_wv[6]; t_x[tsel] <= csr_wv[2]; + t_s[tsel] <= csr_wv[1]; t_l[tsel] <= csr_wv[0]; + end + 12'h7A2: if (tsel) t_a1 <= csr_wv; else t_a0 <= csr_wv; + 12'h7A5: begin mte <= csr_wv[3]; mpte <= csr_wv[7]; end + 12'hB00: mcycle[31:0] <= csr_wv; + 12'hB80: mcycle[63:32] <= csr_wv; + 12'hB02: minstret[31:0] <= csr_wv; + 12'hB82: minstret[63:32] <= csr_wv; + default: ; + endcase + end + + case (state) + S_IF: state <= S_D; + + S_D: begin + ir <= inst; + pc4 <= pc + 32'd4; + tgt <= pc + (is_jal ? imm_j : imm_b); + a <= is_lui ? 32'd0 : (is_auipc || is_jal) ? pc : rv1; + b <= (is_lui || is_auipc) ? imm_u : is_st ? imm_s : + (is_op || is_br || is_mdv) ? rv2 : imm_i; + sv <= rv2; + alu_fn <= (is_lui || is_auipc) ? 3'd0 : f3; + alu_alt <= inst[30]; + e_alu <= is_lui | is_auipc | is_opi | is_op; + e_sub <= is_op & inst[30]; + e_jal <= is_jal; + e_jalr <= is_jalr; + e_br <= is_br; + e_tmis <= is_jal ? inst[21] : inst[8]; + e_ld <= is_ld; + e_st <= is_st; + e_mul <= is_mdv & !f3[2]; + e_div <= is_mdv & f3[2]; + e_csr <= is_csr; + e_ecall <= is_ecall; + e_ebrk <= is_ebrk; + e_mret <= is_mret; + e_mnret <= is_mnret; + e_fencei<= is_fencei; + e_ill <= !legal; + m_a <= {f3[1:0] != 2'b11 && rv1[31], rv1}; // mulhu: unsigned + m_b <= {f3[1:0] == 2'b01 && rv2[31], rv2}; // mulh only: signed + m_hi <= f3[1:0] != 2'b00; + if (!trap) state <= S_E; + end + + S_E: begin + // set up the multi-cycle units (unused if this traps) + la <= lo; + x_trap <= e_br ? taken : 1'b1; + x_cause <= e_br ? 32'd0 : (fire_l || fire_s) ? 32'd3 : e_st ? 32'd6 : 32'd4; + x_val <= e_br ? tgt : sum; + m_cnt <= 1'b0; + dneg_q <= !e_f3[0] && (a[31] ^ b[31]) && b != 32'd0; + dneg_r <= !e_f3[0] && a[31]; + dzero <= b == 32'd0; + da <= a; + dq <= (!e_f3[0] && a[31]) ? -a : a; + dd <= (!e_f3[0] && b[31]) ? -b : b; + dr <= 32'd0; + dcnt <= 6'd0; + if (!trap) begin + if (e_ld || e_st) + state <= ls_bad ? S_XT : S_MEM; + else if (e_mul) + state <= S_MUL; + else if (e_div) + state <= S_DIV; + else if (e_br && e_tmis) + state <= S_XT; + else if (e_mret) begin + pc <= mepc; mie_b <= mpie_b; mpie_b <= 1'b1; mte <= mpte; + state <= S_IF; + end else if (e_mnret) begin + pc <= mnepc; nmie <= 1'b1; + state <= S_IF; + end else if (jump) begin + pc <= jtarget; + state <= S_IF; + end else if (e_fencei) begin + pc <= pc4; + state <= S_IF; + end else begin + pc <= pc4; + state <= S_D; + end + end + end + + S_MEM: if (d_ack) begin pc <= pc4; state <= S_D; end + + S_MUL: begin + m_cnt <= 1'b1; + if (m_cnt) begin pc <= pc4; state <= S_D; end + end + + S_DIV: begin + if (!dsub[33]) begin dr <= dsub[31:0]; dq <= {dq[30:0], 1'b1}; end + else begin dr <= dtmp[31:0]; dq <= {dq[30:0], 1'b0}; end + dcnt <= dcnt + 6'd1; + if (dcnt == 6'd31) state <= S_DIVF; + end + + S_DIVF: begin pc <= pc4; state <= S_D; end + + S_XT: begin pc <= pc4; state <= S_D; end // not taken (else trap) + + endcase + + nmi_taken <= 1'b0; + stepped <= nmie && (stepped || done); // only counts outside the monitor + if (nmi_go) begin + mnepc <= pc; + mncause <= 32'h8000_0000; + nmie <= 1'b0; + stepped <= 1'b0; + nmi_taken <= 1'b1; + pc <= NMI_VEC; + state <= S_IF; + end else if (trap) begin + mepc <= pc; + mcause <= t_cause; + mtval <= t_val; + mpie_b <= mie_b; + mie_b <= 1'b0; + mpte <= mte; + mte <= 1'b0; + pc <= mtvec; + state <= S_IF; + end + + if (rst) begin + state <= S_IF; + pc <= RESET_PC; + mie_b <= 1'b0; mpie_b <= 1'b0; + mie_r <= 32'd0; + mtvec <= RESET_PC; + mcause <= 32'd0; + tsel <= 1'b0; mte <= 1'b0; mpte <= 1'b0; + t_m <= 2'b00; t_x <= 2'b00; t_s <= 2'b00; t_l <= 2'b00; + mcycle <= 64'd0; minstret <= 64'd0; + retire <= 1'b0; count_i <= 1'b0; + nmie <= 1'b1; stepped <= 1'b0; nmi_taken <= 1'b0; + end + end +endmodule diff --git a/rtl/rv32_system.v b/rtl/rv32_system.v new file mode 100644 index 0000000..29cea4d --- /dev/null +++ b/rtl/rv32_system.v @@ -0,0 +1,478 @@ +`timescale 1ns / 1ps + +// RISC-V computer: rv32_cpu, 80 KB of block RAM preloaded with BASIC, the +// monitor's 32 KB, and the Z-80 computer's I/O ports as memory-mapped +// registers. Runs on its own clock; the console crosses to the terminal's +// clock with toggle handshakes (one byte in flight each way). +// +// Memory map: +// 0000_0000-0001_3FFF RAM, 80 KB (BASIC). Writes below ROM_TOP are ignored +// so a crashed program cannot damage BASIC's code. +// 0002_0000-0002_7FFF the monitor's ROM (writes ignored). The NMI enters at +// 0002_0000. +// 0002_8000-0002_9FFF the monitor's RAM, for data only (it is distributed +// RAM, answering a cycle later than block RAM; code +// can't run from it). +// FFFF_FE00-FFFF_FEFF 32-bit registers (below) +// FFFF_FF00-FFFF_FFFF I/O port N at FFFF_FF00 + N, a byte each, the same +// ports as the Z-80 machine. Being within 2 KB of the top +// of memory, a port is one instruction from x0: +// lbu a0, -256+N(zero) / sb a0, -256+N(zero). +// +// I/O ports (FFFF_FF00 + N): +// 00 in bit 0 = key waiting, bit 1 = console can take a byte +// 01 in key (clears bit 0) out byte to the terminal +// 10 in millisecond counter bits 7:0; reading it latches bits 31:8 for 11-13 +// 20 out 7-segment display, right two digits 21 out left two digits +// 30 out graphics X bits 7:0 31 out X bit 8 32 out Y +// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y) +// 34 out fill the whole graphics screen in bit 0 = fill busy +// (also turns the sprites off and the scroll back to 0, unless +// bit 7 is set) +// 35 out scroll: buffer X shown at the left, bits 7:0 +// 36 out bit 0 = scroll X bit 8; bit 1 = hide the graphics in a border (4 +// columns each side, 2 rows top and bottom) to draw in unseen +// 37 out scroll: buffer Y shown at the top (0-239) +// 40 SPI flash control, 41 SPI flash data (see flash_spi.v) +// 60 out bit 1 = stop again (NMI) after one instruction of the program +// in why the last NMI came: 1 Pause key, 2 port 61, 3 step, +// 4 breakpoint 0, 5 breakpoint 1 +// 61 out enter the monitor (NMI) +// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on +// 70-78, 80-87 sprites (see sprites.v) +// 88 in keys held: bit 0 up (W, cursor or keypad 8), 1 down (S, 2), 2 left +// (A, 4), 3 right (D, 6), 4 fire (Space or Ctrl), 5 Enter, 6 Shift, +// 7 Esc +// 89 out pick a scan code (set 2; add 128 for an E0 code) +// in 1 if that key is held, else 0 +// 90-9D sound (see sound.v) +// The Z-80's debug-read ports (62-64) are gone: the monitor runs in the same +// address space as the program. Its breakpoint addresses are 32 bits, below. +// +// 32-bit registers (FFFF_FE00 + N): +// 00 in milliseconds since reset +// 04 in microseconds since reset (wraps every 71 minutes) +// 08 timer compare: the timer interrupt (mip.MTIP) is pending while the +// microsecond counter is at or past it (by less than 2^31) +// 10 breakpoint 0 address 14 breakpoint 1 address +// +// The monitor: an NMI (the Pause key, port 61, a breakpoint or a single step) +// saves the program's pc in mnepc and jumps to the monitor ROM, which leaves +// with mnret. NMIs wait while the program counter is in the monitor's ROM. +// Breakpoints compare the address of each instruction as it starts, so the +// instruction at a breakpoint has not run. +module rv32_system #( + parameter MEM_FILE = "basic.mem", // RAM 0000-FFFF + parameter MEM_HI_FILE = "basic-hi.mem", // RAM 10000-13FFF + parameter MON_FILE = "monitor.mem", + parameter CPU_HZ = 90_000_000, + parameter ROM_TOP = 32'h0000_A000 +) ( + input clk, // CPU clock + input rst, // synchronous to clk + // keyboard side: a byte is offered when rx_req != rx_ack + input rx_req, + input [7:0] rx_data, + output reg rx_ack, + // screen side: a byte is offered when tx_req != tx_ack + output reg tx_req, + output reg [7:0] tx_data, + input tx_ack, + output reg [15:0] seg_val, + output halted, + input brk_key, // pulse: the Pause key, enter the monitor + // graphics layer read port, on the video clock + input vclk, + input [16:0] gfx_vaddr, + output reg [3:0] gfx_vpix, // (combinational from registers) + output reg [8:0] scroll_x, + output reg [7:0] scroll_y, + output reg g_border, + // sprites, on the video clock (see sprites.v) + input sp_go, + input [7:0] sp_line, + input sp_buf, + input [8:0] sp_x, + input sp_on, + output [3:0] sp_pix, + input sp_ftick, + // keys held down (one bit per scan code, from the keyboard's clock) + input [255:0] keys, + // configuration flash (SPI) + output fl_cs_n, + output fl_sck, + output fl_mosi, + input fl_miso, + // sound, for a PmodAMP2 + output audio +); + localparam [31:0] MON_BASE = 32'h0002_0000; + assign halted = 1'b0; + + // ------------------------------------------------------------------ CPU + wire i_en, d_req, d_we, dbg_decode, retire, nmi_taken; + wire [31:0] i_addr, d_addr, d_wdata, dbg_pc; + wire [3:0] d_wstrb; + reg [31:0] i_rdata, d_rdata; + reg d_ack; + wire nmi, timer_irq; + reg step_arm; + + rv32_cpu #(.RESET_PC(32'h0), .NMI_VEC(MON_BASE)) cpu ( + .clk(clk), .rst(rst), + .i_en(i_en), .i_addr(i_addr), .i_rdata(i_rdata), + .d_req(d_req), .d_we(d_we), .d_wstrb(d_wstrb), .d_addr(d_addr), + .d_wdata(d_wdata), .d_rdata(d_rdata), .d_ack(d_ack), + .irq_soft(1'b0), .irq_timer(timer_irq), .irq_ext(1'b0), .irq_local(16'd0), + .nmi(nmi), .nmi_step(step_arm), .nmi_taken(nmi_taken), + .dbg_pc(dbg_pc), .dbg_decode(dbg_decode), .retire(retire) + ); + + // ------------------------------------------------------------- memories + // Each block RAM: instruction fetch on port A; loads and stores on port B, + // where a store is written the cycle after the request (its address + // replacing the core's for that cycle). + // RAM is two arrays (64 KB and 16 KB) so that it takes 20 block RAMs, not 32. + wire d_main = d_addr[31:17] == 15'd0 && (!d_addr[16] || d_addr[15:14] == 2'd0); + wire d_mon = d_addr[31:15] == MON_BASE[31:15]; + wire d_mram = d_addr[31:13] == 19'h14; // 0002_8000-0002_9FFF + wire d_io = d_addr[31:12] == 20'hFFFFF; + integer b; + + (* ram_style = "block" *) reg [31:0] ram0 [0:16383]; // 0000_0000-0000_FFFF + (* ram_style = "block" *) reg [31:0] ram1 [0:4095]; // 0001_0000-0001_3FFF + initial $readmemh(MEM_FILE, ram0); + initial $readmemh(MEM_HI_FILE, ram1); + reg [31:0] ram0_iq, ram1_iq, ram0_dq, ram1_dq, w_d; + reg [13:0] w_a; + reg [3:0] w_s; + reg w_r0, w_r1, d_hi; + wire [13:0] r0_b = w_r0 ? w_a : d_addr[15:2]; + wire [11:0] r1_b = w_r1 ? w_a[11:0] : d_addr[13:2]; + always @(posedge clk) if (i_en) ram0_iq <= ram0[i_addr[15:2]]; + always @(posedge clk) if (i_en) ram1_iq <= ram1[i_addr[13:2]]; + always @(posedge clk) begin + if (w_r0) + for (b = 0; b < 4; b = b + 1) + if (w_s[b]) ram0[r0_b][8*b +: 8] <= w_d[8*b +: 8]; + ram0_dq <= ram0[r0_b]; + end + always @(posedge clk) begin + if (w_r1) + for (b = 0; b < 4; b = b + 1) + if (w_s[b]) ram1[r1_b][8*b +: 8] <= w_d[8*b +: 8]; + ram1_dq <= ram1[r1_b]; + end + + (* ram_style = "block" *) reg [31:0] mrom [0:8191]; + initial $readmemh(MON_FILE, mrom); + reg [31:0] mon_iq, mon_dq; + always @(posedge clk) if (i_en) mon_iq <= mrom[i_addr[14:2]]; + always @(posedge clk) mon_dq <= mrom[d_addr[14:2]]; + + // the monitor's RAM: an access is registered, then the distributed RAM is + // read (or written) in the next cycle + (* ram_style = "distributed" *) reg [31:0] mram [0:2047]; + reg [10:0] mr_a; + reg mr_go, mr_we; + reg [31:0] mr_q; + always @(posedge clk) begin + if (mr_go && mr_we) + for (b = 0; b < 4; b = b + 1) + if (w_s[b]) mram[mr_a][8*b +: 8] <= w_d[8*b +: 8]; + mr_q <= mram[mr_a]; + end + + // instruction fetch: anything outside the two memories reads as 0 (illegal) + reg [1:0] i_sel; + always @(posedge clk) + if (i_en) i_sel <= i_addr[31:16] == 16'h0000 ? 2'd0 : + i_addr[31:14] == 18'h4 ? 2'd1 : + i_addr[31:15] == MON_BASE[31:15] ? 2'd2 : 2'd3; + always @* case (i_sel) + 2'd0: i_rdata = ram0_iq; + 2'd1: i_rdata = ram1_iq; + 2'd2: i_rdata = mon_iq; + default: i_rdata = 32'd0; + endcase + + // ----------------------------------------------------------- data bus + reg [2:0] d_sel; // 0 nothing, 1 RAM, 2 monitor ROM, 3 I/O, 4 monitor RAM + reg io_go, io_we; + reg [11:0] io_a; + reg [31:0] io_ww; // the store data as it came + reg [7:0] io_wd; // the byte for a port + reg [31:0] io_q; + always @(posedge clk) begin + w_r0 <= d_req && d_we && d_main && !d_addr[16] && d_addr >= ROM_TOP; + w_r1 <= d_req && d_we && d_main && d_addr[16] && d_addr >= ROM_TOP; + mr_go <= d_req && d_mram; + mr_we <= d_we; + mr_a <= d_addr[12:2]; + w_a <= d_addr[15:2]; + w_d <= d_wdata; + w_s <= d_wstrb; + io_go <= d_req && d_io; + io_we <= d_we; + io_a <= d_addr[11:0]; + io_ww <= d_wdata; + io_wd <= d_wdata >> {d_addr[1:0], 3'b000}; + if (d_req) begin + d_sel <= d_main ? 3'd1 : d_mon ? 3'd2 : d_io ? 3'd3 : d_mram ? 3'd4 : 3'd0; + d_hi <= d_addr[16]; + end + // block RAM answers the next cycle, I/O and the monitor's RAM the one after + d_ack <= (d_req && !d_io && !d_mram) || io_go || mr_go; + if (rst) begin io_go <= 1'b0; d_ack <= 1'b0; w_r0 <= 1'b0; w_r1 <= 1'b0; mr_go <= 1'b0; end + end + always @* case (d_sel) + 3'd1: d_rdata = d_hi ? ram1_dq : ram0_dq; + 3'd2: d_rdata = mon_dq; + 3'd3: d_rdata = io_q; + 3'd4: d_rdata = mr_q; + default: d_rdata = 32'd0; + endcase + + // the port strobes, a cycle after the request + wire io_bytes = io_a[11:8] == 4'hF; + wire io_wr = io_go && io_we && io_bytes; + wire io_rd = io_go && !io_we && io_bytes; + wire [7:0] io_addr = io_a[7:0]; + wire wr_word = io_go && io_we && io_a[11:8] == 4'hE; + reg [7:0] io_din; + reg [31:0] word_q; + + // ------------------------------------------------------------- console + (* ASYNC_REG = "TRUE" *) reg [1:0] rx_req_s, tx_ack_s; + always @(posedge clk) begin + rx_req_s <= {rx_req_s[0], rx_req}; + tx_ack_s <= {tx_ack_s[0], tx_ack}; + end + wire rx_avail = rx_req_s[1] != rx_ack; + wire tx_ready = tx_ack_s[1] == tx_req; + + // ------------------------------------------------------------ graphics + // 76800 pixels: a 64K array and an 11264 one, so they take about 9.5 block + // RAMs (one array would be built as 96K deep, 12 of them). + localparam GFX_PIXELS = 320 * 240; + (* ram_style = "block" *) reg [3:0] gfx_lo [0:65535]; + (* ram_style = "block" *) reg [3:0] gfx_hi [0:GFX_PIXELS - 65536 - 1]; + integer gi; + initial begin + for (gi = 0; gi < 65536; gi = gi + 1) gfx_lo[gi] = 4'd0; + for (gi = 0; gi < GFX_PIXELS - 65536; gi = gi + 1) gfx_hi[gi] = 4'd0; + end + + reg [8:0] gx; + reg [7:0] gy; + reg [3:0] gfx_q_lo, gfx_q_hi, fill_c; + reg gfx_q_sel; + reg [16:0] fill_a; + reg fill_busy; + wire [16:0] gxy = {gy, 8'd0} + {2'd0, gy, 6'd0} + {8'd0, gx}; + wire plot = io_wr && io_addr == 8'h33 && gx < 9'd320 && gy < 8'd240; + wire [16:0] g_addr = fill_busy ? fill_a : gxy; + wire g_we = fill_busy || plot; + wire [3:0] g_wd = fill_busy ? fill_c : io_wd[3:0]; + wire [3:0] gfx_q = gfx_q_sel ? gfx_q_hi : gfx_q_lo; + + always @(posedge clk) begin + if (g_we && !g_addr[16]) gfx_lo[g_addr[15:0]] <= g_wd; + gfx_q_lo <= gfx_lo[g_addr[15:0]]; + end + always @(posedge clk) begin + if (g_we && g_addr[16]) gfx_hi[g_addr[13:0]] <= g_wd; + gfx_q_hi <= gfx_hi[g_addr[13:0]]; + gfx_q_sel <= g_addr[16]; + end + reg [3:0] gv_lo, gv_hi; + reg gv_sel; + always @(posedge vclk) begin + gv_lo <= gfx_lo[gfx_vaddr[15:0]]; + gv_hi <= gfx_hi[gfx_vaddr[13:0]]; + gv_sel <= gfx_vaddr[16]; + end + always @* gfx_vpix = gv_sel ? gv_hi : gv_lo; + + // whole-array view for testbenches + function [3:0] gfx(input [16:0] n); + gfx = n[16] ? gfx_hi[n[13:0]] : gfx_lo[n[15:0]]; + endfunction + + always @(posedge clk) + if (rst) begin + fill_busy <= 1'b0; + gx <= 9'd0; gy <= 8'd0; + scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0; + end else begin + if (io_wr) case (io_addr) + 8'h30: gx[7:0] <= io_wd; + 8'h31: gx[8] <= io_wd[0]; + 8'h32: gy <= io_wd; + 8'h33: gx <= gx + 1'b1; + 8'h34: begin + fill_busy <= 1'b1; fill_a <= 17'd0; fill_c <= io_wd[3:0]; + if (!io_wd[7]) begin scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0; end + end + 8'h35: scroll_x[7:0] <= io_wd; + 8'h36: begin scroll_x[8] <= io_wd[0]; g_border <= io_wd[1]; end + 8'h37: scroll_y <= io_wd >= 8'd240 ? io_wd - 8'd240 : io_wd; + default: ; + endcase + if (fill_busy) begin + fill_a <= fill_a + 1'b1; + if (fill_a == GFX_PIXELS - 1) fill_busy <= 1'b0; + end + end + + // ------------------------------------------------------------- sprites + wire [7:0] spr_q; + sprites spr ( + .clk(clk), .rst(rst), + .io_wr(io_wr), .io_port(io_addr), .io_wd(io_wd), .io_q(spr_q), + .vclk(vclk), .go(sp_go), .line(sp_line), .rd_buf(sp_buf), .rd_x(sp_x), + .rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick) + ); + + // ---------------------------------------------------------------- sound + wire [7:0] snd_q; + sound #(.CPU_HZ(CPU_HZ)) snd ( + .clk(clk), .rst(rst), .hush(io_wr && io_addr == 8'h34 && !io_wd[7]), + .io_wr(io_wr), .io_port(io_addr), .io_wd(io_wd), .io_q(snd_q), .audio(audio) + ); + + // ---------------------------------------------------------- held keys + // The keyboard's clock writes these; a bit that changes while it is read + // just reads as before or after. + reg [7:0] key_sel = 8'd0; + always @(posedge clk) if (io_wr && io_addr == 8'h89) key_sel <= io_wd; + wire [7:0] joy = { + keys[8'h76], // Esc + keys[8'h12] | keys[8'h59], // Shift + keys[8'h5A] | keys[8'hDA], // Enter + keys[8'h29] | keys[8'h14] | keys[8'h94], // Space, Ctrl + keys[8'h23] | keys[8'hF4] | keys[8'h74], // D, right, keypad 6 + keys[8'h1C] | keys[8'hEB] | keys[8'h6B], // A, left, keypad 4 + keys[8'h1B] | keys[8'hF2] | keys[8'h72], // S, down, keypad 2 + keys[8'h1D] | keys[8'hF5] | keys[8'h75] // W, up, keypad 8 + }; + + // --------------------------------------------------------------- flash + wire [7:0] fl_ctl_q, fl_dat_q; + flash_spi flash ( + .clk(clk), .rst(rst), + .wr_ctl(io_wr && io_addr == 8'h40), .wr_dat(io_wr && io_addr == 8'h41), + .wdata(io_wd), .ctl_q(fl_ctl_q), .dat_q(fl_dat_q), + .cs_n(fl_cs_n), .sck(fl_sck), .mosi(fl_mosi), .miso(fl_miso) + ); + + // ------------------------------------------------- milli/microseconds + localparam MS_DIV = CPU_HZ / 1000; + localparam US_DIV = CPU_HZ / 1000000; + reg [31:0] ms, ms_latch, us, tcmp; + reg [17:0] ms_div; + reg [7:0] us_div; + always @(posedge clk) + if (rst) begin + ms <= 0; ms_div <= 0; us <= 0; us_div <= 0; tcmp <= 32'h8000_0000; + end else begin + if (ms_div == MS_DIV - 1) begin ms <= ms + 1'b1; ms_div <= 0; end + else ms_div <= ms_div + 1'b1; + if (us_div == US_DIV - 1) begin us <= us + 1'b1; us_div <= 0; end + else us_div <= us_div + 1'b1; + if (wr_word && io_a[7:0] == 8'h08) tcmp <= io_ww; + end + wire [31:0] t_left = us - tcmp; + reg timer_r; + always @(posedge clk) timer_r <= !t_left[31]; + assign timer_irq = timer_r; + + // ------------------------------------------------------------- monitor + // An NMI request waits (in nmi_r) until the core takes it; breakpoint hits + // go straight to the core as their instruction starts. + reg [31:0] bp0, bp1; + reg [1:0] bp_on, hit_d; + reg [2:0] why, why_r; + reg nmi_r, in_mon; + wire hit0 = bp_on[0] && dbg_decode && dbg_pc == bp0; + wire hit1 = bp_on[1] && dbg_decode && dbg_pc == bp1; + assign nmi = nmi_r || hit0 || hit1; + + always @(posedge clk) begin + in_mon <= dbg_pc[31:15] == MON_BASE[31:15]; + hit_d <= {hit1, hit0}; + if (rst) begin + nmi_r <= 1'b0; step_arm <= 1'b0; bp_on <= 2'b00; why <= 3'd0; + bp0 <= 32'd0; bp1 <= 32'd0; + end else begin + if (io_wr) case (io_addr) + 8'h60: step_arm <= io_wd[1]; + 8'h67: bp_on <= io_wd[1:0]; + default: ; + endcase + if (wr_word && io_a[7:0] == 8'h10) bp0 <= io_ww; + if (wr_word && io_a[7:0] == 8'h14) bp1 <= io_ww; + if (!nmi_r && !in_mon) begin + if (brk_key) begin + nmi_r <= 1'b1; why_r <= 3'd1; + end else if (io_wr && io_addr == 8'h61) begin + nmi_r <= 1'b1; why_r <= 3'd2; + end + end + if (nmi_taken) begin + why <= nmi_r ? why_r : hit_d[0] ? 3'd4 : hit_d[1] ? 3'd5 : 3'd3; + nmi_r <= 1'b0; + step_arm <= 1'b0; + end + end + end + + // -------------------------------------------------------- port reads + always @* case (io_addr) + 8'h00: io_din = {6'd0, tx_ready, rx_avail}; + 8'h01: io_din = rx_data; + 8'h10: io_din = ms[7:0]; // sampled on the same edge that fills ms_latch + 8'h11: io_din = ms_latch[15:8]; + 8'h12: io_din = ms_latch[23:16]; + 8'h13: io_din = ms_latch[31:24]; + 8'h33: io_din = {4'd0, gfx_q}; + 8'h34: io_din = {7'd0, fill_busy}; + 8'h40: io_din = fl_ctl_q; + 8'h41: io_din = fl_dat_q; + 8'h60: io_din = {5'd0, why}; + 8'h78, 8'h80, 8'h81, 8'h82, 8'h83, 8'h84, 8'h85, 8'h86, 8'h87: + io_din = spr_q; + 8'h88: io_din = joy; + 8'h89: io_din = {7'd0, keys[key_sel]}; + 8'h98, 8'h99, 8'h9A: + io_din = snd_q; + default: io_din = 8'hFF; + endcase + always @* case (io_a[7:0]) + 8'h00: word_q = ms; + 8'h04: word_q = us; + 8'h08: word_q = tcmp; + 8'h10: word_q = bp0; + 8'h14: word_q = bp1; + default: word_q = 32'd0; + endcase + + always @(posedge clk) begin + if (io_go) io_q <= io_bytes ? {24'd0, io_din} << {io_a[1:0], 3'b000} : word_q; + if (rst) begin + rx_ack <= rx_req_s[1]; + tx_req <= tx_ack_s[1]; + seg_val <= 16'h0032; + ms_latch <= 32'd0; + end else begin + if (io_rd && io_addr == 8'h01 && rx_avail) rx_ack <= ~rx_ack; + if (io_rd && io_addr == 8'h10) ms_latch <= ms; + if (io_wr && io_addr == 8'h01 && tx_ready) begin + tx_data <= io_wd; + tx_req <= ~tx_req; + end + if (io_wr && io_addr == 8'h20) seg_val[7:0] <= io_wd; + if (io_wr && io_addr == 8'h21) seg_val[15:8] <= io_wd; + end + end +endmodule diff --git a/rtl/sevenseg.v b/rtl/sevenseg.v new file mode 100644 index 0000000..cf0c4dd --- /dev/null +++ b/rtl/sevenseg.v @@ -0,0 +1,29 @@ +`timescale 1ns / 1ps + +// Four-digit hex display, digit 3 (left) = value[15:12]. Segments active low. +module sevenseg ( + input clk, + input [15:0] value, + output reg [6:0] seg, + output reg [3:0] an +); + reg [17:0] cnt; + always @(posedge clk) cnt <= cnt + 1'b1; + + wire [1:0] d = cnt[17:16]; + wire [3:0] x = value[d*4 +: 4]; + + always @(posedge clk) begin + an <= ~(4'b0001 << d); + case (x) // gfedcba + 4'h0: seg <= 7'b1000000; 4'h1: seg <= 7'b1111001; + 4'h2: seg <= 7'b0100100; 4'h3: seg <= 7'b0110000; + 4'h4: seg <= 7'b0011001; 4'h5: seg <= 7'b0010010; + 4'h6: seg <= 7'b0000010; 4'h7: seg <= 7'b1111000; + 4'h8: seg <= 7'b0000000; 4'h9: seg <= 7'b0010000; + 4'hA: seg <= 7'b0001000; 4'hB: seg <= 7'b0000011; + 4'hC: seg <= 7'b1000110; 4'hD: seg <= 7'b0100001; + 4'hE: seg <= 7'b0000110; 4'hF: seg <= 7'b0001110; + endcase + end +endmodule diff --git a/rtl/sound.v b/rtl/sound.v new file mode 100644 index 0000000..c1f2946 --- /dev/null +++ b/rtl/sound.v @@ -0,0 +1,173 @@ +`timescale 1ns / 1ps +// A small sound chip for the Z-80, in the style of the 8-bit era's +// programmable sound generators, played through a Digilent PmodAMP2. +// +// Three square-wave voices and a noise source. Each voice plays its tone, +// the noise, or both (the mixer), at one of 16 volumes on a log scale (about +// 3 dB a step). A volume write starts an envelope: an optional rise from 0 at +// the attack rate, then an optional fall to 0 at the decay rate, so a game +// can fire off a shot or an explosion with a few OUTs and leave it. +// +// 90h/91h voice 0 pitch, low byte / high 4 bits frequency = 125000 / pitch Hz +// 92h/93h voice 1 pitch (pitch 0 counts as 1) +// 94h/95h voice 2 pitch +// 96h noise pitch, 0-31: higher is lower and rougher +// 97h mixer: bits 0-2 tone on for voices 0-2, bits 3-5 noise on for them +// 98h-9Ah voice 0-2 volume 0-15, which (re)starts its envelope; reading +// gives the volume it is at now, so 0 means the sound has ended +// 9Bh-9Dh voice 0-2 envelope: high nibble attack, low nibble decay, each +// n x 4 ms a volume step (0 = jump straight up / hold) +// +// A voice with neither its tone nor the noise on outputs a steady level, as +// on the old chips. `hush` (CLS) and reset silence everything. +// +// The three voices are added up and turned into a single bit by a first-order +// sigma-delta modulator at the full clock rate; the PmodAMP2 filters it and +// drives headphones or a speaker. +module sound #( + parameter CPU_HZ = 90_000_000 +) ( + input clk, + input rst, + input hush, + input io_wr, + input [7:0] io_port, + input [7:0] io_wd, + output reg [7:0] io_q, // for reads of 98h-9Ah + output reg audio = 1'b0 +); + localparam TICK_DIV = CPU_HZ / 250_000; // tone counters run at 250 kHz + localparam MS4_DIV = CPU_HZ / 250; // envelope steps in 4 ms units + + reg [11:0] pitch [0:2]; + reg [4:0] npitch; + reg [5:0] mixer; + reg [3:0] vol [0:2]; // the volume asked for + reg [3:0] cur [0:2]; // the volume now + reg [3:0] att [0:2], dec [0:2]; + reg rising [0:2]; + + // ---------------------------------------------------------------- ticks + reg [9:0] tdiv = 10'd0; + reg tick = 1'b0; + reg [19:0] ediv = 20'd0; + reg etick = 1'b0; + always @(posedge clk) begin + tick <= tdiv == 0; + tdiv <= tdiv == 0 ? TICK_DIV - 1 : tdiv - 1'b1; + etick <= ediv == 0; + ediv <= ediv == 0 ? MS4_DIV - 1 : ediv - 1'b1; + end + + // --------------------------------------------------------------- voices + reg [11:0] tcnt [0:2]; + reg [2:0] tone = 3'd0; + reg [4:0] ncnt = 5'd0; + reg [16:0] lfsr = 17'd1; + reg [3:0] ecnt [0:2]; + integer i; + initial for (i = 0; i < 3; i = i + 1) begin + tcnt[i] = 12'd0; ecnt[i] = 4'd0; cur[i] = 4'd0; vol[i] = 4'd0; + end + + always @(posedge clk) begin + if (rst || hush) begin + for (i = 0; i < 3; i = i + 1) begin + vol[i] <= 4'd0; cur[i] <= 4'd0; rising[i] <= 1'b0; + if (rst) begin pitch[i] <= 12'd0; att[i] <= 4'd0; dec[i] <= 4'd0; end + end + mixer <= 6'd0; + if (rst) begin npitch <= 5'd0; lfsr <= 17'd1; tone <= 3'd0; end + end else begin + if (io_wr) case (io_port) + 8'h90: pitch[0][7:0] <= io_wd; + 8'h91: pitch[0][11:8] <= io_wd[3:0]; + 8'h92: pitch[1][7:0] <= io_wd; + 8'h93: pitch[1][11:8] <= io_wd[3:0]; + 8'h94: pitch[2][7:0] <= io_wd; + 8'h95: pitch[2][11:8] <= io_wd[3:0]; + 8'h96: npitch <= io_wd[4:0]; + 8'h97: mixer <= io_wd[5:0]; + 8'h9B: {att[0], dec[0]} <= io_wd; + 8'h9C: {att[1], dec[1]} <= io_wd; + 8'h9D: {att[2], dec[2]} <= io_wd; + default: ; + endcase + + // tones: each output flips every `pitch` ticks + if (tick) begin + for (i = 0; i < 3; i = i + 1) + if (tcnt[i] <= 12'd1) begin + tcnt[i] <= pitch[i]; + tone[i] <= ~tone[i]; + end else + tcnt[i] <= tcnt[i] - 1'b1; + if (ncnt == 0) begin + ncnt <= npitch; + lfsr <= {lfsr[0] ^ lfsr[3], lfsr[16:1]}; + end else + ncnt <= ncnt - 1'b1; + end + + // envelopes + for (i = 0; i < 3; i = i + 1) begin + if (io_wr && io_port == 8'h98 + i) begin + vol[i] <= io_wd[3:0]; + ecnt[i] <= 4'd0; + if (att[i] != 0 && io_wd[3:0] != 0) begin + cur[i] <= 4'd0; rising[i] <= 1'b1; + end else begin + cur[i] <= io_wd[3:0]; rising[i] <= 1'b0; + end + end else if (etick) begin + if (rising[i]) begin + if (ecnt[i] + 1'b1 >= att[i]) begin + ecnt[i] <= 4'd0; + cur[i] <= cur[i] + 1'b1; + if (cur[i] + 1'b1 >= vol[i]) rising[i] <= 1'b0; + end else + ecnt[i] <= ecnt[i] + 1'b1; + end else if (dec[i] != 0 && cur[i] != 0) begin + if (ecnt[i] + 1'b1 >= dec[i]) begin + ecnt[i] <= 4'd0; + cur[i] <= cur[i] - 1'b1; + end else + ecnt[i] <= ecnt[i] + 1'b1; + end + end + end + end + end + + always @* case (io_port) + 8'h98: io_q = {4'd0, cur[0]}; + 8'h99: io_q = {4'd0, cur[1]}; + 8'h9A: io_q = {4'd0, cur[2]}; + default: io_q = 8'hFF; + endcase + + // ---------------------------------------------------------------- mixing + function [7:0] level(input [3:0] v); // about 3 dB a step + case (v) + 4'd0: level = 8'd0; 4'd1: level = 8'd2; 4'd2: level = 8'd3; 4'd3: level = 8'd4; + 4'd4: level = 8'd6; 4'd5: level = 8'd8; 4'd6: level = 8'd11; 4'd7: level = 8'd16; + 4'd8: level = 8'd23; 4'd9: level = 8'd32; 4'd10: level = 8'd45; 4'd11: level = 8'd64; + 4'd12: level = 8'd90; 4'd13: level = 8'd128; 4'd14: level = 8'd181; default: level = 8'd255; + endcase + endfunction + + wire [2:0] on; + genvar g; + generate for (g = 0; g < 3; g = g + 1) begin : mix + assign on[g] = (tone[g] | ~mixer[g]) & (lfsr[0] | ~mixer[g + 3]); + end endgenerate + + reg [9:0] sum = 10'd0; + reg [10:0] acc = 11'd0; + always @(posedge clk) begin + sum <= (on[0] ? level(cur[0]) : 10'd0) + (on[1] ? level(cur[1]) : 10'd0) + + (on[2] ? level(cur[2]) : 10'd0); + acc <= rst ? 11'd0 : {1'b0, acc[9:0]} + {1'b0, sum}; // carry out = the output bit + audio <= acc[10]; + end +endmodule diff --git a/rtl/sprites.v b/rtl/sprites.v new file mode 100644 index 0000000..70c96e8 --- /dev/null +++ b/rtl/sprites.v @@ -0,0 +1,237 @@ +`timescale 1ns / 1ps + +// Hardware sprites over the 320x240 graphics layer. +// +// 32 sprites of 16x16 graphics pixels in the 16 colours (0 = transparent), +// drawn from 64 shapes. Sprite 0 is on top of sprite 1 and so on; all sprites +// are over the graphics and under the text. Each sprite has a position, a +// shape, X and Y flip and an on/off bit. +// +// Z-80 ports (low address byte): +// 70 out select a sprite, 0-31 +// 71 out X bits 7:0 72 out X bit 8 +// 73 out Y; moves the selected sprite to the X and Y given (both at once) +// 74 out shape, 0-63 +// 75 out bit 0 = on, bit 1 = flip left-right, bit 2 = flip upside down +// 76 out start loading shape n (0-63) at its top left +// 77 out two pixels of the shape, left one in bits 7:4, then move on; +// 128 bytes make a shape, a row of 16 pixels at a time +// 78 in frame counter, +1 at the start of each vertical blank +// 80-83 in sprites 0-7, 8-15, 16-23, 24-31 that touched another sprite +// in the last frame +// 84-87 in sprites that touched a graphics pixel (not colour 0) +// 34 out (the graphics fill) also turns every sprite off unless bit 7 is set +// +// X and Y are the top-left pixel and wrap at 512 and 256, so a sprite can go +// partly off the left or top edge: X = 500 is 12 pixels left of the screen. +// +// Drawing: the video asks for each graphics line one line ahead (go, line). +// The engine clears that line's buffer, then walks the sprites from 31 down +// to 0, writing each visible pixel, so lower numbers end up on top. A pixel +// written over another sprite's records a collision for both. The video reads +// the other buffer, one pixel per clock. A line takes at most about 900 of the +// 6,752 pixel clocks that a graphics line lasts. +module sprites ( + // Z-80 side + input clk, + input rst, + input io_wr, + input [7:0] io_port, + input [7:0] io_wd, + output reg [7:0] io_q, + // video side (pixel clock) + input vclk, + input go, // prepare graphics line `line` + input [7:0] line, + input rd_buf, // buffer of the line on screen + input [8:0] rd_x, // graphics x on screen, registered + input rd_on, // inside the graphics area + output reg [3:0] pix, // sprite colour there, a clock later + input [3:0] gfx_pix, // graphics colour there, same clock as pix + input ftick // start of vertical blank +); + integer i; + + // ------------------------------------------------------------ Z-80 side + reg [4:0] sel = 5'd0; + reg [8:0] x_stage = 9'd0; + reg [31:0] en = 32'd0; + reg [12:0] pat_a = 13'd0; + (* ram_style = "distributed" *) reg [16:0] pos [0:31]; // {y, x} + (* ram_style = "distributed" *) reg [7:0] shp [0:31]; // {flip y, flip x, shape} + (* ram_style = "block" *) reg [7:0] pat [0:8191]; // shape, row, pixel pair + initial begin + for (i = 0; i < 32; i = i + 1) begin pos[i] = 17'd0; shp[i] = 8'd0; end + for (i = 0; i < 8192; i = i + 1) pat[i] = 8'd0; + end + + wire [7:0] shp_sel = shp[sel]; + always @(posedge clk) begin + if (io_wr) case (io_port) + 8'h73: pos[sel] <= {io_wd, x_stage}; + 8'h74: shp[sel] <= {shp_sel[7:6], io_wd[5:0]}; + 8'h75: shp[sel] <= {io_wd[2:1], shp_sel[5:0]}; + default: ; + endcase + end + always @(posedge clk) if (io_wr && io_port == 8'h77) pat[pat_a] <= io_wd; + + always @(posedge clk) + if (rst) begin + en <= 32'd0; + sel <= 5'd0; + x_stage <= 9'd0; + pat_a <= 13'd0; + end else if (io_wr) case (io_port) + 8'h34: if (!io_wd[7]) en <= 32'd0; + 8'h70: sel <= io_wd[4:0]; + 8'h71: x_stage[7:0] <= io_wd; + 8'h72: x_stage[8] <= io_wd[0]; + 8'h75: en[sel] <= io_wd[0]; + 8'h76: pat_a <= {io_wd[5:0], 7'd0}; + 8'h77: pat_a <= pat_a + 1'b1; + default: ; + endcase + + // ----------------------------------------------------------- line fill + // line buffers: {buffer, x} -> {colour, sprite} + (* ram_style = "distributed" *) reg [8:0] lb [0:1023]; + initial for (i = 0; i < 1024; i = i + 1) lb[i] = 9'd0; + + localparam S_IDLE = 2'd0, S_CLEAR = 2'd1, S_SPR = 2'd2; + reg [1:0] st = S_IDLE; + reg [8:0] cx; + reg wb; + reg [7:0] ln; + reg [4:0] s; + reg drawing = 1'b0; + reg [3:0] col; + reg [8:0] sx; + reg [3:0] srow; + reg sfx; + reg [5:0] sshape; + + // the sprite being considered + wire [16:0] s_pos = pos[s]; + wire [7:0] s_shp = shp[s]; + wire [7:0] s_row = ln - s_pos[16:9]; + wire s_vis = en[s] && s_row < 8'd16; + + // pixel pipeline: address, pattern read, write + reg [12:0] pat_ra; + reg [7:0] pat_q; + reg p0_v = 1'b0, p1_v = 1'b0, p0_n, p1_n; + reg [8:0] p0_x, p1_x; + reg [4:0] p0_s, p1_s; + wire [3:0] cc = sfx ? ~col : col; + + always @(posedge vclk) pat_q <= pat[pat_ra]; + + always @(posedge vclk) begin + p0_v <= 1'b0; + if (go) begin + st <= S_CLEAR; + cx <= 9'd0; + wb <= line[0]; + ln <= line; + drawing <= 1'b0; + end else case (st) + S_CLEAR: begin + cx <= cx + 1'b1; + if (cx == 9'd319) begin + st <= S_SPR; + s <= 5'd31; + end + end + S_SPR: + if (!drawing) begin + if (s_vis) begin + drawing <= 1'b1; + col <= 4'd0; + sx <= s_pos[8:0]; + srow <= s_shp[7] ? ~s_row[3:0] : s_row[3:0]; + sfx <= s_shp[6]; + sshape <= s_shp[5:0]; + end else if (s == 5'd0) + st <= S_IDLE; + else + s <= s - 1'b1; + end else begin + pat_ra <= {sshape, srow, cc[3:1]}; + p0_n <= cc[0]; + p0_x <= sx + col; + p0_s <= s; + p0_v <= 1'b1; + col <= col + 1'b1; + if (col == 4'd15) begin + drawing <= 1'b0; + if (s == 5'd0) st <= S_IDLE; + else s <= s - 1'b1; + end + end + default: ; + endcase + {p1_v, p1_n, p1_x, p1_s} <= {p0_v, p0_n, p0_x, p0_s}; + end + + wire [3:0] w_col = p1_n ? pat_q[3:0] : pat_q[7:4]; + wire w_spr = p1_v && w_col != 4'd0 && p1_x < 9'd320; + wire w_clr = st == S_CLEAR; + wire [9:0] wa = {wb, w_clr ? cx : p1_x}; + wire [8:0] old = lb[wa]; + always @(posedge vclk) + if (w_clr || w_spr) lb[wa] <= w_clr ? 9'd0 : {w_col, p1_s}; + + // ----------------------------------------------------------- video read + wire [8:0] rd = lb[{rd_buf, rd_x}]; + reg [4:0] pix_id; + always @(posedge vclk) begin + pix <= rd_on ? rd[8:5] : 4'd0; + pix_id <= rd[4:0]; + end + + // ----------------------------------------------------------- collisions + reg [31:0] ss_acc = 32'd0, bg_acc = 32'd0, ss_frame = 32'd0, bg_frame = 32'd0; + reg ft = 1'b0; + always @(posedge vclk) + if (ftick) begin + ss_frame <= ss_acc; + bg_frame <= bg_acc; + ss_acc <= 32'd0; + bg_acc <= 32'd0; + ft <= ~ft; + end else begin + if (pix != 4'd0 && gfx_pix != 4'd0) bg_acc[pix_id] <= 1'b1; + if (w_spr && old[8:5] != 4'd0) begin + ss_acc[p1_s] <= 1'b1; + ss_acc[old[4:0]] <= 1'b1; + end + end + + // A frame's results are steady for a whole frame after ft flips, so the + // Z-80 side copies them once it has seen the flip. + (* ASYNC_REG = "TRUE" *) reg [2:0] ft_s = 3'd0; + reg [7:0] frames = 8'd0; + reg [31:0] ss_cpu = 32'd0, bg_cpu = 32'd0; + always @(posedge clk) begin + ft_s <= {ft_s[1:0], ft}; + if (ft_s[2] != ft_s[1]) begin + frames <= frames + 1'b1; + ss_cpu <= ss_frame; + bg_cpu <= bg_frame; + end + end + + always @* case (io_port) + 8'h78: io_q = frames; + 8'h80: io_q = ss_cpu[7:0]; + 8'h81: io_q = ss_cpu[15:8]; + 8'h82: io_q = ss_cpu[23:16]; + 8'h83: io_q = ss_cpu[31:24]; + 8'h84: io_q = bg_cpu[7:0]; + 8'h85: io_q = bg_cpu[15:8]; + 8'h86: io_q = bg_cpu[23:16]; + 8'h87: io_q = bg_cpu[31:24]; + default: io_q = 8'hFF; + endcase +endmodule diff --git a/rtl/term_ctrl.v b/rtl/term_ctrl.v new file mode 100644 index 0000000..0b198a4 --- /dev/null +++ b/rtl/term_ctrl.v @@ -0,0 +1,789 @@ +`timescale 1ns / 1ps + +// VT220 terminal engine with ANSI colour. Consumes received bytes and keeps +// the character buffer up to date: 80x32, or 132x64 after DECCOLM (CSI ?3h). +// The buffer is row-major with a 132-cell stride in both (address = row*132 + +// col), so scrolling copies whole 132-cell rows either way. +// +// Cell format: {blink, underline, bg[3:0], fg[3:0], CP437 code}. Reverse, +// bold and concealed text are resolved into the colours when a new_cell is written. +// +// Supported (beyond C0 controls): +// ESC 7 8 D E H M Z c = > ESC ( ) <0|A|B> ESC # 8 +// CSI A B C D E F G H I J K L M P S T X Z @ ` a d e f g h l m n q r s u c +// CSI ? J K h l n CSI > c CSI ! p +// Modes: IRM(4) LNM(20) DECCKM(?1) DECCOLM(?3) DECSCLM(?4) DECOM(?6) DECAWM(?7) +// DECTCEM(?25) +// alternate screen ?47 (parameters stop at 255, so not ?1047/?1049) +// SGR 0 1 4 5 7 8 21-28 30-49 90-107, 38/48;5;n and 38/48;2;r;g;b (approximated) +// DECLL (CSI n q) drives four LEDs. +// OSC, DCS, APC, PM and SOS strings (e.g. titles, OSC 3008) are discarded. +// Scrolling copies rows in memory. With smooth scroll on, a line feed at the +// bottom margin first slides the region up a few pixels per frame. + +module term_ctrl ( + input clk, + input rst, + input [7:0] in_byte, + input in_empty, + output reg in_rd, + input lf_cr, // LF also returns the carriage + input clear_req, + input [3:0] def_fg, // default foreground colour index + input smooth_sw, // force smooth scrolling on + input smooth_fast, + input frame_tick, // start of vertical blanking + // character RAM port + output reg [13:0] addr, + output reg we, + output reg [17:0] wdata, + input [17:0] rdata, + // to the display + output reg [5:0] row, + output reg [7:0] col, + output reg cur_vis, + output reg [5:0] stop, // scroll region, inclusive + output reg [5:0] sbot, + output reg sm_on, + output reg sm_dir, // 0 = scrolling up, 1 = down + output reg [4:0] sm_off, + // replies to the host (DA, DSR) + output reg [7:0] resp_byte, + output reg resp_wr, + input resp_full, + // modes the keyboard needs + output reg cursor_app, + output reg keypad_app, + output reg lnm, + output reg [3:0] dec_leds, + output reg bell, + output reg alt_scr, // showing and writing the alternate screen + output reg wide // 132 columns (DECCOLM) +); + localparam [13:0] STRIDE = 14'd132; + localparam [13:0] ALL = 14'd8448; // 132 x 64: clears either layout + wire [5:0] LAST_ROW = wide ? 6'd63 : 6'd31; + wire [7:0] LAST_COL = wide ? 8'd131 : 8'd79; + wire [7:0] NCOLS = wide ? 8'd132 : 8'd80; + wire [6:0] NROWS = wide ? 7'd64 : 7'd32; + wire [13:0] CELLS = wide ? 14'd8448 : 14'd4224; + + localparam [3:0] S_IDLE = 4'd0, S_DISP = 4'd1, S_FILL = 4'd2, S_CRD = 4'd3, + S_CWAIT = 4'd4, S_CWR = 4'd5, S_PLOOP = 4'd6, S_RESP = 4'd7, + S_PUT = 4'd8, S_TAB = 4'd9, S_SMOOTH = 4'd10, S_SMEND = 4'd11, + S_OP = 4'd12, S_EXEC = 4'd13, S_SCR1 = 4'd14, S_SCR2 = 4'd15; + localparam [2:0] P_NORM = 3'd0, P_ESC = 3'd1, P_ESCI = 3'd2, P_CSI = 3'd3, P_STR = 3'd4; + localparam [1:0] K_SGR = 2'd0, K_SET = 2'd1, K_RST = 2'd2, K_LL = 2'd3; + + reg [3:0] st, ret_st, sm_ret; + reg [2:0] ps; + reg [7:0] c; + + // modes and attributes + reg pend, awm, irm, om, sclm; + reg bold, ul, blink, rev, conceal; + reg [3:0] fg, bg; + reg [1:0] g0, g1; // 0 ASCII, 1 DEC special graphics, 2 UK + reg gl; // 0 = G0 active, 1 = G1 (SO) + reg [131:0] tabs; + reg colm_clr; // DECCOLM: clear the screen when idle + + // saved cursor (DECSC) + reg [5:0] sv_row; + reg [7:0] sv_col; + reg sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal; + reg [3:0] sv_fg, sv_bg; + reg [1:0] sv_g0, sv_g1; + + // parser + reg [7:0] par [0:15]; + reg [3:0] pidx; + reg priv, gtm, ign; + reg [7:0] cint, inter; + + // scroll request + reg sc_dir; + reg [5:0] sc_t, sc_b; + reg [7:0] sc_n; + reg [6:0] sc_h, sc_k; // region height, lines to move + + // memory copy / fill engine + reg [13:0] c_src, c_dst, c_cnt, f_addr, f_cnt; + reg c_dir; + reg [17:0] f_cell; + + // parameter loop (SGR, SM/RM, DECLL) + reg [1:0] pk; + reg [3:0] pi; + reg [1:0] ext; // 38/48 extended colour state + reg ext_bg; + reg [1:0] ext_n; + reg [7:0] ext_r, ext_g; + + reg [95:0] rbuf; + reg [3:0] rlen; + reg [7:0] rep; + reg tdir; + + integer i; + + // ------------------------------------------------------------ helpers + function [13:0] rc(input [5:0] r, input [7:0] cc); + rc = {1'b0, r, 7'b0} + {6'b0, r, 2'b0} + {6'b0, cc}; + endfunction + + function [13:0] rows(input [6:0] n); // n whole rows of cells + rows = {n, 7'b0} + {5'b0, n, 2'b0}; + endfunction + + function [7:0] acc(input [7:0] p, input [7:0] d); + reg [11:0] v; + begin + v = p * 10 + (d - "0"); + acc = v > 255 ? 8'd255 : v[7:0]; + end + endfunction + + // DEC special graphics to CP437 + function [7:0] gfx(input [7:0] ch); + case (ch) + 8'h5F: gfx = 8'h20; 8'h60: gfx = 8'h04; 8'h61: gfx = 8'hB1; + 8'h66: gfx = 8'hF8; 8'h67: gfx = 8'hF1; 8'h6A: gfx = 8'hD9; + 8'h6B: gfx = 8'hBF; 8'h6C: gfx = 8'hDA; 8'h6D: gfx = 8'hC0; + 8'h6E: gfx = 8'hC5; 8'h6F: gfx = 8'hC4; 8'h70: gfx = 8'hC4; + 8'h71: gfx = 8'hC4; 8'h72: gfx = 8'hC4; 8'h73: gfx = 8'hC4; + 8'h74: gfx = 8'hC3; 8'h75: gfx = 8'hB4; 8'h76: gfx = 8'hC1; + 8'h77: gfx = 8'hC2; 8'h78: gfx = 8'hB3; 8'h79: gfx = 8'hF3; + 8'h7A: gfx = 8'hF2; 8'h7B: gfx = 8'hE3; 8'h7C: gfx = 8'hD8; + 8'h7D: gfx = 8'h9C; 8'h7E: gfx = 8'hFA; + default: gfx = 8'hFE; // control-code pictures + endcase + endfunction + + function [1:0] charset(input [7:0] ch); + charset = ch == "0" ? 2'd1 : ch == "A" ? 2'd2 : 2'd0; + endfunction + + // colour index from levels: bit0 red, bit1 green, bit2 blue, bit3 bright + function [3:0] approx(input hr, input hg, input hb, input bright, input dim); + approx = (hr | hg | hb) ? {bright, hb, hg, hr} : (dim ? 4'd8 : 4'd0); + endfunction + + function [3:0] map256(input [7:0] n); + reg [7:0] k; + reg [2:0] r, g, b, mx; + begin + if (n < 16) + map256 = n[3:0]; + else if (n >= 232) + map256 = n < 238 ? 4'd0 : n < 244 ? 4'd8 : n < 250 ? 4'd7 : 4'd15; + else begin + k = n - 8'd16; + r = k / 36; + g = (k / 6) % 6; + b = k % 6; + mx = r > g ? (r > b ? r : b) : (g > b ? g : b); + map256 = approx(r >= 3, g >= 3, b >= 3, mx >= 4, mx >= 2); + end + end + endfunction + + function [3:0] rgb16(input [7:0] r, input [7:0] g, input [7:0] b); + reg [7:0] mx; + begin + mx = r > g ? (r > b ? r : b) : (g > b ? g : b); + rgb16 = approx(r[7], g[7], b[7], mx >= 192, mx >= 64); + end + endfunction + + function [7:0] next_tab(input [131:0] t, input [7:0] cc, input [7:0] last); + integer k; + begin + next_tab = last; + for (k = 131; k >= 0; k = k - 1) + if (k > cc && k < last && t[k]) next_tab = k; + end + endfunction + + function [7:0] prev_tab(input [131:0] t, input [7:0] cc); + integer k; + begin + prev_tab = 8'd0; + for (k = 0; k < 132; k = k + 1) + if (k < cc && t[k]) prev_tab = k; + end + endfunction + + // --------------------------------------------------- derived values + wire [17:0] BLANK = {2'b00, 4'd0, def_fg, 8'h20}; + wire [7:0] p0 = par[0]; + wire [7:0] p1 = par[1]; + reg [7:0] n8; // count parameter (default 1), registered + reg [7:0] nc; // ... clamped to the rest of the line + wire [7:0] room = NCOLS - col; // cells from cursor to end of line + wire [7:0] n8_c = p0 == 0 ? 8'd1 : p0; + always @(posedge clk) begin + n8 <= n8_c; + nc <= n8_c > room ? room : n8_c; + end + + wire [3:0] fgb = bold ? (fg | 4'd8) : fg; + wire [3:0] dfg = rev ? bg : fgb; + wire [3:0] dbg = rev ? fgb : bg; + wire [1:0] cs = gl ? g1 : g0; + wire [7:0] glyph = (cs == 2'd1 && c >= 8'h5F && c <= 8'h7E) ? gfx(c) : + (cs == 2'd2 && c == "#") ? 8'h9C : c; + wire [17:0] new_cell = {blink, ul, dbg, conceal ? dbg : dfg, glyph}; + + wire smooth = sclm | smooth_sw; + wire [4:0] sm_step = smooth_fast ? 5'd4 : 5'd2; + + wire [5:0] up_lim = row >= stop ? stop : 6'd0; + wire [5:0] dn_lim = row <= sbot ? sbot : LAST_ROW; + wire [5:0] row_up = (row - up_lim > n8) ? row - n8 : up_lim; + wire [5:0] row_dn = (dn_lim - row > n8) ? row + n8 : dn_lim; + wire [7:0] col_rt = (LAST_COL - col > n8) ? col + n8 : LAST_COL; + wire [7:0] col_lt = (col > n8) ? col - n8 : 8'd0; + + wire [7:0] r_rel = p0 == 0 ? 8'd0 : p0 - 1'b1; + wire [8:0] r_abs = (om ? stop : 6'd0) + r_rel; + wire [5:0] r_max = om ? sbot : LAST_ROW; + wire [5:0] row_p0 = r_abs > r_max ? r_max : r_abs[5:0]; + wire [7:0] col_p0 = p0 == 0 ? 8'd0 : p0 > NCOLS ? LAST_COL : p0 - 1'b1; + wire [7:0] col_p1 = p1 == 0 ? 8'd0 : p1 > NCOLS ? LAST_COL : p1 - 1'b1; + + wire [13:0] here = rc(row, col); + wire [6:0] rep_row = (om ? row - stop : row) + 1'b1; + wire [7:0] rep_col = col + 1'b1; + reg [7:0] pv; // parameter being processed, registered + reg pv_ok; + + // ------------------------------------------------------------ tasks + task op(input [13:0] src, input [13:0] dst, input [13:0] ccnt, input dir, + input [13:0] fa, input [13:0] fcnt, input [17:0] fcell, input [3:0] rs); + begin + c_src <= src; c_dst <= dst; c_cnt <= ccnt; c_dir <= dir; + f_addr <= fa; f_cnt <= fcnt; f_cell <= fcell; + ret_st <= rs; + st <= S_OP; // decided next clock, off the critical path + end + endtask + + task fill(input [13:0] fa, input [13:0] fcnt); + op(14'd0, 14'd0, 14'd0, 1'b0, fa, fcnt, BLANK, S_IDLE); + endtask + + // scroll rows t..b up (dir 0) or down (dir 1) by n lines + // scroll rows t..b up (dir 0) or down (dir 1) by n lines; the copy and fill + // ranges are worked out over the next two clocks (S_SCR1, S_SCR2) + task scroll(input dir, input [5:0] t, input [5:0] b, input [7:0] n, input [3:0] rs); + begin + sc_dir <= dir; + sc_t <= t; + sc_b <= b; + sc_n <= n; + ret_st <= rs; + st <= S_SCR1; + end + endtask + + task line_feed(input [3:0] rs); + begin + if (row == sbot) begin + if (smooth) begin + sm_on <= 1'b1; sm_dir <= 1'b0; sm_off <= 5'd0; sm_ret <= rs; + st <= S_SMOOTH; + end else + scroll(1'b0, stop, sbot, 8'd1, rs); + end else begin + if (row != LAST_ROW) row <= row + 1'b1; + st <= rs; + end + end + endtask + + task reverse_index; + begin + if (row == stop) begin + if (smooth) begin + sm_on <= 1'b1; sm_dir <= 1'b1; sm_off <= 5'd0; sm_ret <= S_IDLE; + st <= S_SMOOTH; + end else + scroll(1'b1, stop, sbot, 8'd1, S_IDLE); + end else if (row != 0) + row <= row - 1'b1; + end + endtask + + task reset_attrs; + begin + {bold, ul, blink, rev, conceal} <= 5'b0; + fg <= def_fg; + bg <= 4'd0; + end + endtask + + task soft_reset; + begin + reset_attrs; + {pend, irm, om, cursor_app, keypad_app, gl} <= 6'b0; + {g0, g1} <= 4'b0; + awm <= 1'b1; + cur_vis <= 1'b1; + alt_scr <= 1'b0; + stop <= 6'd0; + sbot <= LAST_ROW; + {sv_row, sv_col, sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal} <= 0; + {sv_g0, sv_g1, sv_bg} <= 0; + sv_fg <= def_fg; + end + endtask + + task full_reset; + begin + soft_reset; + {row, col} <= 0; + {sclm, lnm, wide, colm_clr} <= 4'b0; + sbot <= 6'd31; + dec_leds <= 4'd0; + sm_on <= 1'b0; + sm_off <= 5'd0; + ps <= P_NORM; + for (i = 0; i < 132; i = i + 1) tabs[i] <= i != 0 && i % 8 == 0; + fill(14'd0, ALL); + end + endtask + + task respond(input [95:0] s, input [3:0] n); + begin + rbuf <= s; + rlen <= n; + st <= S_RESP; + end + endtask + + function [7:0] tens(input [7:0] v); + tens = "0" + (v / 8'd10) % 8'd10; + endfunction + + function [7:0] ones(input [7:0] v); + ones = "0" + v % 8'd10; + endfunction + + // ESC [ rr ; cc R, or ESC [ rr ; 1cc R past column 99 + task cursor_report; + if (rep_col >= 100) + respond({8'h1B, "[", tens(rep_row), ones(rep_row), ";", "1", + tens(rep_col), ones(rep_col), "R", 24'd0}, 4'd9); + else + respond({8'h1B, "[", tens(rep_row), ones(rep_row), ";", + tens(rep_col), ones(rep_col), "R", 32'd0}, 4'd8); + endtask + + // one SGR parameter + task sgr(input [7:0] v); + begin + case (ext) + 2'd0: + if (v == 0) reset_attrs; + else if (v == 1) bold <= 1'b1; + else if (v == 4 || v == 21) ul <= 1'b1; + else if (v == 5 || v == 6) blink <= 1'b1; + else if (v == 7) rev <= 1'b1; + else if (v == 8) conceal <= 1'b1; + else if (v == 22) bold <= 1'b0; + else if (v == 24) ul <= 1'b0; + else if (v == 25) blink <= 1'b0; + else if (v == 27) rev <= 1'b0; + else if (v == 28) conceal <= 1'b0; + else if (v >= 30 && v <= 37) fg <= v - 8'd30; + else if (v == 38 || v == 48) begin ext <= 2'd1; ext_bg <= v == 48; end + else if (v == 39) fg <= def_fg; + else if (v >= 40 && v <= 47) bg <= v - 8'd40; + else if (v == 49) bg <= 4'd0; + else if (v >= 90 && v <= 97) fg <= v - 8'd82; + else if (v >= 100 && v <= 107) bg <= v - 8'd92; + 2'd1: // after 38/48: 5 = indexed, 2 = RGB + if (v == 5) ext <= 2'd2; + else if (v == 2) begin ext <= 2'd3; ext_n <= 2'd0; end + else ext <= 2'd0; + 2'd2: begin + if (ext_bg) bg <= map256(v); else fg <= map256(v); + ext <= 2'd0; + end + 2'd3: begin + ext_n <= ext_n + 1'b1; + if (ext_n == 0) ext_r <= v; + else if (ext_n == 1) ext_g <= v; + else begin + if (ext_bg) bg <= rgb16(ext_r, ext_g, v); else fg <= rgb16(ext_r, ext_g, v); + ext <= 2'd0; + end + end + endcase + end + endtask + + // one SM/RM parameter + task set_mode(input [7:0] v, input on); + begin + if (priv) begin + if (v == 1) cursor_app <= on; + if (v == 3) begin // DECCOLM: 80x32 / 132x64, cleared + wide <= on; colm_clr <= 1'b1; + {row, col, pend, om, stop} <= 0; + sbot <= on ? 6'd63 : 6'd31; + end + if (v == 4) sclm <= on; + if (v == 6) begin om <= on; row <= on ? stop : 6'd0; col <= 8'd0; pend <= 1'b0; end + if (v == 7) awm <= on; + if (v == 25) cur_vis <= on; + if (v == 47) alt_scr <= on; + end else begin + if (v == 4) irm <= on; + if (v == 20) lnm <= on; + end + end + endtask + + task plist(input [1:0] kind); + begin + pk <= kind; + pi <= 4'd0; + ext <= 2'd0; + pv_ok <= 1'b0; + st <= S_PLOOP; + end + endtask + + // ------------------------------------------------------------ main + always @(posedge clk) begin + in_rd <= 1'b0; + we <= 1'b0; + bell <= 1'b0; + resp_wr <= 1'b0; + if (rst) begin + full_reset; + cursor_app <= 1'b0; + end else case (st) + S_IDLE: + if (clear_req || colm_clr) begin + {row, col, pend, colm_clr} <= 0; + fill(14'd0, ALL); + end else if (!in_empty && !in_rd) begin + c <= in_byte; + in_rd <= 1'b1; + st <= S_DISP; + end + + // ---- scroll: size the move, then set up the copy and fill + S_SCR1: begin + sc_h <= sc_b - sc_t + 1'b1; + sc_k <= sc_n > sc_b - sc_t ? sc_b - sc_t + 1'b1 : sc_n[6:0]; + st <= S_SCR2; + end + S_SCR2: + if (!sc_dir) + op(rc(sc_t + sc_k, 0), rc(sc_t, 0), rows(sc_h - sc_k), 1'b0, + rc(sc_b - sc_k + 1'b1, 0), rows(sc_k), BLANK, ret_st); + else + op(rc(sc_b - sc_k + 1'b1, 0) - 1'b1, rc(sc_b + 1'b1, 0) - 1'b1, rows(sc_h - sc_k), 1'b1, + rc(sc_t, 0), rows(sc_k), BLANK, ret_st); + + // ---- copy c_cnt cells, then fill f_cnt cells, then go to ret_st + S_OP: + st <= c_cnt != 0 ? S_CRD : f_cnt != 0 ? S_FILL : ret_st; + S_CRD: begin + addr <= c_src; + st <= S_CWAIT; + end + S_CWAIT: + st <= S_CWR; + S_CWR: begin + addr <= c_dst; + wdata <= rdata; + we <= 1'b1; + c_src <= c_dir ? c_src - 1'b1 : c_src + 1'b1; + c_dst <= c_dir ? c_dst - 1'b1 : c_dst + 1'b1; + c_cnt <= c_cnt - 1'b1; + st <= c_cnt != 1 ? S_CRD : f_cnt != 0 ? S_FILL : ret_st; + end + S_FILL: begin + addr <= f_addr; + wdata <= f_cell; + we <= 1'b1; + f_addr <= f_addr + 1'b1; + f_cnt <= f_cnt - 1'b1; + if (f_cnt == 1) st <= ret_st; + end + + S_SMOOTH: + // the region slides during active video; the copy runs in blanking + if (frame_tick) begin + if (sm_off + sm_step >= 16) + scroll(sm_dir, stop, sbot, 8'd1, S_SMEND); + else + sm_off <= sm_off + sm_step; + end + S_SMEND: begin + sm_on <= 1'b0; + sm_off <= 5'd0; + st <= sm_ret; + end + + S_RESP: + if (!resp_full) begin + resp_byte <= rbuf[95:88]; + resp_wr <= 1'b1; + rbuf <= rbuf << 8; + rlen <= rlen - 1'b1; + if (rlen == 1) st <= S_IDLE; + end + + S_TAB: begin + col <= tdir ? prev_tab(tabs, col) : next_tab(tabs, col, LAST_COL); + rep <= rep - 1'b1; + if (rep == 1) st <= S_IDLE; + end + + S_PLOOP: if (!pv_ok) begin + // fetch the parameter one clock ahead, then act on it + pv <= par[pi]; + pv_ok <= 1'b1; + end else begin + pv_ok <= 1'b0; + case (pk) + K_SGR: sgr(pv); + K_SET: set_mode(pv, 1'b1); + K_RST: set_mode(pv, 1'b0); + K_LL: + if (pv == 0) dec_leds <= 4'd0; + else if (pv >= 1 && pv <= 4) dec_leds[pv - 1] <= 1'b1; + else if (pv >= 21 && pv <= 24) dec_leds[pv - 21] <= 1'b0; + endcase + pi <= pi + 1'b1; + if (pi == pidx) st <= S_IDLE; + end + + S_PUT: begin // write the character at the cursor + we <= 1'b1; + addr <= here; + wdata <= new_cell; + if (col == LAST_COL) pend <= awm; + else col <= col + 1'b1; + st <= S_IDLE; + end + + S_DISP: begin + st <= S_IDLE; + if (ps == P_STR) begin + // inside OSC/DCS/APC/PM/SOS: discard until BEL or ESC \ (ST) + if (c == 8'h07 || c == 8'h18 || c == 8'h1A) ps <= P_NORM; + else if (c == 8'h1B) ps <= P_ESC; + end else if (c == 8'h1B) begin + ps <= P_ESC; + end else if (c == 8'h18 || c == 8'h1A) begin + ps <= P_NORM; // CAN / SUB cancel a sequence + end else if (c < 8'h20) begin + // C0 controls act immediately, even inside an escape sequence + case (c) + 8'h07: bell <= 1'b1; + 8'h08: begin pend <= 1'b0; if (col != 0) col <= col - 1'b1; end + 8'h09: begin pend <= 1'b0; col <= next_tab(tabs, col, LAST_COL); end + 8'h0A, 8'h0B, 8'h0C: begin + pend <= 1'b0; + if (lf_cr || lnm) col <= 8'd0; + line_feed(S_IDLE); + end + 8'h0D: begin pend <= 1'b0; col <= 8'd0; end + 8'h0E: gl <= 1'b1; + 8'h0F: gl <= 1'b0; + default: ; + endcase + end else if (c == 8'h7F) begin + // DEL is ignored + end else case (ps) + P_NORM: + if (pend && awm) begin + pend <= 1'b0; + col <= 8'd0; + line_feed(S_DISP); // wrap, then print this byte + end else if (irm && col != LAST_COL) + // insert mode: shift the rest of the line right first + op(rc(row, LAST_COL - 1'b1), rc(row, LAST_COL), {6'd0, LAST_COL - col}, 1'b1, + 14'd0, 14'd0, BLANK, S_PUT); + else + st <= S_PUT; + + P_ESC: begin + ps <= P_NORM; + if (c >= 8'h20 && c <= 8'h2F) begin + inter <= c; + ps <= P_ESCI; + end else case (c) + "]", "P", "_", "^", "X": + ps <= P_STR; // string sequences are ignored + "[": begin + ps <= P_CSI; + for (i = 0; i < 16; i = i + 1) par[i] <= 8'd0; + {pidx, priv, gtm, ign} <= 0; + cint <= 8'd0; + end + "D": begin pend <= 1'b0; line_feed(S_IDLE); end + "E": begin pend <= 1'b0; col <= 8'd0; line_feed(S_IDLE); end + "M": begin pend <= 1'b0; reverse_index; end + "H": tabs[col] <= 1'b1; + "7": begin + {sv_row, sv_col, sv_pend, sv_om, sv_gl} <= {row, col, pend, om, gl}; + {sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal} <= {bold, ul, blink, rev, conceal}; + {sv_fg, sv_bg, sv_g0, sv_g1} <= {fg, bg, g0, g1}; + end + "8": begin + {row, col, pend, om, gl} <= {sv_row, sv_col, sv_pend, sv_om, sv_gl}; + {bold, ul, blink, rev, conceal} <= {sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal}; + {fg, bg, g0, g1} <= {sv_fg, sv_bg, sv_g0, sv_g1}; + end + "=": keypad_app <= 1'b1; + ">": keypad_app <= 1'b0; + "Z": respond({8'h1B, "[?62;22c", 24'd0}, 4'd9); + "c": begin full_reset; cursor_app <= 1'b0; end + default: ; + endcase + end + + P_ESCI: begin + ps <= P_NORM; + if (c >= 8'h20 && c <= 8'h2F) + ps <= P_ESCI; // further intermediates + else case (inter) + "(": g0 <= charset(c); + ")": g1 <= charset(c); + "#": if (c == "8") begin // DECALN: fill the screen with E + {row, col, pend, stop} <= 0; + sbot <= LAST_ROW; + op(14'd0, 14'd0, 14'd0, 1'b0, 14'd0, CELLS, {2'b00, 4'd0, def_fg, "E"}, S_IDLE); + end + default: ; + endcase + end + + P_CSI: + if (c >= "0" && c <= "9") + par[pidx] <= acc(par[pidx], c); + else if (c == ";" || c == ":") begin + if (pidx != 4'd15) pidx <= pidx + 1'b1; + end else if (c == "?") + priv <= 1'b1; + else if (c == ">") + gtm <= 1'b1; + else if (c == "<" || c == "=") + ign <= 1'b1; + else if (c >= 8'h20 && c <= 8'h2F) + cint <= c; + else if (c >= 8'h40 && c <= 8'h7E) begin + ps <= P_NORM; + st <= S_EXEC; // run it next clock, off the parser's path + end + default: ps <= P_NORM; + endcase + end + + // ---- CSI final byte (in c): parameters and cursor are unchanged + S_EXEC: begin + st <= S_IDLE; + if (ign) begin + end else if (cint == "!") begin + if (c == "p") soft_reset; + end else if (cint != 0) begin + end else if (gtm) begin + if (c == "c") respond({8'h1B, "[>1;10;0c", 16'd0}, 4'd10); + end else if (priv) begin + case (c) + "h": plist(K_SET); + "l": plist(K_RST); + "J": begin + pend <= 1'b0; + if (p0 == 0) fill(here, CELLS - here); + else if (p0 == 1) fill(14'd0, here + 1'b1); + else if (p0 == 2) fill(14'd0, CELLS); + end + "K": begin + pend <= 1'b0; + if (p0 == 0) fill(here, room); + else if (p0 == 1) fill(rc(row, 0), col + 1'b1); + else if (p0 == 2) fill(rc(row, 0), STRIDE); + end + "n": if (p0 == 6) cursor_report; + default: ; + endcase + end else case (c) + "A": begin pend <= 1'b0; row <= row_up; end + "B", "e": begin pend <= 1'b0; row <= row_dn; end + "C", "a": begin pend <= 1'b0; col <= col_rt; end + "D": begin pend <= 1'b0; col <= col_lt; end + "E": begin pend <= 1'b0; row <= row_dn; col <= 8'd0; end + "F": begin pend <= 1'b0; row <= row_up; col <= 8'd0; end + "G", "`": begin pend <= 1'b0; col <= col_p0; end + "d": begin pend <= 1'b0; row <= row_p0; end + "H", "f": begin pend <= 1'b0; row <= row_p0; col <= col_p1; end + "I": begin pend <= 1'b0; rep <= n8; tdir <= 1'b0; st <= S_TAB; end + "Z": begin pend <= 1'b0; rep <= n8; tdir <= 1'b1; st <= S_TAB; end + "J": begin + pend <= 1'b0; + if (p0 == 0) fill(here, CELLS - here); + else if (p0 == 1) fill(14'd0, here + 1'b1); + else if (p0 == 2 || p0 == 3) fill(14'd0, CELLS); + end + "K": begin + pend <= 1'b0; + if (p0 == 0) fill(here, room); + else if (p0 == 1) fill(rc(row, 0), col + 1'b1); + else if (p0 == 2) fill(rc(row, 0), STRIDE); + end + "L": if (row >= stop && row <= sbot) begin + pend <= 1'b0; col <= 8'd0; + scroll(1'b1, row, sbot, n8, S_IDLE); + end + "M": if (row >= stop && row <= sbot) begin + pend <= 1'b0; col <= 8'd0; + scroll(1'b0, row, sbot, n8, S_IDLE); + end + "@": begin + pend <= 1'b0; + op(rc(row, LAST_COL - nc), rc(row, LAST_COL), {6'd0, room - nc}, 1'b1, + here, {6'd0, nc}, BLANK, S_IDLE); + end + "P": begin + pend <= 1'b0; + op(rc(row, col + nc), here, {6'd0, room - nc}, 1'b0, + rc(row, NCOLS - nc), {6'd0, nc}, BLANK, S_IDLE); + end + "X": begin pend <= 1'b0; fill(here, {6'd0, nc}); end + "S": scroll(1'b0, stop, sbot, n8, S_IDLE); + "T": scroll(1'b1, stop, sbot, n8, S_IDLE); + "g": if (p0 == 0) tabs[col] <= 1'b0; else if (p0 == 3) tabs <= 132'd0; + "h": plist(K_SET); + "l": plist(K_RST); + "m": plist(K_SGR); + "q": plist(K_LL); + "r": begin + if ((p0 == 0 ? 8'd1 : p0) < (p1 == 0 || p1 > NROWS ? {1'b0, NROWS} : p1)) begin + stop <= p0 == 0 ? 6'd0 : p0 - 1'b1; + sbot <= p1 == 0 || p1 > NROWS ? LAST_ROW : p1 - 1'b1; + row <= om ? (p0 == 0 ? 6'd0 : p0 - 1'b1) : 6'd0; + col <= 8'd0; + pend <= 1'b0; + end + end + "s": {sv_row, sv_col, sv_pend} <= {row, col, pend}; + "u": {row, col, pend} <= {sv_row, sv_col, sv_pend}; + "n": if (p0 == 5) respond({8'h1B, "[0n", 64'd0}, 4'd4); + else if (p0 == 6) cursor_report; + "c": if (p0 == 0) respond({8'h1B, "[?62;22c", 24'd0}, 4'd9); + default: ; + endcase + end + default: st <= S_IDLE; + endcase + end +endmodule diff --git a/rtl/text_display.v b/rtl/text_display.v new file mode 100644 index 0000000..e1336d6 --- /dev/null +++ b/rtl/text_display.v @@ -0,0 +1,245 @@ +`timescale 1ns / 1ps + +// 1280x1024 @ 60 Hz VGA text display (108 MHz pixel clock), two layouts: +// 80 columns: 80x32 cells of 16x32 pixels (the 8x16 font doubled) +// 132 columns: 132x64 cells of 8x16 pixels, centred (112-pixel side borders) +// 16 colours, underline, blink, block cursor and smooth-scroll offset for the +// scroll region. The character buffer has a 132-cell stride in both layouts. +// Hardware sprites (sprites.v) sit between the graphics and the text. +// A 320x240 graphics layer (each pixel 4x4, the top 960 lines, so 80-column +// text row r still starts at graphics line 8(r-1)) shows through wherever the +// text is background; colour 0 is transparent. It scrolls: the picture starts +// at (scroll_x, scroll_y) of the buffer and wraps round at 320 and 240. With +// g_border the graphics are hidden in a border (4 columns each side, 2 rows +// top and bottom), where a scrolling program can draw what comes next unseen. +// One pixel per clock, pipelined: +// clock 0 position -> row, column, glyph line (registered) +// clock 1 character RAM and graphics reads +// clock 2 font ROM read +// clock 3 colour out +module text_display #( + parameter FONT_FILE = "font.mem" +) ( + input clk, // pixel clock, 108 MHz + input rst, + input wide, // 132-column layout + input [5:0] cur_row, + input [7:0] cur_col, + input cur_vis, + input [5:0] stop, // scroll region (rows, inclusive) + input [5:0] sbot, + input sm_on, // smooth scroll in progress + input sm_dir, // 0 = up, 1 = down + input [4:0] sm_off, // font lines the region has moved + output [13:0] ram_addr, // row * 132 + column + input [17:0] ram_data, // {blink, underline, bg, fg, code} + output [16:0] gfx_addr, // graphics pixel, read a clock later + input [3:0] gfx_pix, + input [8:0] scroll_x, // graphics pixel shown at the top left + input [7:0] scroll_y, + input g_border, // hide 4 graphics columns each side, 2 rows top and bottom + // sprites: the line to prepare next, and the pixel on screen + output reg sp_go, + output reg [7:0] sp_line, + output sp_buf, + output [8:0] sp_x, + output sp_on, + input [3:0] sp_pix, // read a clock after sp_x, like gfx_pix + output reg [3:0] red, + output reg [3:0] green, + output reg [3:0] blue, + output reg hsync, + output reg vsync, + output reg frame_tick // one clock at the start of vertical blanking +); + localparam H_VIS = 1280, H_FP = 48, H_SYNC = 112, H_TOTAL = 1688; + localparam V_VIS = 1024, V_FP = 1, V_SYNC = 3, V_TOTAL = 1066; + localparam WIDE_X0 = 112; // 132 x 8 = 1056 pixels, centred + + reg [10:0] h, v; + reg [5:0] frame = 6'd0; + + always @(posedge clk) begin + frame_tick <= h == 0 && v == V_VIS; + // each graphics line is 4 scan lines; ask for the next one as it starts + sp_go <= h == 0 && v[1:0] == 2'd0 && (v < 11'd956 || v == 11'd1064); + sp_line <= v == 11'd1064 ? 8'd0 : v[9:2] + 1'b1; + if (rst) begin + h <= 0; + v <= 0; + end else if (h == H_TOTAL - 1) begin + h <= 0; + if (v == V_TOTAL - 1) begin + v <= 0; + frame <= frame + 1'b1; + end else + v <= v + 1'b1; + end else + h <= h + 1'b1; + end + + // graphics pixel for this h, v with the scroll added: counters set from + // the scroll registers at the end of each line and each frame + reg [8:0] g_col = 9'd0; + reg [7:0] g_row = 8'd0; + reg [1:0] g_sub = 2'd0; + always @(posedge clk) + if (h == H_TOTAL - 1) begin + g_col <= scroll_x; + g_sub <= 2'd0; + if (v == V_TOTAL - 1) g_row <= scroll_y; + else if (v[1:0] == 2'd3) g_row <= g_row == 8'd239 ? 8'd0 : g_row + 1'b1; + end else begin + g_sub <= g_sub + 1'b1; + if (g_sub == 2'd3) g_col <= g_col >= 9'd319 ? 9'd0 : g_col + 1'b1; + end + + // ---- clock 0: where this pixel is in the text, in font units + // yl counts font lines (a 16-line font: 32 pixels a row in 80 columns) + wire [9:0] yl = wide ? v[9:0] : {1'b0, v[9:1]}; + wire [10:0] xw = h - WIDE_X0; + wire [10:0] xl = wide ? xw : {1'b0, h[10:1]}; // font pixels across + wire text_on = wide ? h >= WIDE_X0 && h < WIDE_X0 + 1056 : 1'b1; + wire in_region = sm_on && v < V_VIS && yl[9:4] >= stop && yl[9:4] <= sbot; + wire [9:0] ys = !in_region ? yl : sm_dir ? yl - sm_off : yl + sm_off; + wire gap = in_region && (sm_dir ? yl < {stop, 4'b0} + sm_off : ys[9:4] > sbot); + wire [7:0] tcol = xl[10:3]; + wire [5:0] trow = ys[9:4]; + + reg [13:0] a_base; // row * 132 + reg [7:0] a_col; + reg [3:0] a_line; + reg [2:0] a_bit; + reg a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon, a_ghide; + wire [8:0] gcol_s = h[10:2]; // graphics pixel on the screen, unscrolled + wire [7:0] grow_s = v[9:2]; + reg [16:0] a_gfx; + reg [8:0] a_spx; + reg a_spbuf; + always @(posedge clk) begin + a_base <= {trow, 7'd0} + {6'd0, trow, 2'd0}; + a_col <= tcol; + a_line <= ys[3:0]; + a_bit <= xl[2:0]; + a_blank <= gap; + a_text <= text_on; + a_vis <= h < H_VIS && v < V_VIS; + a_cur <= cur_vis && frame[5] && tcol == cur_col && ys[9:4] == cur_row && !gap; + a_hs <= h >= H_VIS + H_FP && h < H_VIS + H_FP + H_SYNC; // positive sync + a_vs <= v >= V_VIS + V_FP && v < V_VIS + V_FP + V_SYNC; + a_gon <= v < 960; + a_ghide <= g_border && (gcol_s < 9'd4 || gcol_s >= 9'd316 || grow_s < 8'd2 || grow_s >= 8'd238); + a_gfx <= {1'b0, g_row, 8'd0} + {3'd0, g_row, 6'd0} + {8'd0, g_col}; + a_spx <= h[10:2]; + a_spbuf <= v[2]; + end + + // ---- clock 1: character RAM and graphics reads + assign ram_addr = a_base + {6'd0, a_col}; + assign gfx_addr = a_gfx; + assign sp_x = a_spx; + assign sp_buf = a_spbuf; + assign sp_on = a_gon; + reg [3:0] b_line; + reg [2:0] b_bit; + reg b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon, b_ghide; + always @(posedge clk) + {b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon, b_ghide} <= + {a_line, a_bit, a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon, a_ghide}; + + // ---- clock 2: font ROM + reg [7:0] font [0:4095]; + initial $readmemh(FONT_FILE, font); + reg [7:0] glyph; + reg [17:0] c_cell; + reg [3:0] c_gfx, c_spr, c_line; + reg [2:0] c_bit; + reg c_blank, c_text, c_vis, c_cur, c_hs, c_vs; + always @(posedge clk) begin + glyph <= font[{ram_data[7:0], b_line}]; + c_cell <= ram_data; + c_gfx <= b_gon && !b_ghide ? gfx_pix : 4'd0; + c_spr <= sp_pix; + {c_line, c_bit, c_blank, c_text, c_vis, c_cur, c_hs, c_vs} <= + {b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs}; + end + + function [11:0] palette(input [3:0] n); + case (n) + 4'd0: palette = 12'h000; 4'd1: palette = 12'hA00; + 4'd2: palette = 12'h0A0; 4'd3: palette = 12'hA50; + 4'd4: palette = 12'h00A; 4'd5: palette = 12'hA0A; + 4'd6: palette = 12'h0AA; 4'd7: palette = 12'hAAA; + 4'd8: palette = 12'h555; 4'd9: palette = 12'hF55; + 4'd10: palette = 12'h5F5; 4'd11: palette = 12'hFF5; + 4'd12: palette = 12'h55F; 4'd13: palette = 12'hF5F; + 4'd14: palette = 12'h5FF; 4'd15: palette = 12'hFFF; + endcase + endfunction + + // ---- clock 3: colour + wire ink = (glyph[~c_bit] | (c_cell[16] && c_line == 4'd15)) && !(c_cell[17] && frame[5]); + wire fg = c_text && !c_blank && (ink ^ c_cur); + wire [3:0] idx = fg ? c_cell[11:8] : c_spr != 4'd0 ? c_spr : c_gfx != 4'd0 ? c_gfx : + c_blank || !c_text ? 4'd0 : c_cell[15:12]; + always @(posedge clk) begin + {red, green, blue} <= c_vis ? palette(idx) : 12'h000; + hsync <= c_hs; + vsync <= c_vs; + end +endmodule + +// Two character buffers of 132x64 cells (the normal and the alternate screen, +// picked by a_alt/b_alt): read/write port for the terminal engine, read-only +// port for video on the pixel clock. +module char_ram ( + input clk, + input a_alt, + input [13:0] a_addr, + input a_we, + input [17:0] a_wdata, + output [17:0] a_rdata, + input vclk, + input b_alt, + input [13:0] b_addr, + output [17:0] b_rdata +); + // Two pages of 132 x 64 cells: 16896, just past 16K. Kept as a 16K array + // and a 512-entry one, so it takes about 9.5 block RAMs rather than 18 + // (one array of 16896 would be built as 32K deep). + localparam PAGE = 132 * 64; + (* ram_style = "block" *) reg [17:0] lo [0:16383]; + (* ram_style = "block" *) reg [17:0] hi [0:2 * PAGE - 16384 - 1]; + integer i; + initial begin + for (i = 0; i < 16384; i = i + 1) lo[i] = {10'h00A, 8'h20}; + for (i = 0; i < 2 * PAGE - 16384; i = i + 1) hi[i] = {10'h00A, 8'h20}; + end + + wire [14:0] aa = {1'b0, a_addr} + (a_alt ? PAGE : 0); + wire [14:0] ba = {1'b0, b_addr} + (b_alt ? PAGE : 0); + reg [17:0] a_lo, a_hi, b_lo, b_hi; + reg a_sel, b_sel; + always @(posedge clk) begin + if (a_we && !aa[14]) lo[aa[13:0]] <= a_wdata; + a_lo <= lo[aa[13:0]]; + end + always @(posedge clk) begin + if (a_we && aa[14]) hi[aa[8:0]] <= a_wdata; + a_hi <= hi[aa[8:0]]; + a_sel <= aa[14]; + end + assign a_rdata = a_sel ? a_hi : a_lo; + + always @(posedge vclk) begin + b_lo <= lo[ba[13:0]]; + b_hi <= hi[ba[8:0]]; + b_sel <= ba[14]; + end + assign b_rdata = b_sel ? b_hi : b_lo; + + // whole-array view for testbenches + function [17:0] cell_at(input [14:0] n); + cell_at = n[14] ? hi[n[8:0]] : lo[n[13:0]]; + endfunction +endmodule diff --git a/rtl/uart.v b/rtl/uart.v new file mode 100644 index 0000000..8f562a2 --- /dev/null +++ b/rtl/uart.v @@ -0,0 +1,106 @@ +`timescale 1ns / 1ps + +// 8N1 UART receiver and transmitter. div = clock frequency / baud rate. + +module uart_rx ( + input clk, + input rst, + input [13:0] div, + input rx, + output reg [7:0] data, + output reg valid +); + localparam IDLE = 3'd0, START = 3'd1, DATA = 3'd2, STOP = 3'd3, BREAK = 3'd4; + + reg [2:0] sync = 3'b111; + reg [2:0] st; + reg [13:0] cnt; + reg [2:0] bitn; + reg [7:0] sh; + wire rxs = sync[2]; + + always @(posedge clk) sync <= {sync[1:0], rx}; + + always @(posedge clk) begin + valid <= 1'b0; + if (rst) begin + st <= IDLE; + end else case (st) + IDLE: + if (!rxs) begin + st <= START; + cnt <= {1'b0, div[13:1]}; // sample mid-bit + end + START: + if (cnt == 0) begin + if (!rxs) begin + st <= DATA; + cnt <= div - 1'b1; + bitn <= 3'd0; + end else + st <= IDLE; // glitch, not a start bit + end else + cnt <= cnt - 1'b1; + DATA: + if (cnt == 0) begin + sh <= {rxs, sh[7:1]}; + cnt <= div - 1'b1; + bitn <= bitn + 1'b1; + if (bitn == 3'd7) st <= STOP; + end else + cnt <= cnt - 1'b1; + STOP: + if (cnt == 0) begin + if (rxs) begin + data <= sh; + valid <= 1'b1; + st <= IDLE; + end else + st <= BREAK; // bad stop bit: drop it + end else + cnt <= cnt - 1'b1; + BREAK: + if (rxs) st <= IDLE; // wait for the line to go idle + default: + st <= IDLE; + endcase + end +endmodule + +module uart_tx ( + input clk, + input rst, + input [13:0] div, + input [7:0] data, + input start, + output reg tx = 1'b1, + output reg busy +); + reg [9:0] sh; + reg [3:0] n; + reg [13:0] cnt; + + always @(posedge clk) begin + if (rst) begin + tx <= 1'b1; + busy <= 1'b0; + end else if (!busy) begin + if (start) begin + sh <= {1'b1, data, 1'b0}; + n <= 4'd0; + cnt <= 14'd0; + busy <= 1'b1; + end + end else if (cnt == 0) begin + if (n == 4'd10) + busy <= 1'b0; + else begin + tx <= sh[0]; + sh <= {1'b1, sh[9:1]}; + n <= n + 1'b1; + cnt <= div - 1'b1; + end + end else + cnt <= cnt - 1'b1; + end +endmodule diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..c3a3f07 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Build the bitstream; add "program" or "flash" to load it onto a connected board. +set -e +cd "$(dirname "$0")/.." +source scripts/vivado_env.sh +mkdir -p build +cd build +vivado -mode batch -nojournal -log build.log -source ../scripts/build.tcl +case "$1" in + program) vivado -mode batch -nojournal -log program.log -source ../scripts/program.tcl ;; + flash) vivado -mode batch -nojournal -log program.log -source ../scripts/program.tcl -tclargs flash ;; +esac diff --git a/scripts/build.tcl b/scripts/build.tcl new file mode 100644 index 0000000..10739e8 --- /dev/null +++ b/scripts/build.tcl @@ -0,0 +1,37 @@ +# Non-project Vivado build: vivado -mode batch -source scripts/build.tcl +# The CPU clock is 100 MHz * CPU_MULT / CPU_DIV (environment variables). +set root [file normalize [file dirname [info script]]/..] +set out $root/build +file mkdir $out + +set mult [expr {[info exists ::env(CPU_MULT)] ? $::env(CPU_MULT) : 9.0}] +set div [expr {[info exists ::env(CPU_DIV)] ? $::env(CPU_DIV) : 10.0}] +set hz [expr {int(round(100e6 * $mult / $div))}] +puts "CPU clock: [expr {$hz / 1e6}] MHz" + +read_verilog [glob $root/rtl/*.v] +read_mem $root/font/font.mem +read_mem $root/basic/basic.mem +read_mem $root/basic/basic-hi.mem +read_mem $root/monitor/monitor.mem +read_xdc $root/constraints/basys3.xdc + +synth_design -top basys3_terminal -part xc7a35tcpg236-1 \ + -generic CPU_MULT=$mult -generic CPU_DIV=$div -generic CPU_HZ=$hz +opt_design -directive Explore +place_design -directive ExtraTimingOpt +phys_opt_design -directive AggressiveExplore +route_design -directive Explore +phys_opt_design -directive AggressiveExplore +write_checkpoint -force $out/routed.dcp + +report_utilization -file $out/utilization.rpt +report_timing_summary -file $out/timing.rpt +report_timing -max_paths 30 -nworst 1 -unique_pins -file $out/paths.rpt +write_bitstream -force $out/basys3_terminal.bit +write_cfgmem -force -format mcs -interface SPIx4 -size 4 \ + -loadbit "up 0x0 $out/basys3_terminal.bit" $out/basys3_terminal.mcs + +set wns [get_property SLACK [get_timing_paths -max_paths 1 -setup]] +puts "Worst setup slack: $wns ns" +if {$wns < 0} { error "timing not met" } diff --git a/scripts/cputest.sh b/scripts/cputest.sh new file mode 100755 index 0000000..a05c30d --- /dev/null +++ b/scripts/cputest.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Build riscv-tests (rv32ui, rv32um, rv32mi) and our own tests in tests/, run +# them all on rtl/rv32_cpu.v in xsim. Fetches riscv-tests into third_party/. +# scripts/cputest.sh [name-filter] +set -e +cd "$(dirname "$0")/.." +ROOT=$(pwd) +source scripts/rv_env.sh +RT=$ROOT/third_party/riscv-tests +if [ ! -d "$RT/isa" ]; then + git clone --recursive https://github.com/riscv-software-src/riscv-tests.git "$RT" +fi + +# Not applicable to this core: +# ma_data assumes misaligned loads/stores work; here they trap (allowed) +# pmpaddr needs PMP +SKIP="rv32ui-ma_data rv32mi-pmpaddr" + +OUT=$ROOT/build/tests +mkdir -p "$OUT" +LIST=$OUT/list.txt +: > "$LIST" +build() { # name source + local name=$1 src=$2 + case " $SKIP " in *" $name "*) return ;; esac + [ -n "$FILTER" ] && [[ $name != *$FILTER* ]] && return + ${RV_PREFIX}gcc $RV_ARCH -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -Wl,--build-id=none \ + -I"$RT/env/p" -I"$RT/isa/macros/scalar" -I"$ROOT/tests" -T"$ROOT/tests/link.ld" \ + "$src" -o "$OUT/$name.elf" + ${RV_PREFIX}objcopy -O binary "$OUT/$name.elf" "$OUT/$name.bin" + python3 "$ROOT/tools/bin2mem.py" "$OUT/$name.bin" "$OUT/$name.mem" + local th=$(${RV_PREFIX}nm "$OUT/$name.elf" | awk '$3=="tohost"{print $1}') + echo "$OUT/$name.mem $th $name" >> "$LIST" +} +FILTER=$1 +for suite in rv32ui rv32um rv32mi; do + for t in $(sed -n "/^${suite}_sc_tests/,/^\$/p" "$RT/isa/$suite/Makefrag" | grep -v = | tr -d '\\'); do + build "$suite-$t" "$RT/isa/$suite/$t.S" + done +done +for s in tests/*.S; do [ -e "$s" ] || continue; build "own-$(basename "$s" .S)" "$s"; done +echo "$(wc -l < "$LIST") tests built" + +source scripts/vivado_env.sh +mkdir -p sim/cpu +cd sim/cpu +rm -f xsim.log +xvlog "$ROOT/rtl/rv32_cpu.v" "$ROOT/sim/tb_cpu.v" | grep -E "^(ERROR|WARNING)" || true +[ -d xsim.dir/work ] && ! grep -q ERROR xvlog.log || { echo "compile failed"; exit 1; } +xelab -debug off tb_cpu -s tb_cpu >/dev/null +xsim tb_cpu -R -testplusarg list="$LIST" | grep -E '^(PASS|FAIL|[0-9]+ passed)' +grep -q " passed, 0 failed" xsim.log diff --git a/scripts/program.tcl b/scripts/program.tcl new file mode 100644 index 0000000..b256a4e --- /dev/null +++ b/scripts/program.tcl @@ -0,0 +1,43 @@ +# Program the Basys 3 over its USB-JTAG port. +# vivado -mode batch -source scripts/program.tcl (SRAM, lost at power-off) +# vivado -mode batch -source scripts/program.tcl -tclargs flash (QSPI flash, survives power-off) +set root [file normalize [file dirname [info script]]/..] +set mode [expr {[llength $argv] > 0 ? [lindex $argv 0] : "sram"}] + +open_hw_manager +connect_hw_server +open_hw_target +set dev [lindex [get_hw_devices xc7a35t*] 0] +current_hw_device $dev +refresh_hw_device -update_hw_probes false $dev + +if {$mode eq "flash"} { + # Board revisions differ: older Basys 3s have Spansion flash, newer ones Macronix. + # Vivado checks the chip ID before erasing, so a wrong guess is harmless. + set done 0 + foreach part {mx25l3273f-spi-x1_x2_x4 s25fl032p-spi-x1_x2_x4} { + create_hw_cfgmem -hw_device $dev [lindex [get_cfgmem_parts $part] 0] + set mem [get_property PROGRAM.HW_CFGMEM $dev] + set_property PROGRAM.FILES [list $root/build/basys3_terminal.mcs] $mem + set_property PROGRAM.ADDRESS_RANGE use_file $mem + set_property PROGRAM.ERASE 1 $mem + set_property PROGRAM.CFG_PROGRAM 1 $mem + set_property PROGRAM.VERIFY 1 $mem + create_hw_bitstream -hw_device $dev [get_property PROGRAM.HW_CFGMEM_BITFILE $dev] + program_hw_devices $dev + if {![catch {program_hw_cfgmem -hw_cfgmem $mem}]} { + set done 1 + break + } + delete_hw_cfgmem $mem + } + if {!$done} { error "flash part not recognised" } + # reload the FPGA from flash (works when JP1 is set to QSPI) + boot_hw_device $dev + puts "Flash programmed; with JP1 on QSPI the board now boots from it." +} else { + set_property PROGRAM.FILE $root/build/basys3_terminal.bit $dev + program_hw_devices $dev + puts "FPGA configured." +} +close_hw_manager diff --git a/scripts/rv_env.sh b/scripts/rv_env.sh new file mode 100755 index 0000000..5f15587 --- /dev/null +++ b/scripts/rv_env.sh @@ -0,0 +1,13 @@ +# Sourced by the build scripts: finds a RISC-V GCC. +# RV_PREFIX overrides; otherwise a riscv64/riscv32-unknown-elf-gcc on PATH, else +# the one that ships with Vivado (for MicroBlaze V; it has the rv32im multilib). +if [ -z "$RV_PREFIX" ]; then + for p in riscv64-unknown-elf- riscv32-unknown-elf-; do + command -v ${p}gcc >/dev/null && { RV_PREFIX=$p; break; } + done +fi +if [ -z "$RV_PREFIX" ]; then + RV_PREFIX=$(ls -d "$HOME"/vivado/*/gnu/riscv/lin/bin 2>/dev/null | sort -V | tail -1)/riscv64-unknown-elf- +fi +[ -x "${RV_PREFIX}gcc" ] || command -v "${RV_PREFIX}gcc" >/dev/null || { echo "no RISC-V gcc found; set RV_PREFIX" >&2; exit 1; } +RV_ARCH="-march=rv32im_zicsr_zifencei -mabi=ilp32" diff --git a/scripts/sim-sound.sh b/scripts/sim-sound.sh new file mode 100755 index 0000000..f906baf --- /dev/null +++ b/scripts/sim-sound.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Run the sound chip's testbench (sim/tb_sound.v) in Vivado's simulator. +set -e +cd "$(dirname "$0")/.." +ROOT=$(pwd) +source scripts/vivado_env.sh +mkdir -p sim/work-sound +cd sim/work-sound +xvlog "$ROOT"/rtl/sound.v "$ROOT"/sim/tb_sound.v +xelab -debug typical tb_sound -s tb_sound +xsim tb_sound -R diff --git a/scripts/sim.sh b/scripts/sim.sh new file mode 100755 index 0000000..18095e2 --- /dev/null +++ b/scripts/sim.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Run the whole-design testbench in Vivado's simulator; output lands in sim/work. +# scripts/sim.sh [quick] quick: only the computer, up to the monitor +set -e +cd "$(dirname "$0")/.." +ROOT=$(pwd) +source scripts/vivado_env.sh +DEFS="" +[ "$1" = quick ] && DEFS="-d SKIP_TERMINAL -d STOP_BEFORE_MONITOR" +MON=$ROOT/monitor/monitor.mem +[ -e "$MON" ] || { mkdir -p sim/work; MON=$ROOT/sim/work/empty.mem; : > "$MON"; } +mkdir -p sim/work +cd sim/work +xvlog -d SIMULATION $DEFS -d FONT_FILE="\"$ROOT/font/font.mem\"" -d MEM_FILE="\"$ROOT/basic/basic.mem\"" \ + -d MEM_HI_FILE="\"$ROOT/basic/basic-hi.mem\"" -d MON_FILE="\"$MON\"" \ + "$ROOT"/rtl/*.v "$ROOT"/sim/spiflash_model.v "$ROOT"/sim/tb_terminal.v | grep -E '^(ERROR|WARNING)' || true +xelab -debug off tb_terminal -s tb_terminal | grep -E '^(ERROR|WARNING)' || true +xsim tb_terminal -R | grep -v -E '^(INFO|#|\*\*|Vivado|source|run|exit|Time:|Copyright)' +if command -v python3 >/dev/null; then + for f in frame_*.ppm; do + [ -e "$f" ] || continue + python3 -c "import sys; from PIL import Image; Image.open(sys.argv[1]).save(sys.argv[2])" \ + "$f" "${f%.ppm}.png" && echo "wrote sim/work/${f%.ppm}.png" + done +fi diff --git a/scripts/synth.tcl b/scripts/synth.tcl new file mode 100644 index 0000000..fa39564 --- /dev/null +++ b/scripts/synth.tcl @@ -0,0 +1,13 @@ +# Synthesis only, for resource counts: vivado -mode batch -source scripts/synth.tcl +set root [file normalize [file dirname [info script]]/..] +set out $root/build +file mkdir $out +read_verilog [glob $root/rtl/*.v] +read_mem $root/font/font.mem +read_mem $root/basic/basic.mem +read_mem $root/basic/basic-hi.mem +read_mem $root/monitor/monitor.mem +read_xdc $root/constraints/basys3.xdc +synth_design -top basys3_terminal -part xc7a35tcpg236-1 +report_utilization -file $out/synth_util.rpt +report_utilization -hierarchical -hierarchical_depth 2 -file $out/synth_hier.rpt diff --git a/scripts/vivado_env.sh b/scripts/vivado_env.sh new file mode 100755 index 0000000..9239c1d --- /dev/null +++ b/scripts/vivado_env.sh @@ -0,0 +1,14 @@ +# Sourced by build.sh and sim.sh: sets up Vivado's environment. +# VIVADO picks the install; default is the newest in ~/vivado//Vivado. +VIVADO=${VIVADO:-$(ls -d "$HOME"/vivado/*/Vivado 2>/dev/null | sort -V | tail -1)} +source "$VIVADO/settings64.sh" + +# Vivado still links against ncurses 5; newer distros only ship 6, which works. +COMPAT_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/build/compat-lib" +mkdir -p "$COMPAT_LIB" +for l in ncurses tinfo; do + if ! ldconfig -p | grep -q "lib$l.so.5" && [ -e /usr/lib/x86_64-linux-gnu/lib$l.so.6 ]; then + ln -sf /usr/lib/x86_64-linux-gnu/lib$l.so.6 "$COMPAT_LIB/lib$l.so.5" + fi +done +export LD_LIBRARY_PATH="$COMPAT_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" diff --git a/sim/spiflash_model.v b/sim/spiflash_model.v new file mode 100644 index 0000000..eeec290 --- /dev/null +++ b/sim/spiflash_model.v @@ -0,0 +1,82 @@ +`timescale 1ns / 1ps + +// Behavioural SPI flash (mode 0) with the commands the Z-80 uses: +// 03 read, 05 status, 06/04 write enable/disable, 9F ID (Macronix MX25L3273F), +// 02 page program, 20 4 KB erase. Reports any program or erase below PROTECT. +module spiflash_model #( + parameter PROTECT = 24'h240000 +) ( + input cs_n, + input sck, + input mosi, + output reg miso = 1'b1 +); + reg [7:0] mem [0:(1 << 22) - 1]; + reg [7:0] in_sh, out_sh, cmd; + reg [7:0] pagebuf [0:255]; + reg [23:0] addr; + reg [2:0] bitn; + integer nbytes, ndata, i; + reg wel = 1'b0; + realtime busy_until = 0; + integer violations = 0, programs = 0, erases = 0; + + initial for (i = 0; i < (1 << 22); i = i + 1) mem[i] = 8'hFF; + + always @(negedge cs_n) begin + bitn = 0; nbytes = 0; ndata = 0; out_sh = 8'hFF; + end + + always @(posedge sck) if (!cs_n) begin + in_sh = {in_sh[6:0], mosi}; + bitn = bitn + 1; + if (bitn == 0) begin // a whole byte + if (nbytes == 0) cmd = in_sh; + else if (nbytes <= 3) addr = {addr[15:0], in_sh}; + else if (cmd == 8'h02 && ndata < 256) begin pagebuf[ndata] = in_sh; ndata = ndata + 1; end + nbytes = nbytes + 1; + case (cmd) + 8'h03: out_sh = nbytes >= 4 ? mem[addr + nbytes - 4] : 8'hFF; + 8'h05: out_sh = {6'd0, wel, $realtime < busy_until}; + 8'h9F: out_sh = nbytes == 1 ? 8'hC2 : nbytes == 2 ? 8'h20 : 8'h16; + default: out_sh = 8'hFF; + endcase + end + end + + always @(negedge sck) if (!cs_n) begin + miso = out_sh[7]; + out_sh = {out_sh[6:0], 1'b1}; + end + + task busy_for(input integer ns); + busy_until = $realtime + ns; + endtask + + always @(posedge cs_n) if (bitn == 0) begin + case (cmd) + 8'h06: wel = 1'b1; + 8'h04: wel = 1'b0; + 8'h02: if (wel && nbytes >= 5) begin + if (addr < PROTECT) begin + $display("FLASH VIOLATION: program at %h", addr); violations = violations + 1; + end + for (i = 0; i < ndata; i = i + 1) + mem[{addr[23:8], addr[7:0] + i[7:0]}] = mem[{addr[23:8], addr[7:0] + i[7:0]}] & pagebuf[i]; + programs = programs + 1; + wel = 1'b0; + busy_for(3000); + end + 8'h20: if (wel && nbytes == 4) begin + if (addr < PROTECT) begin + $display("FLASH VIOLATION: erase at %h", addr); violations = violations + 1; + end + for (i = 0; i < 4096; i = i + 1) mem[{addr[23:12], 12'd0} + i] = 8'hFF; + erases = erases + 1; + wel = 1'b0; + busy_for(20000); + end + default: ; + endcase + end +endmodule diff --git a/sim/tb_cpu.v b/sim/tb_cpu.v new file mode 100644 index 0000000..282d7cf --- /dev/null +++ b/sim/tb_cpu.v @@ -0,0 +1,118 @@ +`timescale 1ns / 1ps + +// Runs a list of test images on rv32_cpu, one after another. +// +list=: lines of " " +// A test ends when it writes tohost: 1 is a pass, anything else a failure +// (riscv-tests put the failing test number in bits 31:1). +// The data bus answers after a pseudo-random 1-3 cycles to exercise d_ack. +// Address FFFF_FF00 is a test device: writing N raises the interrupt lines +// in N[5:0] (bit 0 soft, 1 timer, 2 external, 3 local 16, 4 nmi, 5 nmi_step) +// N[31:8] cycles later; any write first drops them. NMI_VEC is 8000h. +module tb_cpu; + reg clk = 0, rst = 1; + always #5 clk = !clk; + + wire i_en, d_req, d_we; + wire [31:0] i_addr, d_addr, d_wdata; + wire [3:0] d_wstrb; + reg [31:0] i_rdata, d_rdata; + reg d_ack; + reg [5:0] irq; + wire retire; + + rv32_cpu #(.NMI_VEC(32'h8000)) cpu ( + .clk(clk), .rst(rst), + .i_en(i_en), .i_addr(i_addr), .i_rdata(i_rdata), + .d_req(d_req), .d_we(d_we), .d_wstrb(d_wstrb), .d_addr(d_addr), + .d_wdata(d_wdata), .d_rdata(d_rdata), .d_ack(d_ack), + .irq_soft(irq[0]), .irq_timer(irq[1]), .irq_ext(irq[2]), + .irq_local({15'd0, irq[3]}), .nmi(irq[4]), .nmi_step(irq[5]), .nmi_taken(), + .dbg_pc(), .dbg_decode(), .retire(retire) + ); + + localparam WORDS = 16384; // 64 KB + reg [31:0] mem [0:WORDS-1]; + reg [31:0] tohost; + reg done; + reg [31:0] result; + + always @(posedge clk) if (i_en) i_rdata <= mem[i_addr[15:2]]; + + // data bus with random wait states + reg [1:0] wait_n; + reg busy, bwe; + reg [31:0] baddr, bdata; + reg [3:0] bstrb; + reg [31:0] lfsr = 32'h1234_5678; + reg [5:0] irq_set; + reg [23:0] irq_delay; + always @(posedge clk) begin + lfsr <= {lfsr[30:0], lfsr[31] ^ lfsr[21] ^ lfsr[1] ^ lfsr[0]}; + d_ack <= 1'b0; + if (d_req) begin + busy <= 1'b1; baddr <= d_addr; bwe <= d_we; bdata <= d_wdata; bstrb <= d_wstrb; + wait_n <= lfsr[1:0] == 2'd3 ? 2'd2 : lfsr[1:0]; + end else if (busy) begin + if (wait_n != 0) wait_n <= wait_n - 2'd1; + else begin + busy <= 1'b0; + d_ack <= 1'b1; + d_rdata <= mem[baddr[15:2]]; + if (bwe) begin + if (baddr == 32'hFFFF_FF00) begin + irq_set <= bdata[5:0]; irq_delay <= bdata[31:8]; + irq <= 6'd0; + end else if (baddr == tohost) begin + done <= 1'b1; result <= bdata; + end else if (baddr[31:16] == 16'd0) begin + if (bstrb[0]) mem[baddr[15:2]][7:0] <= bdata[7:0]; + if (bstrb[1]) mem[baddr[15:2]][15:8] <= bdata[15:8]; + if (bstrb[2]) mem[baddr[15:2]][23:16] <= bdata[23:16]; + if (bstrb[3]) mem[baddr[15:2]][31:24] <= bdata[31:24]; + end + end + end + end + if (irq_set != 6'd0) begin + if (irq_delay == 0) begin irq <= irq_set; irq_set <= 6'd0; end + else irq_delay <= irq_delay - 1; + end + if (rst) begin + busy <= 1'b0; done <= 1'b0; irq <= 6'd0; irq_set <= 6'd0; + end + end + + integer fd, n, cycles, pass = 0, fail = 0, i; + reg [8*200-1:0] memf, name, list; + initial begin + if (!$value$plusargs("list=%s", list)) begin + $display("need +list=file"); $finish; + end + fd = $fopen(list, "r"); + while (!$feof(fd)) begin + n = $fscanf(fd, "%s %h %s\n", memf, tohost, name); + if (n == 3) begin + for (i = 0; i < WORDS; i = i + 1) mem[i] = 32'd0; + $readmemh(memf, mem); + rst = 1; + repeat (4) @(posedge clk); + rst = 0; + cycles = 0; + while (!done && cycles < 200000) begin + @(posedge clk); + cycles = cycles + 1; + end + if (done && result == 32'd1) begin + pass = pass + 1; + $display("PASS %0s (%0d cycles)", name, cycles); + end else begin + fail = fail + 1; + if (done) $display("FAIL %0s test %0d", name, result >> 1); + else $display("FAIL %0s timeout, pc=%h", name, cpu.pc); + end + end + end + $display("%0d passed, %0d failed", pass, fail); + $finish; + end +endmodule diff --git a/sim/tb_sound.v b/sim/tb_sound.v new file mode 100644 index 0000000..90dd7ff --- /dev/null +++ b/sim/tb_sound.v @@ -0,0 +1,142 @@ +`timescale 1ns / 1ps +// Testbench for rtl/sound.v at the Z-80's 90 MHz clock: pitch, mixer, noise, +// volume levels, the attack and decay envelopes, reading back and hushing. +// scripts/sim-sound.sh +module tb_sound; + reg clk = 0, rst = 1, hush = 0, io_wr = 0; + reg [7:0] port = 0, wd = 0; + wire [7:0] q; + wire audio; + integer errors = 0; + + sound #(.CPU_HZ(90_000_000)) dut ( + .clk(clk), .rst(rst), .hush(hush), .io_wr(io_wr), .io_port(port), .io_wd(wd), + .io_q(q), .audio(audio) + ); + always #5.556 clk = ~clk; + + task out(input [7:0] p, input [7:0] v); + begin + @(posedge clk) begin port <= p; wd <= v; io_wr <= 1; end + @(posedge clk) io_wr <= 0; + end + endtask + + task rd(input [7:0] p); // q then holds the port's value + begin port = p; #1; end + endtask + + task check(input [8*48-1:0] what, input ok); + begin + if (ok) $display("PASS %0s", what); + else begin $display("FAIL %0s", what); errors = errors + 1; end + end + endtask + + // count rising edges of voice 0's tone over a time, and the output's duty + integer edges, ones, total; + real t0, duty; + task measure(input real ms); + begin + edges = 0; ones = 0; total = 0; + t0 = $realtime; + while ($realtime - t0 < ms * 1e6) begin + @(posedge clk); + total = total + 1; + ones = ones + audio; + end + duty = 1.0 * ones / total; + end + endtask + reg t_prev = 0; + integer tone_edges = 0; + always @(posedge clk) begin + t_prev <= dut.tone[0]; + if (dut.tone[0] && !t_prev) tone_edges = tone_edges + 1; + end + + real d15, d7; + integer n0, v, k, rose_at, fell_at; + initial begin + repeat (10) @(posedge clk); + rst = 0; + repeat (10) @(posedge clk); + measure(1.0); + check("no output after reset", ones == 0); + + // voice 0 at 440 Hz: 125000 / 284 = 440.1 + out(8'h90, 284 % 256); out(8'h91, 284 / 256); + out(8'h97, 8'b000_001); + out(8'h98, 8'd15); + n0 = tone_edges; + measure(50.0); + $display(" voice 0: %0d cycles in 50 ms (%.1f Hz), duty %.3f", tone_edges - n0, + (tone_edges - n0) / 0.05, duty); + check("pitch 284 plays about 440 Hz", tone_edges - n0 >= 21 && tone_edges - n0 <= 23); + d15 = duty; + check("one voice at full volume: high 1/8 of the time", d15 > 0.11 && d15 < 0.13); + out(8'h98, 8'd7); + measure(50.0); + d7 = duty; + $display(" volume 15 duty %.4f, volume 7 duty %.4f (ratio %.1f)", d15, d7, d15 / d7); + check("volume 7 is about 24 dB quieter", d15 / d7 > 12 && d15 / d7 < 20); + rd(8'h98); + check("volume reads back", q == 8'd7); + + // decay: 15 steps of 2 x 4 ms from 15 = 120 ms + out(8'h9B, 8'h02); + out(8'h98, 8'd15); + t0 = $realtime; + wait (dut.cur[0] == 0); + $display(" decay from 15 took %.1f ms", ($realtime - t0) / 1e6); + check("decay 2 fades 15 steps in 120 ms", ($realtime - t0) / 1e6 > 115 && ($realtime - t0) / 1e6 < 125); + rd(8'h98); + check("a finished sound reads back 0", q == 8'd0); + + // attack then decay: up 12 steps of 1 x 4 ms, then down + out(8'h9B, 8'h13); + out(8'h98, 8'd12); + t0 = $realtime; + check("attack starts from 0", dut.cur[0] == 0); + wait (dut.cur[0] == 12); + rose_at = ($realtime - t0) / 1e6; + wait (dut.cur[0] == 0); + fell_at = ($realtime - t0) / 1e6; + $display(" attack reached 12 at %0d ms, faded out at %0d ms", rose_at, fell_at); + check("attack 1 rises 12 steps in 48 ms", rose_at >= 46 && rose_at <= 50); + check("decay 3 then falls 12 steps in 144 ms", fell_at - rose_at >= 140 && fell_at - rose_at <= 150); + + // noise on voice 1, no tone + out(8'h96, 8'd4); + out(8'h97, 8'b010_000); + out(8'h9C, 8'h00); + out(8'h99, 8'd15); + n0 = 0; + for (k = 0; k < 2000; k = k + 1) begin + repeat (360) @(posedge clk); + n0 = n0 + dut.lfsr[0]; + end + $display(" noise was high %0d of 2000 samples", n0); + check("noise is about half high, half low", n0 > 800 && n0 < 1200); + + // all three voices and CLS + out(8'h92, 8'd142); out(8'h94, 8'd71); + out(8'h97, 8'b000_111); + out(8'h98, 8'd15); out(8'h99, 8'd15); out(8'h9A, 8'd15); + measure(20.0); + check("three voices make sound", duty > 0.2); + @(posedge clk) hush <= 1; + @(posedge clk) hush <= 0; + repeat (4) @(posedge clk); // what was already in the mixer + measure(2.0); + $display(" after CLS: output high %0d times in 2 ms", ones); + rd(8'h99); + check("CLS silences everything", ones == 0 && q == 0); + rd(8'h97); + check("other ports read FFh", q == 8'hFF); + + if (errors == 0) $display("ALL SOUND TESTS PASSED"); + else $display("%0d SOUND TESTS FAILED", errors); + $finish; + end +endmodule diff --git a/sim/tb_terminal.v b/sim/tb_terminal.v new file mode 100644 index 0000000..0c3df3c --- /dev/null +++ b/sim/tb_terminal.v @@ -0,0 +1,601 @@ +`timescale 1ns / 1ps + +// Whole-design test: keystrokes on PS/2 -> UART TX bytes, host queries -> +// replies, UART RX text -> screen buffer (printed as text) and VGA frames +// (written as frame_*.ppm). +module tb_terminal; + reg clk = 0; + always #5 clk = ~clk; + + reg [15:0] sw = 16'h0200; // 115200 baud, fast smooth scroll when enabled + reg btnC = 0, btnU = 0, btnD = 0; + reg rsrx = 1; + reg ps2c = 1, ps2d = 1; + wire rstx, hs, vs; + wire [3:0] r, g, b; + wire [15:0] led; + wire qcs; + wire [3:0] qdb; + + basys3_terminal #(.FONT_FILE(`FONT_FILE), .MEM_FILE(`MEM_FILE), .MEM_HI_FILE(`MEM_HI_FILE), .MON_FILE(`MON_FILE)) dut ( + .clk(clk), .btnC(btnC), .btnU(btnU), .btnD(btnD), .sw(sw), .led(led), .seg(), .dp(), .an(), + .vgaRed(r), .vgaGreen(g), .vgaBlue(b), .Hsync(hs), .Vsync(vs), + .RsRx(rsrx), .RsTx(rstx), .PS2Clk(ps2c), .PS2Data(ps2d), + .QspiCSn(qcs), .QspiDB(qdb) + ); + + spiflash_model flash (.cs_n(qcs), .sck(dut.fl_sck), .mosi(qdb[0]), .miso(qdb[1])); + + real BIT_NS = 1_000_000_000.0 / 115200; // changed for the 3 Mbaud test + integer errors = 0; + + task uart_send(input [7:0] d); + integer i; + begin + rsrx = 0; #(BIT_NS); + for (i = 0; i < 8; i = i + 1) begin rsrx = d[i]; #(BIT_NS); end + rsrx = 1; #(BIT_NS); + end + endtask + + task uart_str(input [8*200-1:0] s); + integer i; + begin + for (i = 199; i >= 0; i = i - 1) + if (s[i*8 +: 8] != 0) uart_send(s[i*8 +: 8]); + end + endtask + + task ps2_send(input [7:0] d); + integer i; + reg [10:0] f; + begin + f = {1'b1, ~^d, d, 1'b0}; + for (i = 0; i < 11; i = i + 1) begin + ps2d = f[i]; #10000; + ps2c = 0; #20000; + ps2c = 1; #10000; + end + #100000; + end + endtask + + task key(input [7:0] code); // press and release + begin ps2_send(code); ps2_send(8'hF0); ps2_send(code); end + endtask + + task ext_key(input [7:0] code); + begin ps2_send(8'hE0); ps2_send(code); ps2_send(8'hE0); ps2_send(8'hF0); ps2_send(code); end + endtask + + // everything the terminal transmits + reg [8*32-1:0] tx_log = 0; + integer tx_n = 0; + initial forever begin : txmon + integer i; + reg [7:0] d; + @(negedge rstx); + #(BIT_NS / 2); + for (i = 0; i < 8; i = i + 1) begin #(BIT_NS); d[i] = rstx; end + #(BIT_NS); + if (!rstx) $display("TX framing error"); + tx_log = {tx_log[8*31-1:0], d}; + tx_n = tx_n + 1; + end + + task expect_tx(input [8*32-1:0] want, input integer n, input [8*40-1:0] what); + reg [8*32-1:0] mask; + begin + #1_200_000; // a 10-byte reply takes ~0.9 ms + mask = {256{1'b1}} >> (256 - 8 * n); + if (tx_n == n && (tx_log & mask) == (want & mask)) + $display("PASS %0s", what); + else begin + $display("FAIL %0s: got %0d bytes %h", what, tx_n, tx_log & mask); + errors = errors + 1; + end + tx_n = 0; + tx_log = 0; + end + endtask + + function [7:0] cellraw(input integer rr, input integer cc); + reg [17:0] v; + begin + v = dut.screen.cell_at((dut.alt_scr ? 8448 : 0) + rr * 132 + cc); // the page on show + cellraw = v[7:0]; + end + endfunction + + function [7:0] cellch(input integer rr, input integer cc); + reg [7:0] v; + begin + v = cellraw(rr, cc); + cellch = v < 8'h20 || v >= 8'h7F ? "~" : v; + end + endfunction + + task dump_screen; + integer rr, cc; + reg [8*80-1:0] line; + begin + $display("+--------------------------------------------------------------------------------+"); + for (rr = 0; rr < 30; rr = rr + 1) begin + for (cc = 0; cc < 80; cc = cc + 1) + line[(79 - cc) * 8 +: 8] = cellch(rr, cc); + $display("|%s| %0d", line, rr); + end + $display("+--------------------------------------------------------------------------------+"); + $display("cursor row %0d col %0d, region %0d-%0d", dut.term.row, dut.term.col, + dut.term.stop, dut.term.sbot); + end + endtask + + task expect_row(input integer rr, input [8*40-1:0] want); + integer cc, n; + reg [8*40-1:0] got; + begin + n = 0; + for (cc = 0; cc < 40; cc = cc + 1) if (want[cc*8 +: 8] != 0) n = cc + 1; + got = 0; + for (cc = 0; cc < n; cc = cc + 1) got[(n - 1 - cc) * 8 +: 8] = cellraw(rr, cc); + if (got == want) $display("PASS row %0d", rr); + else begin + $display("FAIL row %0d: want %h got %h", rr, want, got); + errors = errors + 1; + end + end + endtask + + // wait (up to 100 ms) for a row to read want, then check it + task wait_row(input integer rr, input [8*40-1:0] want); + integer cc, n; + reg [8*40-1:0] got; + realtime t0; + begin + t0 = $realtime; + n = 0; + for (cc = 0; cc < 40; cc = cc + 1) if (want[cc*8 +: 8] != 0) n = cc + 1; + got = 0; + while (got != want && $realtime - t0 < 100_000_000) begin + #100_000; + for (cc = 0; cc < n; cc = cc + 1) got[(n - 1 - cc) * 8 +: 8] = cellraw(rr, cc); + end + expect_row(rr, want); + end + endtask + + // wait (up to 300 ms) for text at row rr from column c0 + task wait_at(input integer rr, input integer c0, input [8*40-1:0] want); + integer cc, n; + reg [8*40-1:0] got; + realtime t0; + begin + t0 = $realtime; + n = 0; + for (cc = 0; cc < 40; cc = cc + 1) if (want[cc*8 +: 8] != 0) n = cc + 1; + got = 0; + while (got != want && $realtime - t0 < 300_000_000) begin + #100_000; + for (cc = 0; cc < n; cc = cc + 1) got[(n - 1 - cc) * 8 +: 8] = cellraw(rr, c0 + cc); + end + if (got == want) $display("PASS row %0d col %0d: %0s", rr, c0, want); + else begin + $display("FAIL row %0d col %0d: want \"%0s\" got \"%0s\"", rr, c0, want, got); + errors = errors + 1; + end + end + endtask + + reg [31:0] pc_a, pc_b, jp_to; + reg [15:0] jp_txt; + integer i; + // a hex number on the screen at (rr, c0), up to a character that isn't one + function [31:0] hex_at(input integer rr, input integer c0); + integer cc; + reg [7:0] ch; + reg go; + begin + hex_at = 0; + go = 1; + for (cc = c0; cc < c0 + 9; cc = cc + 1) begin + ch = cellraw(rr, cc); + if (go && ch >= "0" && ch <= "9") hex_at = hex_at * 16 + (ch - "0"); + else if (go && ch >= "A" && ch <= "F") hex_at = hex_at * 16 + (ch - "A" + 10); + else go = 0; + end + end + endfunction + + // the PC in the monitor's register display + function [31:0] screen_pc(input integer dummy); + screen_pc = hex_at(2, 4); + endfunction + + // capture one frame (1280x1024; the colour on the pins belongs to the + // position the display's counters had four clocks earlier) + reg [11:0] fb [0:1280*1024-1]; + reg cap = 0; + reg [21:0] pd1, pd2, pd3, pd4; + always @(posedge dut.pix_clk) begin + pd1 <= {dut.video.h, dut.video.v}; + pd2 <= pd1; pd3 <= pd2; pd4 <= pd3; + end + always @(negedge dut.pix_clk) + if (cap && pd4[21:11] < 1280 && pd4[10:0] < 1024) fb[pd4[10:0] * 1280 + pd4[21:11]] = {r, g, b}; + + task capture_frame(input [8*16-1:0] name); + integer fd, i; + begin + @(posedge vs); + cap = 1; + @(negedge vs); + @(posedge vs); + cap = 0; + fd = $fopen(name, "w"); + $fwrite(fd, "P3\n1280 1024\n15\n"); + for (i = 0; i < 1280 * 1024; i = i + 1) + $fwrite(fd, "%0d %0d %0d\n", fb[i][11:8], fb[i][7:4], fb[i][3:0]); + $fclose(fd); + $display("wrote %0s", name); + end + endtask + + // check VGA timing on the outputs: 1688 x 1066 pixel clocks (10 ns here) + realtime t_hs = 0, t_vs = 0, t_cmd; + integer hs_bad = 0, vs_bad = 0; + always @(posedge hs) begin + if (t_hs != 0 && ($realtime - t_hs) != 16880) hs_bad = hs_bad + 1; + t_hs = $realtime; + end + always @(posedge vs) begin + if (t_vs != 0 && ($realtime - t_vs) != 16880 * 1066) begin + vs_bad = vs_bad + 1; + $display("VSYNC period %0t", $realtime - t_vs); + end + t_vs = $realtime; + end + + initial begin + #2_000_000; // reset, clear, banner + +`ifndef SKIP_TERMINAL + // ---- keyboard: a, shift+b, Enter, up, ctrl+c, F5 + key(8'h1C); + ps2_send(8'h12); key(8'h32); ps2_send(8'hF0); ps2_send(8'h12); + key(8'h5A); + ext_key(8'h75); + ps2_send(8'h14); key(8'h21); ps2_send(8'hF0); ps2_send(8'h14); + key(8'h03); + expect_tx({8'h61, 8'h42, 8'h0D, 8'h1B, "[A", 8'h03, 8'h1B, "[15~"}, 12, "keyboard -> UART"); + + // ---- host queries and modes + uart_str("\033[c"); + expect_tx({8'h1B, "[?62;22c"}, 9, "DA reply"); + uart_str("\033[>c"); + expect_tx({8'h1B, "[>1;10;0c"}, 10, "secondary DA reply"); + uart_str("\033[5;10H\033[6n"); + expect_tx({8'h1B, "[05;10R"}, 8, "cursor position report"); + uart_str("\033[?1h"); + ext_key(8'h75); + expect_tx({8'h1B, "OA"}, 3, "DECCKM up arrow"); + uart_str("\033[?1l\033="); + key(8'h69); + expect_tx({8'h1B, "Oq"}, 3, "DECKPAM keypad 1"); + uart_str("\033>\033[1;3q"); + #50_000; + if (led[11:8] == 4'b0101) $display("PASS DECLL LEDs"); + else begin $display("FAIL DECLL LEDs %b", led[11:8]); errors = errors + 1; end + + // ---- screen + uart_str({"\033[2J\033[H\033[1mBold\033[0m \033[31mred \033[32mgreen \033[44;33myellow-on-blue\033[0m ", + "\033[4munderline\033[0m \033[7mreverse\033[0m \033[5mblink\033[0m\015\012"}); + uart_str("\033)0\016lqqqqk\015\012x x\015\012mqqqqj\017\015\012"); + uart_str("abcdefgh\033[4D\033[2@XY\033[3P\015\012"); + uart_str("\033[38;5;196m256-red \033[38;2;0;0;255mrgb-blue \033[90mgrey \033[103;30mon-yellow\033[0m\015\012"); + uart_str({"\033]3008;start=1f2e;user=brad;type=shell\033\\\033]0;title\007", + "line A\015\012line B\015\012line C\015\012line D\015\012"}); + uart_str("\033[8;1H\033[Linserted\033[10;1H\033[M"); + uart_str("\033[13;1Habove region\033[19;1Hbelow region\033[15;18r\033[15;1H"); + uart_str("r1\015\012r2\015\012r3\015\012r4\015\012r5\015\012r6"); + uart_str("\033[1;1H\033[4h>\033[4l\033[30;70Hcorner\033[1;1H"); + #200_000; + expect_row(0, ">Bold red green yellow-on-blue"); + expect_row(1, {8'hDA, 8'hC4, 8'hC4, 8'hC4, 8'hC4, 8'hBF}); + expect_row(2, {8'hB3, " ", 8'hB3}); + expect_row(4, "abcdXYh"); + expect_row(6, "line A"); + expect_row(7, "inserted"); + expect_row(8, "line B"); + expect_row(9, "line D"); + expect_row(12, "above region"); + expect_row(14, "r3"); + expect_row(17, "r6"); + expect_row(18, "below region"); + dump_screen; + capture_frame("frame_1.ppm"); + + // ---- smooth scroll inside the region + uart_str("\033[18;1H\033[?4h\015\012r7"); + capture_frame("frame_2.ppm"); // mid-scroll + #100_000_000; + expect_row(14, "r4"); + expect_row(17, "r7"); + expect_row(18, "below region"); + uart_str("\033[?4l\033[r"); + dump_screen; + + // ---- 132 columns (DECCOLM): 132x64, cleared, then back to 80x32 + uart_str("\033[?3h"); + #1_000_000; + uart_str("132 columns\033[64;124Hcorner!\033[10;120H\033[6n"); + expect_tx({8'h1B, "[10;120R"}, 9, "cursor report past column 99"); + #200_000; + expect_row(0, "132 columns"); + if ({cellraw(63, 123), cellraw(63, 129)} == {"c", "!"} && dut.wide) + $display("PASS 132x64: last row and column"); + else begin $display("FAIL 132x64 corner: %c%c", cellraw(63, 123), cellraw(63, 129)); errors = errors + 1; end + capture_frame("frame_4.ppm"); + uart_str("\033[?3l"); + #1_000_000; + uart_str("\033[32;75Hend"); + #200_000; + if (!dut.wide && cellraw(31, 74) == "e" && cellraw(0, 0) == " ") + $display("PASS back to 80x32, cleared"); + else begin $display("FAIL back to 80x32"); errors = errors + 1; end + if (hs_bad == 0 && vs_bad == 0) $display("PASS 1280x1024 sync timing"); + else begin $display("FAIL sync timing: %0d hsync, %0d vsync periods off", hs_bad, vs_bad); errors = errors + 1; end + +`endif + // ---- BASIC as the console, input pasted over the UART + uart_str("\033[2J\033[H"); + #100_000; + sw[15] = 1; sw[14] = 1; // the computer has been waiting to print its banner + #3_000_000; + uart_str("PRINT 2+2\015"); + #2_000_000; + uart_str("10 FOR I=1 TO 3: PRINT I*I;: NEXT I\015RUN\015"); + #5_000_000; + expect_row(1, "DARTMOUTH-STYLE BASIC"); + expect_row(3, "READY"); + expect_row(4, "PRINT 2+2"); + expect_row(5, " 4"); + expect_row(7, "READY"); + expect_row(10, " 1 4 9"); + expect_row(11, "READY"); + + // ---- graphics + uart_str({"CLS:INK 11:CIRCLE 160,120,50,12:FILL 10,10,40,30,4:", + "LINE 0,0,319,239,14:PRINT POINT(160,70)\015"}); + t_cmd = $realtime; + while (cellraw(0, 2) != "2" && $realtime - t_cmd < 20_000_000) #10_000; + $display("graphics line ran in %0.2f ms", ($realtime - t_cmd) / 1e6); + expect_row(0, " 12"); + if (dut.sys.gfx(70 * 320 + 160) == 12 && dut.sys.gfx(20 * 320 + 20) == 4 && + dut.sys.gfx(120 * 320 + 160) == 14 && dut.sys.gfx(5 * 320 + 100) == 0) + $display("PASS graphics memory"); + else begin + $display("FAIL graphics memory"); + errors = errors + 1; + end + capture_frame("frame_3.ppm"); + + // ---- sprites: shape 0 solid colour 9, shape 1 solid 2, shape 2 left + // half 14; sprite 0 over sprite 1, sprite 2 flipped at the right edge + // over a filled strip + uart_str({"CLS:OUT 118,0:FOR I=1 TO 128:OUT 119,153:NEXT I:", + "OUT 118,1:FOR I=1 TO 128:OUT 119,34:NEXT I\015"}); + uart_str({"OUT 118,2:FOR I=1 TO 16:FOR J=1 TO 4:OUT 119,238:NEXT J:", + "FOR J=1 TO 4:OUT 119,0:NEXT J:NEXT I\015"}); + uart_str({"OUT 112,0:OUT 113,100:OUT 114,0:OUT 115,150:OUT 116,0:OUT 117,1:", + "OUT 112,1:OUT 113,108:OUT 114,0:OUT 115,158:OUT 116,1:OUT 117,1\015"}); + uart_str({"FILL 0,200,319,239,4:OUT 112,2:OUT 113,54:OUT 114,1:OUT 115,230:", + "OUT 116,2:OUT 117,3\015"}); + #40_000_000; + @(posedge vs); @(posedge vs); @(posedge vs); + uart_str("LOCATE 30,1:PRINT INP(128);INP(129);INP(132)\015"); + wait_row(29, " 3 0 4"); + capture_frame("frame_5.ppm"); + // graphics pixel (x, y) is screen pixel (4x+2, 4y+2) + if (fb[(4*151+2)*1280 + 4*101+2] == 12'hF55 && // sprite 0 + fb[(4*162+2)*1280 + 4*112+2] == 12'hF55 && // sprite 0 over sprite 1 + fb[(4*170+2)*1280 + 4*120+2] == 12'h0A0 && // sprite 1 + fb[(4*150+2)*1280 + 4*99+2] == 12'h000 && // beside them + fb[(4*235+2)*1280 + 4*312+2] == 12'h00A && // flipped: clear half + fb[(4*235+2)*1280 + 4*318+2] == 12'h5FF) // flipped: coloured half + $display("PASS sprites on screen"); + else begin + $display("FAIL sprites on screen: %h %h %h %h %h %h", + fb[(4*151+2)*1280 + 4*101+2], fb[(4*162+2)*1280 + 4*112+2], + fb[(4*170+2)*1280 + 4*120+2], fb[(4*150+2)*1280 + 4*99+2], + fb[(4*235+2)*1280 + 4*312+2], fb[(4*235+2)*1280 + 4*318+2]); + errors = errors + 1; + end + uart_str("CLS\015"); + #5_000_000; + if (dut.sys.spr.en == 32'd0) $display("PASS CLS turns sprites off"); + else begin + $display("FAIL CLS left sprites on: %h", dut.sys.spr.en); + errors = errors + 1; + end + + // ---- held keys: Ctrl and right Shift (they type nothing) read on + // port 136 as fire (16) + shift (64), and right Shift on port 137 + ps2_send(8'h14); ps2_send(8'h59); + #2_000_000; + uart_str("CLS:OUT 137,89:LOCATE 30,1:PRINT INP(136);INP(137)\015"); + wait_row(29, " 80 1"); + ps2_send(8'hF0); ps2_send(8'h14); ps2_send(8'hF0); ps2_send(8'h59); + #2_000_000; + uart_str("CLS:LOCATE 30,1:PRINT INP(136);INP(137)\015"); + wait_row(29, " 0 0"); + + // ---- graphics scroll: buffer (5,3) at the top left, so (10,100) + // shows at (5,97) and (2,1) wraps round to (317,238) + uart_str("CLS:PLOT 10,100,9:PLOT 2,1,12:OUT 53,5:OUT 54,0:OUT 55,3\015"); + #5_000_000; + capture_frame("frame_6.ppm"); + if (fb[(4*97+2)*1280 + 4*5+2] == 12'hF55 && fb[(4*100+2)*1280 + 4*10+2] == 12'h000 && + fb[(4*238+2)*1280 + 4*317+2] == 12'h55F) + $display("PASS graphics scroll"); + else begin + $display("FAIL graphics scroll: %h %h %h", fb[(4*97+2)*1280 + 4*5+2], + fb[(4*100+2)*1280 + 4*10+2], fb[(4*238+2)*1280 + 4*317+2]); + errors = errors + 1; + end + // the border hides the graphics at the screen's edges, not inside + uart_str("OUT 54,2\015"); + #5_000_000; + capture_frame("frame_7.ppm"); + if (fb[(4*97+2)*1280 + 4*5+2] == 12'hF55 && fb[(4*238+2)*1280 + 4*317+2] == 12'h000) + $display("PASS graphics border"); + else begin + $display("FAIL graphics border: %h %h", fb[(4*97+2)*1280 + 4*5+2], fb[(4*238+2)*1280 + 4*317+2]); + errors = errors + 1; + end + uart_str("CLS\015"); + #5_000_000; + if (dut.sys.scroll_x == 0 && dut.sys.scroll_y == 0 && !dut.sys.g_border) $display("PASS CLS resets the scroll"); + else begin + $display("FAIL CLS left the scroll at %0d,%0d", dut.sys.scroll_x, dut.sys.scroll_y); + errors = errors + 1; + end + + // ---- files in the flash, and the bitstream protection + uart_str({"CLS:DATE \"2026-11-28 09:30\":NEW\01510 PRINT \"SAVED\";6*7\015SAVE \"TEST1\"\015NEW\015", + "LOAD \"TEST1\"\015RUN\015DIR\015"}); + #20_000_000; + expect_row(13, "SAVED 42"); + wait_row(17, "TEST1 21 2026-11-28 09:30"); + wait_row(18, "1 FILE, 1780K FREE"); + uart_str("OUT 64,1:OUT 65,6:OUT 64,0:OUT 64,1:OUT 65,32:OUT 65,0:OUT 65,0:OUT 65,0:OUT 64,0\015"); + #3_000_000; + if (flash.programs > 0 && flash.erases > 0 && flash.violations == 0) + $display("PASS flash: %0d programs, %0d erases, bitstream untouched", + flash.programs, flash.erases); + else begin + $display("FAIL flash: %0d programs, %0d erases, %0d violations", + flash.programs, flash.erases, flash.violations); + errors = errors + 1; + end + + // ---- a data file: write it, read it back + uart_str({"CLS:OPEN \"D\" FOR OUTPUT AS 1:PRINT #1,\"XY\";\",\";7:CLOSE\015", + "OPEN \"D\" FOR INPUT AS 1:INPUT #1,A$,B:PRINT A$;B*6;EOF(1):CLOSE\015"}); + wait_row(3, "XY 42 -1"); + +`ifndef STOP_BEFORE_MONITOR + // ---- the machine-code monitor + uart_str("MONITOR\015"); + wait_at(0, 50, "STOPPED BY MONITOR COMMAND"); + wait_at(2, 0, " PC "); + wait_at(29, 0, "> "); + pc_a = screen_pc(0); + wait_at(9, 0, ">"); + jp_txt = {cellraw(9, 19), cellraw(9, 20)}; + jp_to = hex_at(9, 21); + dump_screen; + uart_str("\015"); // Enter: one step + wait_at(0, 50, "STOPPED BY STEP"); + wait_at(29, 0, "> "); + pc_b = screen_pc(0); + // MONITOR stops on a J (to the end of BASIC's statement routine): one + // step must land exactly on its target + if (jp_txt == "J " && pc_b == jp_to) $display("PASS step: PC %h -> %h", pc_a, pc_b); + else begin $display("FAIL step: PC %h -> %h, wanted %h (%0s)", pc_a, pc_b, jp_to, jp_txt); errors = errors + 1; end + // a breakpoint where the step stopped (the end of BASIC's statement + // routine), hit again by OUT; leaving from it steps off it first + uart_str("B "); for (i = 0; i < 8; i = i + 1) uart_send(cellraw(2, 4 + i)); uart_send(8'h0D); + wait_at(29, 40, "BREAKPOINT SET"); + uart_str("X\015"); + wait_row(3, "XY 42 -1"); // BASIC's screen is back as it was + uart_str("OUT 32,7\015"); + wait_at(0, 50, "STOPPED BY BREAKPOINT"); + wait_at(29, 0, "> "); + if (screen_pc(0) == pc_b) $display("PASS breakpoint at %h", pc_b); + else begin $display("FAIL breakpoint: PC %h, wanted %h", screen_pc(0), pc_b); errors = errors + 1; end + uart_str("B\015"); + wait_at(29, 40, "BREAKPOINT CLEARED"); + uart_str("X\015"); + #5_000_000; + // the Pause key + ps2_send(8'hE1); ps2_send(8'h14); ps2_send(8'h77); + ps2_send(8'hE1); ps2_send(8'hF0); ps2_send(8'h14); ps2_send(8'hF0); ps2_send(8'h77); + wait_at(0, 50, "STOPPED BY PAUSE KEY"); + wait_at(29, 0, "> "); + uart_str("X\015"); + #2_000_000; + uart_str("CLS:PRINT 3*4\015"); + wait_row(0, " 12"); + + // ---- 3 Mbaud (SW1:0 = 11): a program in, its output on screen and back + sw[1:0] = 2'b11; + BIT_NS = 1_000_000_000.0 / 3_000_000; + #200_000; + tx_n = 0; tx_log = 0; + uart_str({"CLS:NEW\01510 FOR I=1 TO 3:PRINT I*111;:NEXT I\01520 PRINT \"FAST\"\015", + "RUN\015"}); + wait_row(5, " 111 222 333 FAST"); + #2_000_000; + if (tx_log[8*7-1:0] == "READY\015\012") $display("PASS 3 Mbaud: %0d bytes back, ending READY", tx_n); + else begin $display("FAIL 3 Mbaud: %0d bytes back, last %h", tx_n, tx_log[8*7-1:0]); errors = errors + 1; end + + // ---- memory files: the monitor's SAVE/LOAD/DIR, BASIC's BSAVE/BLOAD + uart_str("CLS:POKE 73728,72:POKE 73729,73:MONITOR\015"); + wait_at(29, 0, "> "); + uart_str("SAVE \"MEM1\" 12000 12001\015"); + wait_at(29, 40, "SAVED"); + uart_str("E 12000 00 00\015"); + wait_at(29, 0, "> "); + uart_str("LOAD \"MEM1\"\015"); + wait_at(29, 40, "LOADED 12000-12001"); + wait_at(22, 0, " 12000 48 49 "); + uart_str("DIR\015"); + wait_at(29, 40, "M TO SHOW MEMORY AGAIN"); + uart_str("X\015"); + #3_000_000; + uart_str("CLS:POKE 73728,0:BLOAD \"MEM1\":BSAVE \"MEM2\",73728,2:BLOAD \"MEM2\",73730:PRINT PEEK(73730);PEEK(73731)\015"); + wait_row(0, " 72 73"); + + // ---- the assembler: source typed into BASIC, saved, assembled by the monitor + uart_str({"NEW\01510 ORG 12000H\01520 START: LA A1,MSG\01530 LOOP: LBU A0,0(A1)\015", + "40 BEQZ A0,DONE\01550 WAIT: LBU T0,-256(ZERO)\01560 ANDI T0,T0,2\015"}); + uart_str({"70 BEQZ T0,WAIT\01580 SB A0,-255(ZERO)\01590 ADDI A1,A1,1\015100 J LOOP\015", + "110 DONE: RET\015"}); + uart_str({"120 MSG: DB \"ASM OK\",0 ; THE MESSAGE\015SAVE \"HELLO\"\015MONITOR\015"}); + wait_at(29, 0, "> "); + uart_str("ASM \"HELLO\"\015"); + wait_at(29, 40, "ASSEMBLED 12000-12032"); + uart_str("A 12100\015LI A0,66\015\015"); + wait_at(9, 2, "12100 04200513 LI A0,66"); + // an Intel HEX record above 64K (an extended address first) and the end record + uart_str(":020000040001F9\015:03210000AABBCCAB\015:00000001FF\015"); + wait_at(29, 40, "HEX LOADED 12100-12102"); + if (dut.sys.ram1[12'h840][23:0] == 24'hCCBBAA) + $display("PASS hex record in memory"); + else begin + $display("FAIL hex record: %h", dut.sys.ram1[12'h840]); + errors = errors + 1; + end + uart_str("X\015"); + #3_000_000; + uart_str("CLS:CALL 73728\015"); + wait_row(0, "ASM OK"); + + // ---- Ctrl-Alt-Del restarts the computer + ps2_send(8'h14); ps2_send(8'h11); ps2_send(8'hE0); ps2_send(8'h71); + ps2_send(8'hE0); ps2_send(8'hF0); ps2_send(8'h71); ps2_send(8'hF0); ps2_send(8'h11); + ps2_send(8'hF0); ps2_send(8'h14); + // the restarted BASIC's banner, on whichever row it lands + t_cmd = $realtime; + while ({cellraw(2, 0), cellraw(2, 1)} != "DA" && {cellraw(3, 0), cellraw(3, 1)} != "DA" && + {cellraw(4, 0), cellraw(4, 1)} != "DA" && $realtime - t_cmd < 50_000_000) #100_000; + if ($realtime - t_cmd < 50_000_000) $display("PASS Ctrl-Alt-Del restarted BASIC"); + else begin $display("FAIL Ctrl-Alt-Del: no banner"); errors = errors + 1; end + dump_screen; +`endif + if (errors == 0) $display("ALL TESTS PASSED"); + else $display("%0d TESTS FAILED", errors); + $finish; + end +endmodule diff --git a/terminfo/basys3.ti b/terminfo/basys3.ti new file mode 100644 index 0000000..b86b32e --- /dev/null +++ b/terminfo/basys3.ti @@ -0,0 +1,24 @@ +# terminfo for the Basys 3 FPGA terminal: a VT220 with 16 ANSI colours, +# underline, blink, 80x32 (basys3) or 132x64 after ESC[?3h (basys3-w). +# tic -x -o ~/.terminfo terminfo/basys3.ti then export TERM=basys3 +basys3|Basys 3 FPGA VT220 terminal with ANSI colour, + lines#32, cols#80, + colors#16, pairs#256, + op=\E[39;49m, + setaf=\E[%?%p1%{8}%<%t3%p1%d%e9%p1%{8}%-%d%;m, + setab=\E[%?%p1%{8}%<%t4%p1%d%e10%p1%{8}%-%d%;m, + invis=\E[8m, + rmso=\E[27m, rmul=\E[24m, + sgr0=\E[m\017\E(B, + kbs=\177, + khome=\E[1~, kend=\E[4~, + kf5=\E[15~, + indn=\E[%p1%dS, rin=\E[%p1%dT, + cnl=\E[%p1%dE, cpl=\E[%p1%dF, + hpa=\E[%i%p1%dG, vpa=\E[%i%p1%dd, + cbt=\E[Z, + use=vt220, +basys3-w|Basys 3 FPGA terminal in 132-column mode, + lines#64, cols#132, + is2=\E[?3h, rs2=\E[?3h, + use=basys3, diff --git a/tests/irq.S b/tests/irq.S new file mode 100644 index 0000000..c2fbd8f --- /dev/null +++ b/tests/irq.S @@ -0,0 +1,178 @@ +# Interrupts: each source, masking by mie and mstatus.MIE, priority, and code +# that is interrupted again and again giving the same result as without. +# Uses the test device in sim/tb_cpu.v at FFFFFF00. + +#include "riscv_test.h" +#include "test_macros.h" + +#define DEV -256 /* 0xFFFFFF00 */ +#define SOFT 1 +#define TIMER 2 +#define EXT 4 +#define LOCAL 8 + +# raise lines after delay cycles +#define RAISE(lines, delay) li t0, ((delay) << 8) | (lines); sw t0, DEV(zero) + +# spin until the handler has run (s2 != count), or fail after a while +#define WAIT_IRQ(count) \ + li t1, 1000; \ +1: li t0, count; bne s2, t0, 2f; addi t1, t1, -1; bnez t1, 1b; j fail; 2: + +RVTEST_RV32M +RVTEST_CODE_BEGIN + + li s2, 0 + csrsi mstatus, MSTATUS_MIE + + # each source, with its own enable bit + li TESTNUM, 2 + li t0, MIP_MTIP; csrw mie, t0 + RAISE(TIMER, 20) + WAIT_IRQ(0) + li t0, 0x80000007; bne s1, t0, fail + + li TESTNUM, 3 + li t0, MIP_MEIP; csrw mie, t0 + RAISE(EXT, 5) + WAIT_IRQ(1) + li t0, 0x8000000b; bne s1, t0, fail + + li TESTNUM, 4 + li t0, MIP_MSIP; csrw mie, t0 + RAISE(SOFT, 0) + WAIT_IRQ(2) + li t0, 0x80000003; bne s1, t0, fail + + li TESTNUM, 5 + li t0, 1 << 16; csrw mie, t0 + RAISE(LOCAL, 3) + WAIT_IRQ(3) + li t0, 0x80000010; bne s1, t0, fail + + # masked by mie: pending shows in mip but nothing is taken + li TESTNUM, 6 + csrw mie, zero + RAISE(TIMER, 0) + li t1, 100 +1: addi t1, t1, -1; bnez t1, 1b + li t0, 4; bne s2, t0, fail + csrr t0, mip; andi t0, t0, MIP_MTIP; beqz t0, fail + li t0, MIP_MTIP; csrs mie, t0 # now it is taken + WAIT_IRQ(4) + + # masked by mstatus.MIE + li TESTNUM, 7 + csrci mstatus, MSTATUS_MIE + RAISE(EXT, 0) + li t0, MIP_MEIP; csrw mie, t0 + li t1, 100 +1: addi t1, t1, -1; bnez t1, 1b + li t0, 5; bne s2, t0, fail + csrsi mstatus, MSTATUS_MIE + WAIT_IRQ(5) + li t0, 0x8000000b; bne s1, t0, fail + # the handler saw MPIE set and MIE clear + li t0, MSTATUS_MPIE; and t1, s3, t0; beqz t1, fail + andi t1, s3, MSTATUS_MIE; bnez t1, fail + # and mret turned MIE back on + csrr t0, mstatus; andi t0, t0, MSTATUS_MIE; beqz t0, fail + + # priority: external, then software, then timer, then local + li TESTNUM, 8 + li t0, MIP_MEIP | MIP_MSIP | MIP_MTIP | (1 << 16); csrw mie, t0 + csrci mstatus, MSTATUS_MIE + RAISE(EXT | SOFT | TIMER | LOCAL, 0) + li t1, 10 +1: addi t1, t1, -1; bnez t1, 1b + csrsi mstatus, MSTATUS_MIE + WAIT_IRQ(6) + li t0, 0x8000000b; bne s1, t0, fail + li TESTNUM, 9 + csrci mstatus, MSTATUS_MIE + RAISE(SOFT | TIMER | LOCAL, 0) + li t1, 10 +1: addi t1, t1, -1; bnez t1, 1b + csrsi mstatus, MSTATUS_MIE + WAIT_IRQ(7) + li t0, 0x80000003; bne s1, t0, fail + li TESTNUM, 10 + csrci mstatus, MSTATUS_MIE + RAISE(TIMER | LOCAL, 0) + li t1, 10 +1: addi t1, t1, -1; bnez t1, 1b + csrsi mstatus, MSTATUS_MIE + WAIT_IRQ(8) + li t0, 0x80000007; bne s1, t0, fail + + # a workout: once quietly, once with the timer firing every few cycles + li TESTNUM, 11 + csrw mie, zero + jal workout + mv s5, a0 + li s4, 1 # handler re-arms the timer + li t0, MIP_MTIP; csrw mie, t0 + RAISE(TIMER, 3) + jal workout + csrw mie, zero + li s4, 0 + bne a0, s5, fail + li t0, 100; blt s2, t0, fail # it really was interrupted a lot + + TEST_PASSFAIL + +# mixes ALU, mul, div, loads, stores and branches; result in a0 +workout: + la a1, buf + li a0, 12345 + li a2, 150 +1: + mul a3, a0, a2 + addi a3, a3, 77 + divu a4, a3, a2 + rem a5, a3, a2 + xor a0, a0, a4 + add a0, a0, a5 + slli a6, a2, 2 + andi a6, a6, 60 + add a6, a6, a1 + sw a0, 0(a6) + lh a7, 2(a6) + lbu a3, 1(a6) + add a0, a0, a7 + sub a0, a0, a3 + mulh a4, a0, a0 + add a0, a0, a4 + sb a0, 5(a6) + lw a4, 4(a6) + add a0, a0, a4 + addi a2, a2, -1 + bnez a2, 1b + ret + + .align 2 + .global mtvec_handler +mtvec_handler: + csrr s1, mcause + csrr s3, mstatus + bgez s1, fail # not an interrupt + addi s2, s2, 1 + li t5, DEV + beqz s4, 1f + andi t6, s2, 31 # re-arm after 20..51 cycles + addi t6, t6, 20 + slli t6, t6, 8 + ori t6, t6, TIMER + sw t6, 0(t5) + mret +1: + sw zero, 0(t5) + mret + +RVTEST_CODE_END + + .data +RVTEST_DATA_BEGIN + TEST_DATA +buf: .fill 32, 4, 0 +RVTEST_DATA_END diff --git a/tests/link.ld b/tests/link.ld new file mode 100644 index 0000000..8c10a49 --- /dev/null +++ b/tests/link.ld @@ -0,0 +1,19 @@ +/* riscv-tests image: everything from address 0 (the core's reset vector); + tests/nmi.S puts its NMI handler at 8000h, tb_cpu.v's NMI_VEC. */ +OUTPUT_ARCH( "riscv" ) +ENTRY(_start) +SECTIONS +{ + . = 0x0; + .text.init : { *(.text.init) } + . = ALIGN(0x1000); + .tohost : { *(.tohost) } + . = ALIGN(0x1000); + .text : { *(.text) } + . = ALIGN(0x1000); + .data : { *(.data) } + .bss : { *(.bss) } + . = 0x8000; + .nmi : { KEEP(*(.nmi)) } + _end = .; +} diff --git a/tests/nmi.S b/tests/nmi.S new file mode 100644 index 0000000..1a5ebbc --- /dev/null +++ b/tests/nmi.S @@ -0,0 +1,89 @@ +# Resumable NMI: one from the nmi line, then single steps from nmi_step. +# The handler is at 8000h (tb_cpu.v's NMI_VEC); the test device is FFFFFF00. + +#include "riscv_test.h" +#include "test_macros.h" + +#define DEV -256 +#define NMI 16 +#define STEP 32 +#define RAISE(lines, delay) li t0, ((delay) << 8) | (lines); sw t0, DEV(zero) + +RVTEST_RV32M +RVTEST_CODE_BEGIN + + li s2, 0 + # NMIE starts set + li TESTNUM, 2 + csrr t0, CSR_MNSTATUS; andi t0, t0, MNSTATUS_NMIE; beqz t0, fail + + # an NMI from the line: handler runs once, mnret comes back here + li TESTNUM, 3 + li s4, 0 # handler mode: drop the line + RAISE(NMI, 10) + li t1, 1000 +1: bnez s2, 2f; addi t1, t1, -1; bnez t1, 1b; j fail +2: li t0, 1; bne s2, t0, fail + csrr t0, CSR_MNSTATUS; andi t0, t0, MNSTATUS_NMIE; beqz t0, fail + andi t0, s5, MNSTATUS_NMIE; bnez t0, fail # clear inside the handler + + # NMIs are masked while NMIE is clear + li TESTNUM, 4 + csrci CSR_MNSTATUS, MNSTATUS_NMIE + RAISE(NMI, 0) + li t1, 50 +1: addi t1, t1, -1; bnez t1, 1b + li t0, 1; bne s2, t0, fail + csrsi CSR_MNSTATUS, MNSTATUS_NMIE + li t1, 50 +1: addi t1, t1, -1; bnez t1, 1b + li t0, 2; bne s2, t0, fail + + # single steps: the handler logs mnepc and stops after four + li TESTNUM, 5 + li s2, 0 + li s4, 1 # handler mode: log, stop after 4 + la s6, log + RAISE(STEP, 0) +step0: + addi a0, x0, 1 +step1: + addi a0, a0, 1 +step2: + addi a0, a0, 1 +step3: + addi a0, a0, 1 + addi a0, a0, 1 + li t0, 4; bne s2, t0, fail + li t0, 5; bne a0, t0, fail # every instruction ran once + # the stops were after the RAISE's store, then after each instruction + la s6, log + la t0, step0; lw t1, 0(s6); bne t0, t1, fail + la t0, step1; lw t1, 4(s6); bne t0, t1, fail + la t0, step2; lw t1, 8(s6); bne t0, t1, fail + la t0, step3; lw t1, 12(s6); bne t0, t1, fail + + TEST_PASSFAIL + + .section .nmi, "ax" +nmi_handler: + csrr s5, CSR_MNSTATUS + addi s2, s2, 1 + bnez s4, 1f + sw zero, DEV(zero) # drop the line + .word 0x70200073 # mnret +1: + csrr t5, CSR_MNEPC + sw t5, 0(s6) + addi s6, s6, 4 + li t5, 4 + bne s2, t5, 2f + sw zero, DEV(zero) # stop stepping +2: + .word 0x70200073 # mnret + + .data +RVTEST_DATA_BEGIN + TEST_DATA +log: .fill 8, 4, 0 +RVTEST_DATA_END diff --git a/tools/bin2mem.py b/tools/bin2mem.py new file mode 100644 index 0000000..9fbb58a --- /dev/null +++ b/tools/bin2mem.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +"""Binary image -> $readmemh file of 32-bit little-endian words. + + bin2mem.py image.bin image.mem [words] (pads with zeros to `words`) +""" +import sys + +data = open(sys.argv[1], 'rb').read() +data += b'\0' * (-len(data) % 4) +words = int(sys.argv[3]) if len(sys.argv) > 3 else len(data) // 4 +if len(data) // 4 > words: + raise SystemExit("%s: %d bytes, more than %d words" % (sys.argv[1], len(data), words)) +data += b'\0' * (words * 4 - len(data)) +with open(sys.argv[2], 'w') as f: + for i in range(0, len(data), 4): + f.write('%08x\n' % int.from_bytes(data[i:i + 4], 'little')) diff --git a/tools/boardemu.py b/tools/boardemu.py new file mode 100644 index 0000000..549519a --- /dev/null +++ b/tools/boardemu.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 +"""A model of the Basys 3 RISC-V computer's game hardware around +tools/rv32emu.py, for testing programs on the PC: the terminal (port 1), the +graphics layer with scrolling (30h-37h), the sprites (70h-78h) and the +held-key port (88h). + + from boardemu import Board, load_ihx, load_font + mem, end = load_ihx("prog.ihx") + b = Board(mem, code_end=end) # runs from GAME_BASE, returns to address 0 + b.run_frames(60, joy=FIRE) + b.shot("screen.png", load_font()) + +The frame counter (78h) moves on when the program comes back to read it after +doing some work (more than 100 instructions since it last moved), so a program +that waits for it to change runs one frame per wait, however long its frames +take, and two reads close together see the same frame. Screenshots need +pyte and Pillow, and are drawn the way the board's video combines the layers: +text over sprites over graphics. +""" +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +from rv32emu import RV32 # noqa: E402 + +GAME_BASE = 0xA200 # where BASIC's loader programs put machine code +STACK_TOP = 0x13FF0 + +PAL = ["000", "A00", "0A0", "A50", "00A", "A0A", "0AA", "AAA", + "555", "F55", "5F5", "FF5", "55F", "F5F", "5FF", "FFF"] +PAL = [tuple(int(c, 16) * 17 for c in p) for p in PAL] +UP, DOWN, LEFT, RIGHT, FIRE, ENTER, ESC = 1, 2, 4, 8, 16, 32, 128 + + +class Board(RV32): + def __init__(self, mem, code_end=0x14000, start=GAME_BASE, rom_top=0): + super().__init__(mem, rom_top=rom_top) + self.code_end = code_end + self.code_start = start + self.steps = 0 # instructions run + self.scroll_x = self.scroll_y = 0 + self.border = False + self.pc, self.sp = start, STACK_TOP + self.x[1] = 0 # ra: the program returns to 0 + self.frame = 0 + self.frame_at = -1000 + self.joy = 0 + self.gfx = bytearray(320 * 240) + self.gxv = self.gyv = 0 + self.spr = [[0, 0, 0, 0] for _ in range(32)] # x, y, shape, ctl + self.sel = 0 + self.xst = 0 + self.pat = bytearray(8192) + self.pat_a = 0 + self.text = bytearray() + self.keys_in = bytearray() + + def io_in(self, port): + p = port & 0xFF + if p == 0: + return (1 if self.keys_in else 0) | 2 + if p == 1: + return self.keys_in.pop(0) if self.keys_in else 0 + if p == 0x78: + if self.steps - self.frame_at > 100: + self.frame += 1 + self.frame_at = self.steps + return self.frame & 0xFF + if p == 0x88: + return self.joy + if p == 0x33: + return self.gfx[self.gyv * 320 + self.gxv] if self.gxv < 320 and self.gyv < 240 else 0 + if p == 0x34: + return 0 + return 0xFF + + def io_out(self, port, v): + p = port & 0xFF + if p == 1: + self.text.append(v) + elif p == 0x30: self.gxv = (self.gxv & 0x100) | v + elif p == 0x31: self.gxv = (self.gxv & 0xFF) | (v & 1) << 8 + elif p == 0x32: self.gyv = v + elif p == 0x33: + if self.gxv < 320 and self.gyv < 240: + self.gfx[self.gyv * 320 + self.gxv] = v & 15 + self.gxv = (self.gxv + 1) & 0x1FF + elif p == 0x34: + self.gfx[:] = bytes([v & 15]) * (320 * 240) + if not v & 0x80: + for s in self.spr: s[3] &= ~1 + self.scroll_x = self.scroll_y = 0 + self.border = False + elif p == 0x35: self.scroll_x = (self.scroll_x & 0x100) | v + elif p == 0x36: + self.scroll_x = (self.scroll_x & 0xFF) | (v & 1) << 8 + self.border = bool(v & 2) + elif p == 0x37: self.scroll_y = v - 240 if v >= 240 else v + elif p == 0x70: self.sel = v & 31 + elif p == 0x71: self.xst = (self.xst & 0x100) | v + elif p == 0x72: self.xst = (self.xst & 0xFF) | (v & 1) << 8 + elif p == 0x73: self.spr[self.sel][0], self.spr[self.sel][1] = self.xst, v + elif p == 0x74: self.spr[self.sel][2] = v & 63 + elif p == 0x75: self.spr[self.sel][3] = v & 7 + elif p == 0x76: self.pat_a = (v & 63) * 128 + elif p == 0x77: + self.pat[self.pat_a & 8191] = v + self.pat_a += 1 + + def run_frames(self, n, joy=0): + """Run until the program has waited for n more frames (or returned).""" + self.joy = joy + end = self.frame + n + while self.frame < end and self.pc != 0: + self.step() + self.steps += 1 + if not (self.code_start <= self.pc < self.code_end or self.pc == 0): + raise SystemExit("PC left the program: %05X" % self.pc) + if self.sp < STACK_TOP - 0x1000: + raise SystemExit("stack ran into memory: SP %05X" % self.sp) + + def screen_text(self): + import pyte + scr = pyte.Screen(80, 32) + pyte.ByteStream(scr).feed(bytes(self.text)) + return scr + + def shot(self, path, font): + from PIL import Image + scr = self.screen_text() + img = Image.new("RGB", (1280, 1024)) + px = img.load() + lay = bytearray(320 * 240) # the graphics as scrolled onto the screen + for y in range(240): + fy = (y + self.scroll_y) % 240 + row = self.gfx[fy * 320:(fy + 1) * 320] + sx = self.scroll_x % 320 + lay[y * 320:(y + 1) * 320] = row[sx:] + row[:sx] + if self.border: # hidden: 4 columns each side, 2 rows top and bottom + if y < 2 or y >= 238: + lay[y * 320:(y + 1) * 320] = bytes(320) + else: + lay[y * 320:y * 320 + 4] = bytes(4) + lay[y * 320 + 316:(y + 1) * 320] = bytes(4) + for s in reversed(self.spr): # sprite 0 in front + x0, y0, shape, ctl = s + if not ctl & 1: + continue + for r in range(16): + for c in range(16): + rr = 15 - r if ctl & 4 else r + cc = 15 - c if ctl & 2 else c + b = self.pat[shape * 128 + rr * 8 + cc // 2] + col = b & 15 if cc & 1 else b >> 4 + x, y = (x0 + c) & 511, (y0 + r) & 255 + if col and x < 320 and y < 240: + lay[y * 320 + x] = col | 16 + for y in range(1024): + for x in range(1280): + gx, gy = x >> 2, y >> 2 + c = lay[gy * 320 + gx] & 15 if gy < 240 else 0 + px[x, y] = PAL[c] + names = ["black", "red", "green", "brown", "blue", "magenta", "cyan", "white"] + for r in range(32): + for c in range(80): + ch = scr.buffer[r][c] + code = ord(ch.data[0]) if ch.data else 32 + if code == 32 and ch.bg == "default": + continue + def colour(n, d): + if n in names: return PAL[names.index(n)] + if n.startswith("bright") and n[6:] in names: return PAL[names.index(n[6:]) + 8] + try: + v = int(n, 16); return ((v >> 16) & 255, (v >> 8) & 255, v & 255) + except ValueError: + return d + fg = colour(ch.fg, PAL[10]) + bg = colour(ch.bg, None) + for y in range(16): + bits = font[(code if code < 256 else 63) * 16 + y] + for x in range(8): + on = bits & (0x80 >> x) + for dy in (0, 1): + for dx in (0, 1): + X, Y = c * 16 + 2 * x + dx, r * 32 + 2 * y + dy + if on: px[X, Y] = fg + elif bg is not None and px[X, Y] == (0, 0, 0): px[X, Y] = bg + img.save(path) + + +def load_ihx(path): + """Memory image and the end of the loaded bytes (Intel HEX with type 04 + extended linear addresses, as objcopy writes it).""" + mem = bytearray(0x28000) + hi = 0 + base = 0 + for line in open(path): + if not line.startswith(":"): + continue + n, a, t = int(line[1:3], 16), int(line[3:7], 16), int(line[7:9], 16) + if t == 0: + mem[base + a:base + a + n] = bytes.fromhex(line[9:9 + 2 * n]) + hi = max(hi, base + a + n) + elif t == 4: + base = int(line[9:13], 16) << 16 + return mem, hi + + +def load_syms(path): + """Symbol addresses from `nm` output.""" + sym = {} + for line in open(path): + f = line.split() + if len(f) == 3: + sym[f[2]] = int(f[0], 16) + return sym + + + +def load_font(): + root = os.path.join(HERE, "..") + return [int(l.split("//")[0], 16) for l in open(os.path.join(root, "font", "font.mem")) + if l.split("//")[0].strip()] diff --git a/tools/get-bas.py b/tools/get-bas.py new file mode 100755 index 0000000..b1c050c --- /dev/null +++ b/tools/get-bas.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +"""Copy the program in the Basys 3 RISC-V computer's memory to a file on the PC, or send +BASIC a command and print what it answers. + +The board needs SW15 and SW14 up (computer mode, PC serial linked: the computer's +output is then copied to the PC), and nothing else may be using the port +(stop the getty first). The baud rate must match SW1:0. BASIC's clock is set +to the PC's first (unless --no-date), so files saved get today's date. + + tools/get-bas.py myprog.bas --baud 9600 # LIST into myprog.bas + tools/get-bas.py --cmd 'LOAD "DEMO"' --baud 9600 # run a command, show output +""" +import argparse +import os +import re +import select +import termios +import time + +BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600, + 3000000: termios.B3000000} + +ap = argparse.ArgumentParser() +ap.add_argument("file", nargs="?", help="where to write the listing") +ap.add_argument("--cmd", action="append", help="send this command instead (repeatable)") +ap.add_argument("--port", default="/dev/ttyUSB1") +ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS)) +ap.add_argument("--timeout", type=float, default=30, help="seconds to wait for READY") +ap.add_argument("--no-date", action="store_true", help="don't set BASIC's clock") +a = ap.parse_args() +if not a.file and not a.cmd: + ap.error("give a file name or --cmd") + +fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY) +t = termios.tcgetattr(fd) +t[0] = termios.IXON +t[1] = 0 +t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL +t[3] = 0 +t[4] = t[5] = BAUDS[a.baud] +t[6][termios.VMIN] = 0 +t[6][termios.VTIME] = 0 +termios.tcsetattr(fd, termios.TCSANOW, t) +termios.tcflush(fd, termios.TCIFLUSH) + + +def run(cmd): + """Send one line; return everything BASIC prints up to its next READY.""" + os.write(fd, cmd.encode("ascii") + b"\r") + buf = b"" + end = time.time() + a.timeout + while time.time() < end: + r, _, _ = select.select([fd], [], [], 0.2) + if r: + buf += os.read(fd, 4096) + if re.search(rb"\r\nREADY\r\n$", buf): + break + text = buf.decode("latin-1").replace("\r", "") + lines = text.split("\n") + if lines and lines[0].strip() == cmd.strip(): # BASIC echoes the command + lines = lines[1:] + return "\n".join(l for l in lines if l != "READY").strip("\n") + + +if not a.no_date: + run(time.strftime('DATE "%Y-%m-%d %H:%M:%S"')) +if a.cmd: + for c in a.cmd: + print(run(c)) +else: + out = run("LIST") + prog = [l for l in out.split("\n") if re.match(r"\d+ ", l)] + with open(a.file, "w") as f: + f.write("\n".join(prog) + "\n") + print("%d lines written to %s" % (len(prog), a.file)) +os.close(fd) diff --git a/tools/psf2mem.py b/tools/psf2mem.py new file mode 100644 index 0000000..e57f461 --- /dev/null +++ b/tools/psf2mem.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +"""Convert a Linux console PSF font (8x16) into a CP437-ordered font ROM. + +Output is a $readmemh file with 4096 lines: byte (code*16 + row), MSB = leftmost pixel. + +usage: psf2mem.py [font.psf.gz[,fallback.psf.gz...]] [out.mem] [preview.png] +Glyphs missing from the first font are taken from the fallbacks in order. +""" +import gzip +import struct +import sys + +CP437_LOW = ("\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼") + + +DEFAULT_FONTS = ",".join("/usr/share/consolefonts/%s.psf.gz" % f for f in + ("Uni2-VGA16", "FullGreek-VGA16", "Vietnamese-TerminusBoldVGA16")) + +# Fonts often carry the triangle pointers under their newer code points. +CP437_ALT = {"►": "▶", "◄": "◀"} + + +def cp437(code): + if code < 0x20: + return CP437_LOW[code] + if code == 0x7F: + return "⌂" + return bytes([code]).decode("cp437") + + +def load_psf(path): + raw = gzip.open(path).read() if path.endswith(".gz") else open(path, "rb").read() + if raw[:2] == b"\x36\x04": + mode, charsize = raw[2], raw[3] + count = 512 if mode & 1 else 256 + width, height, hdr = 8, charsize, 4 + has_table = bool(mode & 6) + glyphs = [raw[hdr + i * charsize: hdr + (i + 1) * charsize] for i in range(count)] + table = {} + if has_table: + pos, g = hdr + count * charsize, 0 + while g < count and pos + 1 < len(raw): + (u,) = struct.unpack_from(" 1 and sys.argv[1] else DEFAULT_FONTS + out = sys.argv[2] if len(sys.argv) > 2 else "font.mem" + fonts = [] + for path in src.split(","): + glyphs, table, width, height = load_psf(path) + if width != 8 or height != 16: + raise SystemExit(f"{path}: need an 8x16 font, got {width}x{height}") + fonts.append((glyphs, table)) + missing = [] + rom = [] + for code in range(256): + ch = cp437(code) + glyph = None + if code not in (0, 0x20): + for glyphs, table in fonts: + g = table.get(ch, code if not table else None) + if g is None and ch in CP437_ALT: + g = table.get(CP437_ALT[ch]) + if g is not None: + glyph = glyphs[g][:16] + break + if glyph is None: + missing.append(f"{code:02X}") + rom.extend(glyph or [0] * 16) + with open(out, "w") as f: + f.write("// CP437 order, 256 glyphs x 16 rows, from: %s\n" + % ", ".join(p.split("/")[-1] for p in src.split(","))) + for b in rom: + f.write(f"{b:02x}\n") + print(f"wrote {out}; glyphs missing: {' '.join(missing) or 'none'}") + if len(sys.argv) > 3: + from PIL import Image + img = Image.new("1", (32 * 9, 8 * 17), 0) + for code in range(256): + ox, oy = (code % 32) * 9, (code // 32) * 17 + for r in range(16): + for c in range(8): + if rom[code * 16 + r] & (0x80 >> c): + img.putpixel((ox + c, oy + r), 1) + img.save(sys.argv[3]) + + +if __name__ == "__main__": + main() diff --git a/tools/rv32emu.py b/tools/rv32emu.py new file mode 100644 index 0000000..f5a679f --- /dev/null +++ b/tools/rv32emu.py @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""RV32IM emulator of the Basys 3 RISC-V computer, for testing programs on the +PC and as a reference for rtl/rv32_cpu.v. + +The same machine as rtl/rv32_cpu.v and rtl/rv32_system.v: RV32IM, machine +mode, the CSRs the core has (no triggers), the resumable NMI, 80 KB of RAM +(writes below rom_top ignored), the monitor's 32 KB ROM at 20000h and 8 KB of +RAM at 28000h, the I/O ports at FFFFFF00h + N (io_in / io_out, to be +overridden) and the 32-bit registers at FFFFFE00h + N. + + python3 tools/rv32emu.py image.bin [--input FILE] [--max N] [--trace FILE] + +runs a raw image from address 0 with the console on ports 0/1: text from +--input is typed, output goes to stdout. --trace writes "pc instruction" for +each instruction run. The emulator also counts the clocks rv32_cpu would take +(cycles; see cost()). +""" +import sys + +M32 = 0xFFFFFFFF +RAM_END = 0x14000 +MON_BASE, MON_RAM, MON_END = 0x20000, 0x28000, 0x2A000 +MEM_SIZE = MON_END + + +class Trap(Exception): + def __init__(self, cause, tval=0): + self.cause, self.tval = cause, tval + + +def sx(v, bits): + v &= (1 << bits) - 1 + return v - (1 << bits) if v >> (bits - 1) else v + + +def s32(v): + return v - (1 << 32) if v & 0x80000000 else v + + +class RV32: + def __init__(self, mem=b"", rom_top=0, inp=b"", out=None): + self.m = bytearray(MEM_SIZE) + self.m[:len(mem)] = mem + self.rom_top = rom_top # writes below are ignored + self.x = [0] * 32 + self.pc = 0 + self.cache = {} + self.csr = {0x300: 0, 0x304: 0, 0x305: 0, 0x340: 0, 0x341: 0, 0x342: 0, 0x343: 0, + 0x740: 0, 0x741: 0, 0x742: 0} + self.nmie = True + self.count = 0 # instructions completed + self.cycles = 0 # clocks rv32_cpu would take (see cost()) + self.inp = bytearray(inp) + self.out = out if out is not None else bytearray() + self.step_arm = False # nmi after the next instruction (port 60) + self.stepped = False + self.nmi_pending = False + self.why = 0 + self.bp = [0, 0] + self.bp_on = 0 + + @property + def sp(self): + return self.x[2] + + @sp.setter + def sp(self, v): + self.x[2] = v & M32 + + # ---------------------------------------------------------------- memory + def rd8(self, a): + if a < MEM_SIZE: + return self.m[a] + if a >= 0xFFFFFF00: + return self.io_in(a & 0xFF) & 0xFF + if a >= 0xFFFFFE00: + return self.word_in(a & 0xFC) >> (8 * (a & 3)) & 0xFF + return 0 + + def rd16(self, a): + if a < MEM_SIZE - 1: + return self.m[a] | self.m[a + 1] << 8 + return self.rd8(a) | self.rd8(a + 1) << 8 + + def rd32(self, a): + if a < MEM_SIZE - 3: + return int.from_bytes(self.m[a:a + 4], "little") + if a >= 0xFFFFFF00: + return self.io_in(a & 0xFF) & 0xFF + if a >= 0xFFFFFE00: + return self.word_in(a & 0xFC) & M32 + return 0 + + def writable(self, a): + return self.rom_top <= a < RAM_END or MON_RAM <= a < MON_END + + def wr8(self, a, v): + if a < MEM_SIZE: + if self.writable(a): + self.m[a] = v & 0xFF + if a & ~3 in self.cache: + del self.cache[a & ~3] + elif a >= 0xFFFFFF00: + self.port_out(a & 0xFF, v & 0xFF) + elif a >= 0xFFFFFE00 and not a & 3: + self.word_out(a & 0xFC, v & 0xFF) + + def wr16(self, a, v): + self.wr8(a, v) + self.wr8(a + 1, v >> 8) + + def wr32(self, a, v): + if a >= 0xFFFFFF00: + self.port_out(a & 0xFF, v & 0xFF) + elif a >= 0xFFFFFE00: + self.word_out(a & 0xFC, v & M32) + else: + for i in range(4): + self.wr8(a + i, v >> 8 * i) + + # -------------------------------------------------------------- devices + def io_in(self, port): + """A port read; override. The console is ports 0 and 1.""" + if port == 0: + return (1 if self.inp else 0) | 2 + if port == 1: + return self.inp.pop(0) if self.inp else 0 + if port == 0x60: + return self.why + if port == 0x34: + return 0 # graphics fill: done at once + return 0xFF + + def io_out(self, port, v): + """A port write; override.""" + if port == 1: + self.out.append(v) + + def port_out(self, port, v): + if port == 0x60: + self.step_arm = bool(v & 2) + elif port == 0x61: + if not self.nmi_pending and not self.in_monitor(): + self.nmi_pending, self.why_r = True, 2 + elif port == 0x67: + self.bp_on = v & 3 + self.io_out(port, v) + + def millis(self): + return self.count // 30000 # about 30 instructions a microsecond + + def word_in(self, a): + if a == 0x00: + return self.millis() & M32 + if a == 0x04: + return (self.count // 30) & M32 + if a == 0x10: + return self.bp[0] + if a == 0x14: + return self.bp[1] + return 0 + + def word_out(self, a, v): + if a == 0x10: + self.bp[0] = v + elif a == 0x14: + self.bp[1] = v + + def in_monitor(self): + return MON_BASE <= self.pc < MON_RAM + + # ------------------------------------------------------------------ CSRs + def csr_read(self, n): + if n == 0x300: + return self.csr[0x300] | 0x1800 + if n == 0x301: + return 0x40001100 + if n == 0x344: + return 0 + if n == 0x744: + return 0x1800 | (8 if self.nmie else 0) + if n in (0xB00, 0xC00, 0xC01, 0xB02, 0xC02): + return self.count & M32 + if n in (0xB80, 0xC80, 0xC81, 0xB82, 0xC82): + return self.count >> 32 & M32 + if n in (0xF11, 0xF12, 0xF13, 0xF14, 0xF15, 0x310, 0x7A0, 0x7A1, 0x7A2): + return 0 # (no triggers: tselect stays 0, tdata1 type 0) + if n in self.csr: + return self.csr[n] + raise Trap(2) + + def csr_write(self, n, v): + if n >> 10 == 3: + raise Trap(2) + if n == 0x300: + self.csr[0x300] = v & 0x88 + elif n == 0x304: + self.csr[0x304] = v & 0xFFFF0888 + elif n in (0x305, 0x341, 0x741): + self.csr[n] = v & ~3 & M32 + elif n == 0x744: + self.nmie = bool(v & 8) + elif n in self.csr: + self.csr[n] = v & M32 + elif n in (0x301, 0x344, 0x310, 0x7A0, 0x7A1, 0x7A2): + pass + elif n in (0xB00, 0xB02): # the count after this instruction is v + self.count = (self.count & ~M32 | v) - 1 + elif n in (0xB80, 0xB82): + self.count = (self.count & M32 | v << 32) - 1 + else: + raise Trap(2) + + # --------------------------------------------------------------- decode + def decode(self, pc): + ins = self.rd32(pc) + opc, rd, f3 = ins & 0x7F, ins >> 7 & 31, ins >> 12 & 7 + rs1, rs2, f7 = ins >> 15 & 31, ins >> 20 & 31, ins >> 25 + x = self.x + nxt = (pc + 4) & M32 + immi = sx(ins >> 20, 12) + ill = Trap(2, ins) + + def illegal(): + raise ill + + if opc == 0x37 or opc == 0x17: # lui, auipc + v = (ins & 0xFFFFF000) + (pc if opc == 0x17 else 0) & M32 + if rd == 0: + return lambda: nxt + + def f(): + x[rd] = v + return nxt + return f + if opc == 0x6F: # jal + t = (pc + sx((ins >> 31) << 20 | (ins >> 12 & 0xFF) << 12 | (ins >> 20 & 1) << 11 | + (ins >> 21 & 0x3FF) << 1, 21)) & M32 + + def f(): + if t & 3: + raise Trap(0, t) + if rd: + x[rd] = nxt + return t + return f + if opc == 0x67 and f3 == 0: # jalr + def f(): + t = (x[rs1] + immi) & 0xFFFFFFFE + if t & 3: + raise Trap(0, t) + if rd: + x[rd] = nxt + return t + return f + if opc == 0x63 and f3 not in (2, 3): # branches + t = (pc + sx((ins >> 31) << 12 | (ins >> 7 & 1) << 11 | (ins >> 25 & 0x3F) << 5 | + (ins >> 8 & 15) << 1, 13)) & M32 + cmp = [lambda a, b: a == b, lambda a, b: a != b, None, None, + lambda a, b: s32(a) < s32(b), lambda a, b: s32(a) >= s32(b), + lambda a, b: a < b, lambda a, b: a >= b][f3] + + def f(): + if cmp(x[rs1], x[rs2]): + if t & 3: + raise Trap(0, t) + return t + return nxt + return f + if opc == 0x03 and f3 in (0, 1, 2, 4, 5): # loads + def f(): + a = (x[rs1] + immi) & M32 + if f3 == 2: + if a & 3: + raise Trap(4, a) + v = self.rd32(a) + elif f3 & 3 == 1: + if a & 1: + raise Trap(4, a) + v = self.rd16(a) + if f3 == 1 and v & 0x8000: + v |= 0xFFFF0000 + else: + v = self.rd8(a) + if f3 == 0 and v & 0x80: + v |= 0xFFFFFF00 + if rd: + x[rd] = v + return nxt + return f + if opc == 0x23 and f3 in (0, 1, 2): # stores + imms = sx((ins >> 25) << 5 | (ins >> 7 & 31), 12) + + def f(): + a = (x[rs1] + imms) & M32 + v = x[rs2] + if f3 == 2: + if a & 3: + raise Trap(6, a) + self.wr32(a, v) + elif f3 == 1: + if a & 1: + raise Trap(6, a) + if a >= 0xFFFFFE00: + self.wr32(a, v & 0xFFFF) + else: + self.wr16(a, v) + else: + self.wr8(a, v) + return nxt + return f + if opc == 0x13: # op-imm + sh = rs2 + if (f3 == 1 and f7 != 0) or (f3 == 5 and f7 not in (0, 0x20)): + return illegal + ops = { + 0: lambda a: (a + immi) & M32, + 2: lambda a: int(s32(a) < immi), + 3: lambda a: int(a < (immi & M32)), + 4: lambda a: (a ^ immi) & M32, + 6: lambda a: (a | immi) & M32, + 7: lambda a: (a & immi) & M32, + 1: lambda a: (a << sh) & M32, + 5: (lambda a: (s32(a) >> sh) & M32) if f7 else (lambda a: a >> sh), + } + op = ops[f3] + if rd == 0: + return lambda: nxt + + def f(): + x[rd] = op(x[rs1]) + return nxt + return f + if opc == 0x33 and f7 in (0, 0x20, 1): # op, mul/div + if f7 == 1: + op = [ + lambda a, b: (a * b) & M32, + lambda a, b: (s32(a) * s32(b)) >> 32 & M32, + lambda a, b: (s32(a) * b) >> 32 & M32, + lambda a, b: (a * b) >> 32, + lambda a, b: M32 if b == 0 else (a if (a == 0x80000000 and b == M32) else + int(s32(a) / s32(b)) & M32), + lambda a, b: M32 if b == 0 else a // b, + lambda a, b: a if b == 0 else (0 if (a == 0x80000000 and b == M32) else + (s32(a) - int(s32(a) / s32(b)) * s32(b)) & M32), + lambda a, b: a if b == 0 else a % b, + ][f3] + else: + if f7 == 0x20 and f3 not in (0, 5): + return illegal + op = { + (0, 0): lambda a, b: (a + b) & M32, + (0, 0x20): lambda a, b: (a - b) & M32, + (1, 0): lambda a, b: (a << (b & 31)) & M32, + (2, 0): lambda a, b: int(s32(a) < s32(b)), + (3, 0): lambda a, b: int(a < b), + (4, 0): lambda a, b: a ^ b, + (5, 0): lambda a, b: a >> (b & 31), + (5, 0x20): lambda a, b: (s32(a) >> (b & 31)) & M32, + (6, 0): lambda a, b: a | b, + (7, 0): lambda a, b: a & b, + }[(f3, f7)] + if rd == 0: + return lambda: nxt + + def f(): + x[rd] = op(x[rs1], x[rs2]) + return nxt + return f + if opc == 0x0F and f3 in (0, 1): # fence, fence.i + return lambda: nxt + if opc == 0x73: + if ins == 0x00000073: + def f(): + raise Trap(11) + return f + if ins == 0x00100073: + def f(): + raise Trap(3, pc) + return f + if ins == 0x30200073: # mret + def f(): + st = self.csr[0x300] + self.csr[0x300] = (st & ~8) | (8 if st & 0x80 else 0) | 0x80 + return self.csr[0x341] + return f + if ins == 0x70200073: # mnret + def f(): + self.nmie = True + return self.csr[0x741] + return f + if ins == 0x10500073: # wfi + return lambda: nxt + if f3 in (1, 2, 3, 5, 6, 7): + n = ins >> 20 + uimm = rs1 + + def f(): + src = uimm if f3 & 4 else x[rs1] + write = f3 & 3 == 1 or rs1 != 0 + old = self.csr_read(n) + if write: + v = src if f3 & 3 == 1 else (old | src if f3 & 3 == 2 else old & ~src) + self.csr_write(n, v & M32) + if rd: + x[rd] = old + return nxt + return f + return illegal + + # ------------------------------------------------------------------ run + def trap(self, cause, tval): + self.csr[0x341] = self.pc + self.csr[0x342] = cause + self.csr[0x343] = tval & M32 + st = self.csr[0x300] + self.csr[0x300] = (st & ~0x88) | (0x80 if st & 8 else 0) + self.pc = self.csr[0x305] + + def enter_nmi(self): + self.csr[0x741] = self.pc + self.csr[0x742] = 0x80000000 + self.nmie = False + self.stepped = False + self.pc = MON_BASE + + def step(self): + """One instruction (or the NMI before it).""" + if self.nmie: + hit = self.bp_on & 1 and self.pc == self.bp[0] and 4 or \ + self.bp_on & 2 and self.pc == self.bp[1] and 5 + if self.nmi_pending or hit or (self.step_arm and self.stepped): + self.why = self.why_r if self.nmi_pending else hit or 3 + self.nmi_pending = self.step_arm = False + self.enter_nmi() + return + f = self.cache.get(self.pc) + if f is None: + f = self.cache[self.pc] = self.decode(self.pc) + pc = self.pc + try: + self.pc = f() + except Trap as t: + self.trap(t.cause, t.tval) + self.cycles += 3 + return + self.count += 1 + self.cycles += self.cost(pc) + if self.nmie: + self.stepped = True + + def cost(self, pc): + """Clocks rv32_cpu takes for the instruction at pc, just run: 2, or 3 + for a load, store, jump or taken branch (4 for I/O), 4 for a multiply, + 35 for a divide.""" + ins = self.rd32(pc) + op = ins & 0x7F + if op in (0x03, 0x23): + a = (self.x[ins >> 15 & 31] + sx(ins >> 20 if op == 3 else (ins >> 25) << 5 | (ins >> 7 & 31), 12)) & M32 + return 4 if a >= 0xFFFFFE00 or MON_RAM <= a < MON_END else 3 + if op in (0x6F, 0x67) or (op == 0x63 and self.pc != (pc + 4) & M32): + return 3 + if op == 0x33 and ins >> 25 == 1: + return 35 if ins >> 14 & 1 else 4 + if op == 0x0F and ins >> 12 & 7 == 1: + return 3 + return 2 + + def nmi(self, why=1): + """The Pause key.""" + if not self.nmi_pending and not self.in_monitor(): + self.nmi_pending, self.why_r = True, why + + +def main(): + import argparse + ap = argparse.ArgumentParser() + ap.add_argument("image") + ap.add_argument("--input", default=None) + ap.add_argument("--max", type=int, default=10_000_000) + ap.add_argument("--trace", default=None) + a = ap.parse_args() + inp = open(a.input, "rb").read() if a.input else b"" + cpu = RV32(open(a.image, "rb").read(), inp=inp) + tr = open(a.trace, "w") if a.trace else None + for _ in range(a.max): + if tr: + tr.write("%08x %08x\n" % (cpu.pc, cpu.rd32(cpu.pc))) + cpu.step() + if cpu.out: + sys.stdout.buffer.write(bytes(cpu.out)) + cpu.out.clear() + sys.stdout.flush() + + +if __name__ == "__main__": + main() diff --git a/tools/send-bas.py b/tools/send-bas.py new file mode 100755 index 0000000..0d20371 --- /dev/null +++ b/tools/send-bas.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +"""Type a BASIC program into the Basys 3 RISC-V computer over the serial port. + +The board needs SW15 and SW14 up (computer mode, PC serial linked), and nothing +else may be using the port (stop the getty first). The baud rate must match +SW1:0. Sets BASIC's clock to the PC's (unless --no-date), sends NEW unless +--keep is given, then the program, then RUN if --run is given. + + tools/send-bas.py basic/examples/graphics-demo.bas --baud 9600 --run +""" +import argparse +import os +import select +import termios +import time + +BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600, + 3000000: termios.B3000000} + +ap = argparse.ArgumentParser() +ap.add_argument("file") +ap.add_argument("--port", default="/dev/ttyUSB1") +ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS)) +ap.add_argument("--keep", action="store_true", help="don't send NEW first") +ap.add_argument("--run", action="store_true", help="send RUN at the end") +ap.add_argument("--no-date", action="store_true", help="don't set BASIC's clock") +a = ap.parse_args() + +fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY) +t = termios.tcgetattr(fd) +t[0] = termios.IXON # honour XON/XOFF +t[1] = 0 +t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL +t[3] = 0 +t[4] = t[5] = BAUDS[a.baud] +termios.tcsetattr(fd, termios.TCSANOW, t) + +lines = [l.rstrip() for l in open(a.file) if l.strip()] +if not a.keep: + lines.insert(0, "NEW") +if a.run: + lines.append("RUN") +if not a.no_date: + lines.insert(0, time.strftime('DATE "%Y-%m-%d %H:%M:%S"')) +t[6][termios.VMIN] = 0 # reads don't wait +t[6][termios.VTIME] = 0 +termios.tcsetattr(fd, termios.TCSANOW, t) +for n, line in enumerate(lines, 1): + os.write(fd, line.encode("ascii") + b"\r") + termios.tcdrain(fd) + time.sleep(0.02) # let BASIC store the line + # Read BASIC's echo (copied back when SW14 is up). Left unread, it fills the + # PC's input buffer; Linux then stops reading the port, misses the board's + # XON and never sends again. + while select.select([fd], [], [], 0)[0] and os.read(fd, 4096): + pass + print("\r%d/%d lines" % (n, len(lines)), end="", flush=True) +print() +os.close(fd) diff --git a/tools/send-hex.py b/tools/send-hex.py new file mode 100644 index 0000000..69d5b6c --- /dev/null +++ b/tools/send-hex.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Load an Intel HEX file (as objcopy -O ihex writes it) into the Basys 3 RISC-V +computer's memory through the monitor, and optionally save it as a memory +file in flash. + +The board needs SW15 and SW14 up and BASIC at READY; nothing else may be +using the serial port, and the baud rate must match SW1:0. The tool types +MONITOR, sends every record (the monitor writes each one into memory), +saves the loaded range if asked, and leaves the monitor again. + + tools/send-hex.py games/keep/keep.ihx --save KEEPGAME --baud 3000000 + +Code must go at 0A000h or above. Memory files are loaded back with BLOAD in +BASIC or LOAD in the monitor. +""" +import argparse +import os +import re +import select +import termios +import time + +BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600, + 3000000: termios.B3000000} + +ap = argparse.ArgumentParser() +ap.add_argument("file", help="Intel HEX file") +ap.add_argument("--save", metavar="NAME", help="save the loaded bytes in flash under this name") +ap.add_argument("--port", default="/dev/ttyUSB1") +ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS)) +ap.add_argument("--no-date", action="store_true", help="don't set BASIC's clock (which dates the file)") +a = ap.parse_args() + +records = [l.strip() for l in open(a.file) if l.startswith(":")] +if not records or not records[-1].upper().startswith(":00000001"): + records.append(":00000001FF") +for r in records: + if len(r) > 79: + raise SystemExit("record too long for the monitor (79 characters): " + r[:20]) +if a.save and not re.fullmatch(r"[A-Za-z][A-Za-z0-9]{0,7}", a.save): + raise SystemExit("a file name is 1-8 letters and digits, starting with a letter") + +fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY) +t = termios.tcgetattr(fd) +t[0] = termios.IXON +t[1] = 0 +t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL +t[3] = 0 +t[4] = t[5] = BAUDS[a.baud] +t[6][termios.VMIN] = 0 +t[6][termios.VTIME] = 0 +termios.tcsetattr(fd, termios.TCSANOW, t) +termios.tcflush(fd, termios.TCIFLUSH) + +buf = b"" + + +def send(s): + os.write(fd, s.encode("ascii")) + + +def wait_for(pattern, timeout=10.0): + """Read until the output since the last call matches; return it.""" + global buf + end = time.time() + timeout + while time.time() < end: + m = re.search(pattern, buf, re.S) + if m: + out, buf = buf[:m.end()], buf[m.end():] + return out + r, _, _ = select.select([fd], [], [], 0.05) + if r: + buf += os.read(fd, 65536) + raise SystemExit("no answer from the board (waiting for %r); last output: %r" % (pattern, buf[-200:])) + + +# the monitor's command line, redrawn after each command; its message comes +# after the prompt, and the cursor is turned back on last +PROMPT = rb"\x1b\[30;1H> .*?\x1b\[\?25h" +send("\r") +time.sleep(0.3) +if not a.no_date: # the file gets the PC's date + send(time.strftime('DATE "%Y-%m-%d %H:%M:%S"\r')) + wait_for(rb"READY\r\n") +send("MONITOR\r") +wait_for(rb"RISC-V MONITOR") +wait_for(PROMPT) +n = 0 +for r in records: + send(r.upper() + "\r") + out = wait_for(PROMPT) + if re.search(rb"BAD HEX|CHECKSUM|ROM: NOT|NO HEX", out): + send("X\r") + raise SystemExit("the monitor refused record %d: %s" % (n + 1, r)) + n += 1 + if n % 50 == 0: + print("\r%d/%d records" % (n, len(records)), end="", flush=True) +m = re.search(rb"HEX LOADED ([0-9A-F]{5})-([0-9A-F]{5})", out) +if not m: + send("X\r") + raise SystemExit("the monitor did not report the loaded range") +lo, hi = m.group(1).decode(), m.group(2).decode() +print("\rloaded %s-%s (%d bytes) from %d records" % (lo, hi, int(hi, 16) - int(lo, 16) + 1, len(records))) +if a.save: + send('SAVE "%s" %s %s\r' % (a.save.upper(), lo, hi)) + out = wait_for(PROMPT, 30) + if b"SAVED" not in out: + send("X\r") + raise SystemExit("saving failed: %r" % out[-120:]) + print('saved as "%s"; BLOAD "%s" in BASIC loads it at %sh' % (a.save.upper(), a.save.upper(), lo)) +send("X\r") +wait_for(rb"\x1b\[\?47l", 5) # the monitor's screen goes away +os.close(fd)