줄바꿈을 LF로 통일

서버에서 바로 빌드하고 고칠 수 있게 저장소 줄바꿈을 LF로 맞췄습니다.
CRLF로 들어가 있던 sh 빌드 스크립트도 이제 리눅스에서 그대로 돌아갑니다.
내용은 바뀌지 않았습니다.
This commit is contained in:
syskiller committed 2026-11-24 07:13:54 +09:00
1 parent 40615838ac
commit 2d48091205
623 files changed
+501372 -501365

No files matched your search

+14 -14
View File
@@ -1,14 +1,14 @@
#!/bin/sh
# Build the Paramix field switch (feld.bin, runs from PRAM 0)
set -e
cd "$(dirname "$0")"
CF="--target=thumbv7m-none-eabi -mcpu=cortex-m3 -mthumb -flto -ffreestanding -nostdlib -Oz -fno-common -Wall -Wno-initializer-overrides -Wno-unused-const-variable -fno-builtin-memset -DTONE_FIX -DBL_BLACK -DBL_OFFFIX -DBL_SLEEP -DFAST_LCD -DLCD_FASTCLK -DCLEAN -DPARA_BACK -DPARA_MB_KEEP -DPARA_FLASH -DPARA_FLASH_LATE -DFELD_AUTO -DFELD_BFALL -DFELD_BFALL_NOA -DCLEAN_AUTO -DBAT_SHOW -DBAG_DEL -DFELD_PW -DFELD_TAMA_ANY -DFELD_NOCLK -DFELD_BSETTLE -DFELD_SEEN $XCF"
O=""
for f in main-ko.c hw.c libc.c flash.c; do n=$(basename $f .c); OPT=; [ "$n" = main-ko ] && OPT=-Oz; clang $CF $OPT -c $f -o $n.o; O="$O $n.o"; done # 1.6.8: main with -Oz (menu code, size before speed)
N=${OUT:-feld-ko}
ld.lld -T link.ld --no-rosegment $O -o $N.elf
llvm-objcopy -O binary -j .text $N.elf $N.bin
python3 -c 'import pathlib,sys; p=pathlib.Path(sys.argv[1]); p.write_bytes(p.read_bytes()+b"ITOSM_KO_MENU_V1\x00")' "$N.bin"
llvm-size $N.elf; ls -l $N.bin
# 1.7.2 CLEAN_ROM: a second build for ROMs without the Paradise (own clock); the start device keeps the build above
if [ -z "$XCF" ]; then XCF=-DFELD_CLEAN OUT=feldc-ko sh ./build-ko.sh --inner; fi
#!/bin/sh
# Build the Paramix field switch (feld.bin, runs from PRAM 0)
set -e
cd "$(dirname "$0")"
CF="--target=thumbv7m-none-eabi -mcpu=cortex-m3 -mthumb -flto -ffreestanding -nostdlib -Oz -fno-common -Wall -Wno-initializer-overrides -Wno-unused-const-variable -fno-builtin-memset -DTONE_FIX -DBL_BLACK -DBL_OFFFIX -DBL_SLEEP -DFAST_LCD -DLCD_FASTCLK -DCLEAN -DPARA_BACK -DPARA_MB_KEEP -DPARA_FLASH -DPARA_FLASH_LATE -DFELD_AUTO -DFELD_BFALL -DFELD_BFALL_NOA -DCLEAN_AUTO -DBAT_SHOW -DBAG_DEL -DFELD_PW -DFELD_TAMA_ANY -DFELD_NOCLK -DFELD_BSETTLE -DFELD_SEEN $XCF"
O=""
for f in main-ko.c hw.c libc.c flash.c; do n=$(basename $f .c); OPT=; [ "$n" = main-ko ] && OPT=-Oz; clang $CF $OPT -c $f -o $n.o; O="$O $n.o"; done # 1.6.8: main with -Oz (menu code, size before speed)
N=${OUT:-feld-ko}
ld.lld -T link.ld --no-rosegment $O -o $N.elf
llvm-objcopy -O binary -j .text $N.elf $N.bin
python3 -c 'import pathlib,sys; p=pathlib.Path(sys.argv[1]); p.write_bytes(p.read_bytes()+b"ITOSM_KO_MENU_V1\x00")' "$N.bin"
llvm-size $N.elf; ls -l $N.bin
# 1.7.2 CLEAN_ROM: a second build for ROMs without the Paradise (own clock); the start device keeps the build above
if [ -z "$XCF" ]; then XCF=-DFELD_CLEAN OUT=feldc-ko sh ./build-ko.sh --inner; fi
+13 -13
View File
@@ -1,13 +1,13 @@
#!/bin/sh
# Build the Paramix field switch (feld.bin, runs from PRAM 0)
set -e
cd "$(dirname "$0")"
CF="--target=thumbv7m-none-eabi -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib -Os -fno-common -Wall -Wno-initializer-overrides -Wno-unused-const-variable -fno-builtin-memset -DTONE_FIX -DBL_BLACK -DBL_OFFFIX -DBL_SLEEP -DFAST_LCD -DLCD_FASTCLK -DCLEAN -DPARA_BACK -DPARA_MB_KEEP -DPARA_FLASH -DPARA_FLASH_LATE -DFELD_AUTO -DFELD_BFALL -DFELD_BFALL_NOA -DCLEAN_AUTO -DBAT_SHOW -DBAG_DEL -DFELD_PW -DFELD_TAMA_ANY -DFELD_NOCLK -DFELD_BSETTLE -DFELD_SEEN $XCF"
O=""
for f in main.c hw.c libc.c flash.c; do n=$(basename $f .c); OPT=; [ "$n" = main ] && OPT=-Oz; clang $CF $OPT -c $f -o $n.o; O="$O $n.o"; done # 1.6.8: main with -Oz (menu code, size before speed)
N=${OUT:-feld}
ld.lld -T link.ld --no-rosegment $O -o $N.elf
llvm-objcopy -O binary -j .text $N.elf $N.bin
llvm-size $N.elf; ls -l $N.bin
# 1.7.2 CLEAN_ROM: a second build for ROMs without the Paradise (own clock); the start device keeps the build above
if [ -z "$XCF" ]; then XCF=-DFELD_CLEAN OUT=feldc sh "$0" --inner; fi
#!/bin/sh
# Build the Paramix field switch (feld.bin, runs from PRAM 0)
set -e
cd "$(dirname "$0")"
CF="--target=thumbv7m-none-eabi -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib -Os -fno-common -Wall -Wno-initializer-overrides -Wno-unused-const-variable -fno-builtin-memset -DTONE_FIX -DBL_BLACK -DBL_OFFFIX -DBL_SLEEP -DFAST_LCD -DLCD_FASTCLK -DCLEAN -DPARA_BACK -DPARA_MB_KEEP -DPARA_FLASH -DPARA_FLASH_LATE -DFELD_AUTO -DFELD_BFALL -DFELD_BFALL_NOA -DCLEAN_AUTO -DBAT_SHOW -DBAG_DEL -DFELD_PW -DFELD_TAMA_ANY -DFELD_NOCLK -DFELD_BSETTLE -DFELD_SEEN $XCF"
O=""
for f in main.c hw.c libc.c flash.c; do n=$(basename $f .c); OPT=; [ "$n" = main ] && OPT=-Oz; clang $CF $OPT -c $f -o $n.o; O="$O $n.o"; done # 1.6.8: main with -Oz (menu code, size before speed)
N=${OUT:-feld}
ld.lld -T link.ld --no-rosegment $O -o $N.elf
llvm-objcopy -O binary -j .text $N.elf $N.bin
llvm-size $N.elf; ls -l $N.bin
# 1.7.2 CLEAN_ROM: a second build for ROMs without the Paradise (own clock); the start device keeps the build above
if [ -z "$XCF" ]; then XCF=-DFELD_CLEAN OUT=feldc sh "$0" --inner; fi
+5 -5
View File
@@ -1,5 +1,5 @@
// Captured from the REAL Flash Utility (same PRAM/post-reset context as
// our app). Order kept word for word. clk tail (reset release) first,
// then display/GPIO/backlight registers.
__attribute__((section(".initdata"))) static const unsigned int disp_power_seq[][2]={{0x45000020,0x40},{0x45000210,0x0},{0x45000214,0x0},{0x45000218,0x0},{0x45000204,0x0},{0x45000200,0xe0},{0x45000204,0x0},{0x45000200,0xe0},{0x45000020,0x42},{0x4003a000,0x8000},{0x4003a004,0x8000},{0x4003a004,0x8001},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18000ba0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40007034,0x0},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18000ba0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x4001803c,0xffffffff},{0x4001903c,0xfffff5df},{0x4001a03c,0xffffffff},{0x40018004,0x30},{0x40018000,0xfffffffe},{0x40018008,0x15008a56},{0x40018004,0x30},{0x40018000,0xfffffffe},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffffd},{0x40018008,0x15008a59},{0x40018004,0x30},{0x40018000,0xfffffffd},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffffb},{0x40018008,0x15008a65},{0x40018004,0x30},{0x40018000,0xfffffffb},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffff7},{0x40018008,0x15008a95},{0x40018004,0x30},{0x40018000,0xfffffff7},{0x40018008,0x15008a55},{0x40018004,0x20},{0x40018000,0xffffffef},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xffffffef},{0x40018008,0x15008855},{0x40018004,0x10},{0x40018000,0xffffffcf},{0x40018008,0x15008855},{0x40018004,0x30},{0x40018000,0xffffffcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffff4f},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffff4f},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffecf},{0x40018008,0x15028055},{0x40018004,0x30},{0x40018000,0xfffffecf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffdcf},{0x40018008,0x15088055},{0x40018004,0x30},{0x40018000,0xfffffdcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffbcf},{0x40018008,0x15208055},{0x40018004,0x30},{0x40018000,0xfffffbcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffff7cf},{0x40018008,0x15808055},{0x40018004,0x30},{0x40018000,0xfffff7cf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffefcf},{0x40018008,0x16008055},{0x40018004,0x30},{0x40018000,0xffffefcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffdfcf},{0x40018008,0x19008055},{0x40018004,0x30},{0x40018000,0xffffdfcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffbfcf},{0x40018008,0x25008055},{0x40018004,0x30},{0x40018000,0xffffbfcf},{0x40018008,0x15008055},{0x40019004,0xa00},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff59f},{0x40019008,0x55996800},{0x40019004,0xa20},{0x40019000,0xfffff59f},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff55f},{0x40019008,0x55999800},{0x40019004,0xa20},{0x40019000,0xfffff55f},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff4df},{0x40019008,0x559a5800},{0x40019004,0xa20},{0x40019000,0xfffff4df},{0x40019008,0x55995800},{0x40019004,0x820},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff1df},{0x40019008,0x55a95800},{0x40019004,0xa20},{0x40019000,0xfffff1df},{0x40019008,0x55995800},{0x40019004,0x220},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffe5df},{0x40019008,0x56995800},{0x40019004,0xa20},{0x40019000,0xffffe5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffd5df},{0x40019008,0x59995800},{0x40019004,0xa20},{0x40019000,0xffffd5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffb5df},{0x40019008,0x65995800},{0x40019004,0xa20},{0x40019000,0xffffb5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffff75df},{0x40019008,0x95995800},{0x40019004,0xa20},{0x40019000,0xffff75df},{0x40019008,0x55995800},{0x4001a004,0x0},{0x4001a000,0xfffffffe},{0x4001a008,0x52},{0x4001a004,0x0},{0x4001a000,0xfffffffe},{0x4001a008,0x50},{0x4001a004,0x0},{0x4001a000,0xfffffffd},{0x4001a008,0x58},{0x4001a004,0x0},{0x4001a000,0xfffffffd},{0x4001a008,0x50},{0x4001aLine truncated
#define DISP_POWER_N 262
// Captured from the REAL Flash Utility (same PRAM/post-reset context as
// our app). Order kept word for word. clk tail (reset release) first,
// then display/GPIO/backlight registers.
__attribute__((section(".initdata"))) static const unsigned int disp_power_seq[][2]={{0x45000020,0x40},{0x45000210,0x0},{0x45000214,0x0},{0x45000218,0x0},{0x45000204,0x0},{0x45000200,0xe0},{0x45000204,0x0},{0x45000200,0xe0},{0x45000020,0x42},{0x4003a000,0x8000},{0x4003a004,0x8000},{0x4003a004,0x8001},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18000ba0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40007034,0x0},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18000ba0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x40038014,0xf0},{0x40038018,0xa001},{0x40038014,0xf0},{0x40038004,0x18005da0},{0x40038008,0xffc},{0x4003800c,0x1},{0x40038010,0x1},{0x40038000,0x10},{0x40038000,0x0},{0x4001803c,0xffffffff},{0x4001903c,0xfffff5df},{0x4001a03c,0xffffffff},{0x40018004,0x30},{0x40018000,0xfffffffe},{0x40018008,0x15008a56},{0x40018004,0x30},{0x40018000,0xfffffffe},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffffd},{0x40018008,0x15008a59},{0x40018004,0x30},{0x40018000,0xfffffffd},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffffb},{0x40018008,0x15008a65},{0x40018004,0x30},{0x40018000,0xfffffffb},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xfffffff7},{0x40018008,0x15008a95},{0x40018004,0x30},{0x40018000,0xfffffff7},{0x40018008,0x15008a55},{0x40018004,0x20},{0x40018000,0xffffffef},{0x40018008,0x15008a55},{0x40018004,0x30},{0x40018000,0xffffffef},{0x40018008,0x15008855},{0x40018004,0x10},{0x40018000,0xffffffcf},{0x40018008,0x15008855},{0x40018004,0x30},{0x40018000,0xffffffcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffff4f},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffff4f},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffecf},{0x40018008,0x15028055},{0x40018004,0x30},{0x40018000,0xfffffecf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffdcf},{0x40018008,0x15088055},{0x40018004,0x30},{0x40018000,0xfffffdcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffffbcf},{0x40018008,0x15208055},{0x40018004,0x30},{0x40018000,0xfffffbcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xfffff7cf},{0x40018008,0x15808055},{0x40018004,0x30},{0x40018000,0xfffff7cf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffefcf},{0x40018008,0x16008055},{0x40018004,0x30},{0x40018000,0xffffefcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffdfcf},{0x40018008,0x19008055},{0x40018004,0x30},{0x40018000,0xffffdfcf},{0x40018008,0x15008055},{0x40018004,0x30},{0x40018000,0xffffbfcf},{0x40018008,0x25008055},{0x40018004,0x30},{0x40018000,0xffffbfcf},{0x40018008,0x15008055},{0x40019004,0xa00},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff59f},{0x40019008,0x55996800},{0x40019004,0xa20},{0x40019000,0xfffff59f},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff55f},{0x40019008,0x55999800},{0x40019004,0xa20},{0x40019000,0xfffff55f},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff4df},{0x40019008,0x559a5800},{0x40019004,0xa20},{0x40019000,0xfffff4df},{0x40019008,0x55995800},{0x40019004,0x820},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff1df},{0x40019008,0x55a95800},{0x40019004,0xa20},{0x40019000,0xfffff1df},{0x40019008,0x55995800},{0x40019004,0x220},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xfffff5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffe5df},{0x40019008,0x56995800},{0x40019004,0xa20},{0x40019000,0xffffe5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffd5df},{0x40019008,0x59995800},{0x40019004,0xa20},{0x40019000,0xffffd5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffffb5df},{0x40019008,0x65995800},{0x40019004,0xa20},{0x40019000,0xffffb5df},{0x40019008,0x55995800},{0x40019004,0xa20},{0x40019000,0xffff75df},{0x40019008,0x95995800},{0x40019004,0xa20},{0x40019000,0xffff75df},{0x40019008,0x55995800},{0x4001a004,0x0},{0x4001a000,0xfffffffe},{0x4001a008,0x52},{0x4001a004,0x0},{0x4001a000,0xfffffffe},{0x4001a008,0x50},{0x4001a004,0x0},{0x4001a000,0xfffffffd},{0x4001a008,0x58},{0x4001a004,0x0},{0x4001a000,0xfffffffd},{0x4001a008,0x50},{0x4001aLine truncated
#define DISP_POWER_N 262
+90 -90
View File
@@ -1,90 +1,90 @@
/* Write the Paradise flash: erase and program a sector, exactly like the
* mameise flash app (confirmed on the device). Runs from PRAM; nothing may be
* read from the XIP window while writing. */
#include "io.h"
#include "flash.h"
#define F_DMEM REG(FCTL+0x100)
#define F_DLEN REG(FCTL+0x104)
#define F_DCTL REG(FCTL+0x108)
#define F_DFLA REG(FCTL+0x10C)
static void feed(void){ REG(0x4000800Cu)=0x5AFA55AAu; REG(0x4000900Cu)=0x5AFA55AAu; }
static void wait_loop(u32 n){ for(volatile u32 i=0;i<n;i++){ if((i & 0xFFFFu)==0) feed(); } }
/* Read the flash status register, exactly like the Paradise firmware (PRAM 0x5808
* with -1): set read command bit 14, wait until it clears, byte from 0x14. */
static u32 flash_status(void)
{
REG(FCTL+0x004) |= 0x4000u;
for(u32 g=0; (REG(FCTL+0x004)&0x4000u) && g<1000000u; g++){}
return REG(FCTL+0x014) & 0xFFu;
}
/* Wait until the flash is ready (WIP = bit 0), like the firmware after
* erasing (0x38B0) and programming (0x3D28). Same upper limit as before. */
static void wait_ready(void)
{
wait_loop(2000u);
for(u32 i=0;i<400000u;i++){
if(!(flash_status() & 1u)) return;
if((i & 0xFFu)==0) feed();
}
}
void flash_erase4k(u32 addr)
{
u32 a1=addr>>1;
u32 hi=(a1>>16)&0xFFFFu;
u32 lo=a1 & 0xFFFFu;
REG(FCTL+0x008)=hi;
REG(FCTL+0x00C)=lo;
REG(FCTL+0x004)=0x00000400u;
for(u32 g=0; (REG(FCTL+0x004)&0x400u) && g<60000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
for(u32 g=0; (REG(FCTL+0x004)&0x2u) && g<60000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
wait_ready();
}
void flash_prog4k(u32 addr, const void *src)
{
u32 a1=addr>>1;
u32 hi=(a1>>16)&0xFFFFu;
u32 lo=a1 & 0xFFFFu;
flash_erase4k(addr);
/* program */
REG(FCTL+0x008)=0x3000u | hi;
REG(FCTL+0x00C)=lo;
REG(FCTL+0x004)=0x00000400u;
REG(FCTL+0x004)=0x00004000u;
REG(FCTL+0x000)=0x0000d080u;
REG(FCTL+0x020)=0;
REG(FCTL+0x010)=0;
REG(FCTL+0x000)=0x0000d082u;
F_DFLA=0x60000000u | (addr & 0x00FFFFFFu);
F_DLEN=0x1000u; F_DMEM=(u32)src;
F_DCTL=0u;
F_DCTL=1u;
for(u32 g=0; (F_DCTL & 1u) && g<20000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
wait_ready();
}
void flash_read(u32 addr, void *dst, u32 len)
{
const volatile u8 *s=(const volatile u8*)(0x60000000u + (addr & 0x00FFFFFFu));
u8 *d=(u8*)dst;
for(u32 i=0;i<len;i++) d[i]=s[i];
}
int flash_same(u32 addr, const void *src, u32 len)
{
const volatile u8 *s=(const volatile u8*)(0x60000000u + (addr & 0x00FFFFFFu));
const u8 *p=(const u8*)src;
for(u32 i=0;i<len;i++) if(s[i]!=p[i]) return 0;
return 1;
}
/* Write the sector only if it differs. Returns 1 if it was written. */
int flash_update4k(u32 addr, const void *src)
{
if(flash_same(addr, src, 0x1000u)) return 0;
flash_prog4k(addr, src);
return 1;
}
/* Write the Paradise flash: erase and program a sector, exactly like the
* mameise flash app (confirmed on the device). Runs from PRAM; nothing may be
* read from the XIP window while writing. */
#include "io.h"
#include "flash.h"
#define F_DMEM REG(FCTL+0x100)
#define F_DLEN REG(FCTL+0x104)
#define F_DCTL REG(FCTL+0x108)
#define F_DFLA REG(FCTL+0x10C)
static void feed(void){ REG(0x4000800Cu)=0x5AFA55AAu; REG(0x4000900Cu)=0x5AFA55AAu; }
static void wait_loop(u32 n){ for(volatile u32 i=0;i<n;i++){ if((i & 0xFFFFu)==0) feed(); } }
/* Read the flash status register, exactly like the Paradise firmware (PRAM 0x5808
* with -1): set read command bit 14, wait until it clears, byte from 0x14. */
static u32 flash_status(void)
{
REG(FCTL+0x004) |= 0x4000u;
for(u32 g=0; (REG(FCTL+0x004)&0x4000u) && g<1000000u; g++){}
return REG(FCTL+0x014) & 0xFFu;
}
/* Wait until the flash is ready (WIP = bit 0), like the firmware after
* erasing (0x38B0) and programming (0x3D28). Same upper limit as before. */
static void wait_ready(void)
{
wait_loop(2000u);
for(u32 i=0;i<400000u;i++){
if(!(flash_status() & 1u)) return;
if((i & 0xFFu)==0) feed();
}
}
void flash_erase4k(u32 addr)
{
u32 a1=addr>>1;
u32 hi=(a1>>16)&0xFFFFu;
u32 lo=a1 & 0xFFFFu;
REG(FCTL+0x008)=hi;
REG(FCTL+0x00C)=lo;
REG(FCTL+0x004)=0x00000400u;
for(u32 g=0; (REG(FCTL+0x004)&0x400u) && g<60000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
for(u32 g=0; (REG(FCTL+0x004)&0x2u) && g<60000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
wait_ready();
}
void flash_prog4k(u32 addr, const void *src)
{
u32 a1=addr>>1;
u32 hi=(a1>>16)&0xFFFFu;
u32 lo=a1 & 0xFFFFu;
flash_erase4k(addr);
/* program */
REG(FCTL+0x008)=0x3000u | hi;
REG(FCTL+0x00C)=lo;
REG(FCTL+0x004)=0x00000400u;
REG(FCTL+0x004)=0x00004000u;
REG(FCTL+0x000)=0x0000d080u;
REG(FCTL+0x020)=0;
REG(FCTL+0x010)=0;
REG(FCTL+0x000)=0x0000d082u;
F_DFLA=0x60000000u | (addr & 0x00FFFFFFu);
F_DLEN=0x1000u; F_DMEM=(u32)src;
F_DCTL=0u;
F_DCTL=1u;
for(u32 g=0; (F_DCTL & 1u) && g<20000000u; g++){ if((g & 0xFFFFu)==0) feed(); }
wait_ready();
}
void flash_read(u32 addr, void *dst, u32 len)
{
const volatile u8 *s=(const volatile u8*)(0x60000000u + (addr & 0x00FFFFFFu));
u8 *d=(u8*)dst;
for(u32 i=0;i<len;i++) d[i]=s[i];
}
int flash_same(u32 addr, const void *src, u32 len)
{
const volatile u8 *s=(const volatile u8*)(0x60000000u + (addr & 0x00FFFFFFu));
const u8 *p=(const u8*)src;
for(u32 i=0;i<len;i++) if(s[i]!=p[i]) return 0;
return 1;
}
/* Write the sector only if it differs. Returns 1 if it was written. */
int flash_update4k(u32 addr, const void *src)
{
if(flash_same(addr, src, 0x1000u)) return 0;
flash_prog4k(addr, src);
return 1;
}
+9 -9
View File
@@ -1,9 +1,9 @@
#ifndef FLASH_H
#define FLASH_H
#include "io.h"
void flash_erase4k(u32 addr);
void flash_prog4k(u32 addr, const void *src);
void flash_read(u32 addr, void *dst, u32 len);
int flash_same(u32 addr, const void *src, u32 len);
int flash_update4k(u32 addr, const void *src);
#endif
#ifndef FLASH_H
#define FLASH_H
#include "io.h"
void flash_erase4k(u32 addr);
void flash_prog4k(u32 addr, const void *src);
void flash_read(u32 addr, void *dst, u32 len);
int flash_same(u32 addr, const void *src, u32 len);
int flash_update4k(u32 addr, const void *src);
#endif
+99 -99
View File
@@ -1,99 +1,99 @@
/* generated by gen/font.py: custom 5x7 font */
static const unsigned char g_font[96][7]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x04,0x04,0x04,0x04,0x04,0x00,0x04},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x19,0x19,0x02,0x04,0x08,0x13,0x13},
{0x0c,0x12,0x14,0x08,0x15,0x12,0x0d},
{0x04,0x04,0x08,0x00,0x00,0x00,0x00},
{0x02,0x04,0x08,0x08,0x08,0x04,0x02},
{0x08,0x04,0x02,0x02,0x02,0x04,0x08},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x04,0x04,0x1f,0x04,0x04,0x00},
{0x00,0x00,0x00,0x00,0x0c,0x04,0x08},
{0x00,0x00,0x00,0x1f,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x0c,0x0c},
{0x01,0x01,0x02,0x04,0x08,0x10,0x10},
{0x0e,0x11,0x13,0x15,0x19,0x11,0x0e},
{0x04,0x0c,0x04,0x04,0x04,0x04,0x0e},
{0x0e,0x11,0x01,0x02,0x04,0x08,0x1f},
{0x1e,0x01,0x01,0x0e,0x01,0x01,0x1e},
{0x02,0x06,0x0a,0x12,0x1f,0x02,0x02},
{0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e},
{0x0e,0x10,0x10,0x1e,0x11,0x11,0x0e},
{0x1f,0x01,0x02,0x04,0x08,0x08,0x08},
{0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e},
{0x0e,0x11,0x11,0x0f,0x01,0x01,0x0e},
{0x00,0x04,0x04,0x00,0x04,0x04,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x02,0x04,0x08,0x10,0x08,0x04,0x02},
{0x00,0x00,0x1f,0x00,0x1f,0x00,0x00},
{0x08,0x04,0x02,0x01,0x02,0x04,0x08},
{0x0e,0x11,0x01,0x02,0x04,0x00,0x04},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x0e,0x11,0x11,0x1f,0x11,0x11,0x11},
{0x1e,0x11,0x11,0x1e,0x11,0x11,0x1e},
{0x0e,0x11,0x10,0x10,0x10,0x11,0x0e},
{0x1e,0x11,0x11,0x11,0x11,0x11,0x1e},
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x1f},
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x10},
{0x0e,0x11,0x10,0x17,0x11,0x11,0x0f},
{0x11,0x11,0x11,0x1f,0x11,0x11,0x11},
{0x0e,0x04,0x04,0x04,0x04,0x04,0x0e},
{0x07,0x02,0x02,0x02,0x02,0x12,0x0c},
{0x11,0x12,0x14,0x18,0x14,0x12,0x11},
{0x10,0x10,0x10,0x10,0x10,0x10,0x1f},
{0x11,0x1b,0x15,0x15,0x11,0x11,0x11},
{0x11,0x19,0x15,0x13,0x11,0x11,0x11},
{0x0e,0x11,0x11,0x11,0x11,0x11,0x0e},
{0x1e,0x11,0x11,0x1e,0x10,0x10,0x10},
{0x0e,0x11,0x11,0x11,0x15,0x12,0x0d},
{0x1e,0x11,0x11,0x1e,0x14,0x12,0x11},
{0x0f,0x10,0x10,0x0e,0x01,0x01,0x1e},
{0x1f,0x04,0x04,0x04,0x04,0x04,0x04},
{0x11,0x11,0x11,0x11,0x11,0x11,0x0e},
{0x11,0x11,0x11,0x11,0x11,0x0a,0x04},
{0x11,0x11,0x11,0x15,0x15,0x15,0x0a},
{0x11,0x11,0x0a,0x04,0x0a,0x11,0x11},
{0x11,0x11,0x0a,0x04,0x04,0x04,0x04},
{0x1f,0x01,0x02,0x04,0x08,0x10,0x1f},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x11,0x0a,0x04,0x0a,0x11},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x11,0x0e,0x11,0x1f,0x11,0x11,0x11},
{0x11,0x0e,0x11,0x11,0x11,0x11,0x0e},
{0x11,0x00,0x11,0x11,0x11,0x11,0x0e},
};
/* generated by gen/font.py: custom 5x7 font */
static const unsigned char g_font[96][7]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x04,0x04,0x04,0x04,0x04,0x00,0x04},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x19,0x19,0x02,0x04,0x08,0x13,0x13},
{0x0c,0x12,0x14,0x08,0x15,0x12,0x0d},
{0x04,0x04,0x08,0x00,0x00,0x00,0x00},
{0x02,0x04,0x08,0x08,0x08,0x04,0x02},
{0x08,0x04,0x02,0x02,0x02,0x04,0x08},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x04,0x04,0x1f,0x04,0x04,0x00},
{0x00,0x00,0x00,0x00,0x0c,0x04,0x08},
{0x00,0x00,0x00,0x1f,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x0c,0x0c},
{0x01,0x01,0x02,0x04,0x08,0x10,0x10},
{0x0e,0x11,0x13,0x15,0x19,0x11,0x0e},
{0x04,0x0c,0x04,0x04,0x04,0x04,0x0e},
{0x0e,0x11,0x01,0x02,0x04,0x08,0x1f},
{0x1e,0x01,0x01,0x0e,0x01,0x01,0x1e},
{0x02,0x06,0x0a,0x12,0x1f,0x02,0x02},
{0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e},
{0x0e,0x10,0x10,0x1e,0x11,0x11,0x0e},
{0x1f,0x01,0x02,0x04,0x08,0x08,0x08},
{0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e},
{0x0e,0x11,0x11,0x0f,0x01,0x01,0x0e},
{0x00,0x04,0x04,0x00,0x04,0x04,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x02,0x04,0x08,0x10,0x08,0x04,0x02},
{0x00,0x00,0x1f,0x00,0x1f,0x00,0x00},
{0x08,0x04,0x02,0x01,0x02,0x04,0x08},
{0x0e,0x11,0x01,0x02,0x04,0x00,0x04},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x0e,0x11,0x11,0x1f,0x11,0x11,0x11},
{0x1e,0x11,0x11,0x1e,0x11,0x11,0x1e},
{0x0e,0x11,0x10,0x10,0x10,0x11,0x0e},
{0x1e,0x11,0x11,0x11,0x11,0x11,0x1e},
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x1f},
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x10},
{0x0e,0x11,0x10,0x17,0x11,0x11,0x0f},
{0x11,0x11,0x11,0x1f,0x11,0x11,0x11},
{0x0e,0x04,0x04,0x04,0x04,0x04,0x0e},
{0x07,0x02,0x02,0x02,0x02,0x12,0x0c},
{0x11,0x12,0x14,0x18,0x14,0x12,0x11},
{0x10,0x10,0x10,0x10,0x10,0x10,0x1f},
{0x11,0x1b,0x15,0x15,0x11,0x11,0x11},
{0x11,0x19,0x15,0x13,0x11,0x11,0x11},
{0x0e,0x11,0x11,0x11,0x11,0x11,0x0e},
{0x1e,0x11,0x11,0x1e,0x10,0x10,0x10},
{0x0e,0x11,0x11,0x11,0x15,0x12,0x0d},
{0x1e,0x11,0x11,0x1e,0x14,0x12,0x11},
{0x0f,0x10,0x10,0x0e,0x01,0x01,0x1e},
{0x1f,0x04,0x04,0x04,0x04,0x04,0x04},
{0x11,0x11,0x11,0x11,0x11,0x11,0x0e},
{0x11,0x11,0x11,0x11,0x11,0x0a,0x04},
{0x11,0x11,0x11,0x15,0x15,0x15,0x0a},
{0x11,0x11,0x0a,0x04,0x0a,0x11,0x11},
{0x11,0x11,0x0a,0x04,0x04,0x04,0x04},
{0x1f,0x01,0x02,0x04,0x08,0x10,0x1f},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x11,0x0a,0x04,0x0a,0x11},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x11,0x0e,0x11,0x1f,0x11,0x11,0x11},
{0x11,0x0e,0x11,0x11,0x11,0x11,0x0e},
{0x11,0x00,0x11,0x11,0x11,0x11,0x0e},
};
+73 -73
View File
@@ -1,73 +1,73 @@
# Custom 5x7 font for the field switch helper program. Generates font.h
G = {
'A':[".###.","#...#","#...#","#####","#...#","#...#","#...#"],
'B':["####.","#...#","#...#","####.","#...#","#...#","####."],
'C':[".###.","#...#","#....","#....","#....","#...#",".###."],
'D':["####.","#...#","#...#","#...#","#...#","#...#","####."],
'E':["#####","#....","#....","####.","#....","#....","#####"],
'F':["#####","#....","#....","####.","#....","#....","#...."],
'G':[".###.","#...#","#....","#.###","#...#","#...#",".####"],
'H':["#...#","#...#","#...#","#####","#...#","#...#","#...#"],
'I':[".###.","..#..","..#..","..#..","..#..","..#..",".###."],
'J':["..###","...#.","...#.","...#.","...#.","#..#.",".##.."],
'K':["#...#","#..#.","#.#..","##...","#.#..","#..#.","#...#"],
'L':["#....","#....","#....","#....","#....","#....","#####"],
'M':["#...#","##.##","#.#.#","#.#.#","#...#","#...#","#...#"],
'N':["#...#","##..#","#.#.#","#..##","#...#","#...#","#...#"],
'O':[".###.","#...#","#...#","#...#","#...#","#...#",".###."],
'P':["####.","#...#","#...#","####.","#....","#....","#...."],
'Q':[".###.","#...#","#...#","#...#","#.#.#","#..#.",".##.#"],
'R':["####.","#...#","#...#","####.","#.#..","#..#.","#...#"],
'S':[".####","#....","#....",".###.","....#","....#","####."],
'T':["#####","..#..","..#..","..#..","..#..","..#..","..#.."],
'U':["#...#","#...#","#...#","#...#","#...#","#...#",".###."],
'V':["#...#","#...#","#...#","#...#","#...#",".#.#.","..#.."],
'W':["#...#","#...#","#...#","#.#.#","#.#.#","#.#.#",".#.#."],
'X':["#...#","#...#",".#.#.","..#..",".#.#.","#...#","#...#"],
'Y':["#...#","#...#",".#.#.","..#..","..#..","..#..","..#.."],
'Z':["#####","....#","...#.","..#..",".#...","#....","#####"],
'0':[".###.","#...#","#..##","#.#.#","##..#","#...#",".###."],
'1':["..#..",".##..","..#..","..#..","..#..","..#..",".###."],
'2':[".###.","#...#","....#","...#.","..#..",".#...","#####"],
'3':["####.","....#","....#",".###.","....#","....#","####."],
'4':["...#.","..##.",".#.#.","#..#.","#####","...#.","...#."],
'5':["#####","#....","####.","....#","....#","#...#",".###."],
'6':[".###.","#....","#....","####.","#...#","#...#",".###."],
'7':["#####","....#","...#.","..#..",".#...",".#...",".#..."],
'8':[".###.","#...#","#...#",".###.","#...#","#...#",".###."],
'9':[".###.","#...#","#...#",".####","....#","....#",".###."],
' ':["....."]*7,
':':[".....","..#..","..#..",".....","..#..","..#..","....."],
'.':[".....",".....",".....",".....",".....",".##..",".##.."],
'!':["..#..","..#..","..#..","..#..","..#..",".....","..#.."],
'?':[".###.","#...#","....#","...#.","..#..",".....","..#.."],
'=':[".....",".....","#####",".....","#####",".....","....."],
'-':[".....",".....",".....","#####",".....",".....","....."],
'/':["....#","....#","...#.","..#..",".#...","#....","#...."],
'%':["##..#","##..#","...#.","..#..",".#...","#..##","#..##"],
'>':[".#...","..#..","...#.","....#","...#.","..#..",".#..."],
'<':["...#.","..#..",".#...","#....",".#...","..#..","...#."],
'+':[".....","..#..","..#..","#####","..#..","..#..","....."],
'&':[".##..","#..#.","#.#..",".#...","#.#.#","#..#.",".##.#"],
"'":["..#..","..#..",".#...",".....",".....",".....","....."],
'x':[".....",".....","#...#",".#.#.","..#..",".#.#.","#...#"],
',':[".....",".....",".....",".....",".##..","..#..",".#..."],
'(':["...#.","..#..",".#...",".#...",".#...","..#..","...#."],
')':[".#...","..#..","...#.","...#.","...#.","..#..",".#..."],
'\x01':["#...#",".###.","#...#","#####","#...#","#...#","#...#"], # A umlaut
'\x02':["#...#",".###.","#...#","#...#","#...#","#...#",".###."], # O umlaut
'\x03':["#...#",".....","#...#","#...#","#...#","#...#",".###."], # U umlaut
}
lo=0;hi=127
out=['/* generated by gen/font.py: custom 5x7 font */','static const unsigned char g_font[96][7]={']
codes={}
for c,rows in G.items():
k=ord(c)
codes[k]=[sum((1<<(4-i)) for i,ch in enumerate(r) if ch=='#') for r in rows]
def idx(k):
return k-32 if k>=32 else 92+k # \x01..\x03 -> 93..95
tab=[[0]*7 for _ in range(96)]
for k,v in codes.items(): tab[idx(k)]=v
for i,v in enumerate(tab): out.append(' {%s},'%(','.join('0x%02x'%x for x in v)))
out.append('};')
open('font.h','w').write('\n'.join(out)+'\n')
# Custom 5x7 font for the field switch helper program. Generates font.h
G = {
'A':[".###.","#...#","#...#","#####","#...#","#...#","#...#"],
'B':["####.","#...#","#...#","####.","#...#","#...#","####."],
'C':[".###.","#...#","#....","#....","#....","#...#",".###."],
'D':["####.","#...#","#...#","#...#","#...#","#...#","####."],
'E':["#####","#....","#....","####.","#....","#....","#####"],
'F':["#####","#....","#....","####.","#....","#....","#...."],
'G':[".###.","#...#","#....","#.###","#...#","#...#",".####"],
'H':["#...#","#...#","#...#","#####","#...#","#...#","#...#"],
'I':[".###.","..#..","..#..","..#..","..#..","..#..",".###."],
'J':["..###","...#.","...#.","...#.","...#.","#..#.",".##.."],
'K':["#...#","#..#.","#.#..","##...","#.#..","#..#.","#...#"],
'L':["#....","#....","#....","#....","#....","#....","#####"],
'M':["#...#","##.##","#.#.#","#.#.#","#...#","#...#","#...#"],
'N':["#...#","##..#","#.#.#","#..##","#...#","#...#","#...#"],
'O':[".###.","#...#","#...#","#...#","#...#","#...#",".###."],
'P':["####.","#...#","#...#","####.","#....","#....","#...."],
'Q':[".###.","#...#","#...#","#...#","#.#.#","#..#.",".##.#"],
'R':["####.","#...#","#...#","####.","#.#..","#..#.","#...#"],
'S':[".####","#....","#....",".###.","....#","....#","####."],
'T':["#####","..#..","..#..","..#..","..#..","..#..","..#.."],
'U':["#...#","#...#","#...#","#...#","#...#","#...#",".###."],
'V':["#...#","#...#","#...#","#...#","#...#",".#.#.","..#.."],
'W':["#...#","#...#","#...#","#.#.#","#.#.#","#.#.#",".#.#."],
'X':["#...#","#...#",".#.#.","..#..",".#.#.","#...#","#...#"],
'Y':["#...#","#...#",".#.#.","..#..","..#..","..#..","..#.."],
'Z':["#####","....#","...#.","..#..",".#...","#....","#####"],
'0':[".###.","#...#","#..##","#.#.#","##..#","#...#",".###."],
'1':["..#..",".##..","..#..","..#..","..#..","..#..",".###."],
'2':[".###.","#...#","....#","...#.","..#..",".#...","#####"],
'3':["####.","....#","....#",".###.","....#","....#","####."],
'4':["...#.","..##.",".#.#.","#..#.","#####","...#.","...#."],
'5':["#####","#....","####.","....#","....#","#...#",".###."],
'6':[".###.","#....","#....","####.","#...#","#...#",".###."],
'7':["#####","....#","...#.","..#..",".#...",".#...",".#..."],
'8':[".###.","#...#","#...#",".###.","#...#","#...#",".###."],
'9':[".###.","#...#","#...#",".####","....#","....#",".###."],
' ':["....."]*7,
':':[".....","..#..","..#..",".....","..#..","..#..","....."],
'.':[".....",".....",".....",".....",".....",".##..",".##.."],
'!':["..#..","..#..","..#..","..#..","..#..",".....","..#.."],
'?':[".###.","#...#","....#","...#.","..#..",".....","..#.."],
'=':[".....",".....","#####",".....","#####",".....","....."],
'-':[".....",".....",".....","#####",".....",".....","....."],
'/':["....#","....#","...#.","..#..",".#...","#....","#...."],
'%':["##..#","##..#","...#.","..#..",".#...","#..##","#..##"],
'>':[".#...","..#..","...#.","....#","...#.","..#..",".#..."],
'<':["...#.","..#..",".#...","#....",".#...","..#..","...#."],
'+':[".....","..#..","..#..","#####","..#..","..#..","....."],
'&':[".##..","#..#.","#.#..",".#...","#.#.#","#..#.",".##.#"],
"'":["..#..","..#..",".#...",".....",".....",".....","....."],
'x':[".....",".....","#...#",".#.#.","..#..",".#.#.","#...#"],
',':[".....",".....",".....",".....",".##..","..#..",".#..."],
'(':["...#.","..#..",".#...",".#...",".#...","..#..","...#."],
')':[".#...","..#..","...#.","...#.","...#.","..#..",".#..."],
'\x01':["#...#",".###.","#...#","#####","#...#","#...#","#...#"], # A umlaut
'\x02':["#...#",".###.","#...#","#...#","#...#","#...#",".###."], # O umlaut
'\x03':["#...#",".....","#...#","#...#","#...#","#...#",".###."], # U umlaut
}
lo=0;hi=127
out=['/* generated by gen/font.py: custom 5x7 font */','static const unsigned char g_font[96][7]={']
codes={}
for c,rows in G.items():
k=ord(c)
codes[k]=[sum((1<<(4-i)) for i,ch in enumerate(r) if ch=='#') for r in rows]
def idx(k):
return k-32 if k>=32 else 92+k # \x01..\x03 -> 93..95
tab=[[0]*7 for _ in range(96)]
for k,v in codes.items(): tab[idx(k)]=v
for i,v in enumerate(tab): out.append(' {%s},'%(','.join('0x%02x'%x for x in v)))
out.append('};')
open('font.h','w').write('\n'.join(out)+'\n')
+45 -45
View File
@@ -1,45 +1,45 @@
/* PC test of the Paramix menu: cc -DHOST host.c main.c -o menu_host
* menu_host <flash_in.bin> <flash_out.bin> <image_folder> "<sequence>"
* Sequence: n (wheel forward), p (wheel back), a, b, c. One PPM image after each screen update. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8;
unsigned char *host_flash;
static const char *g_seq; static int g_pos; static const char *g_dir; static int g_frame; static const char *g_out;
static jmp_buf g_jb;
void hw_init(void){}
void hw_wdt_feed(void){}
u32 hw_buttons(void){ return 0; }
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1){
(void)stride;(void)x0;(void)y0;(void)x1;(void)y1;
char p[512]; snprintf(p,sizeof p,"%s/%03d.ppm",g_dir,g_frame++);
FILE *f=fopen(p,"wb"); fprintf(f,"P6 128 128 255\n");
for(int i=0;i<128*128;i++){ u16 c=fb[i]; u8 r=(u8)((c>>11)<<3), g=(u8)(((c>>5)&63)<<2), b=(u8)((c&31)<<3); fputc(r,f); fputc(g,f); fputc(b,f); }
fclose(f);
}
void hw_back_to_paradise(void){ printf("BACK TO PARADISE\n"); longjmp(g_jb,1); }
void host_exit(const char *why){ printf("ENDE %s\n",why); longjmp(g_jb,1); }
void hw_tone(u32 hz){(void)hz;} void hw_backlight(int on){(void)on;} void hw_bl_pwm_off(void){}
void flash_prog4k(u32 addr, const void *src){ memcpy(host_flash+(addr&0xFFFFFF),src,0x1000); }
void flash_erase4k(u32 addr){ memset(host_flash+(addr&0xFFFFFF),0xFF,0x1000); }
void flash_read(u32 addr, void *dst, u32 len){ memcpy(dst,host_flash+(addr&0xFFFFFF),len); }
int flash_same(u32 addr, const void *src, u32 len){ return !memcmp(host_flash+(addr&0xFFFFFF),src,len); }
int flash_update4k(u32 addr, const void *src){ if(flash_same(addr,src,0x1000)) return 0; flash_prog4k(addr,src); return 1; }
int host_input(int *step){
for(;;){
char c=g_seq[g_pos]; if(!c){ printf("FOLGE ZU ENDE\n"); longjmp(g_jb,1); }
g_pos++;
switch(c){ case 'n': *step=1; return 1; case 'p': *step=-1; return 1; case 'a': return 10; case 'b': return 2; case 'c': return 3; default: break; }
}
}
void host_main(void);
int main(int argc,char**argv){
if(argc<5){ fprintf(stderr,"menu_host in out dir folge\n"); return 1; }
host_flash=malloc(0x1000000); FILE *f=fopen(argv[1],"rb"); fread(host_flash,1,0x1000000,f); fclose(f);
g_out=argv[2]; g_dir=argv[3]; g_seq=argv[4];
if(!setjmp(g_jb)) host_main();
f=fopen(g_out,"wb"); fwrite(host_flash,1,0x1000000,f); fclose(f);
printf("%d Bilder\n",g_frame); return 0;
}
/* PC test of the Paramix menu: cc -DHOST host.c main.c -o menu_host
* menu_host <flash_in.bin> <flash_out.bin> <image_folder> "<sequence>"
* Sequence: n (wheel forward), p (wheel back), a, b, c. One PPM image after each screen update. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8;
unsigned char *host_flash;
static const char *g_seq; static int g_pos; static const char *g_dir; static int g_frame; static const char *g_out;
static jmp_buf g_jb;
void hw_init(void){}
void hw_wdt_feed(void){}
u32 hw_buttons(void){ return 0; }
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1){
(void)stride;(void)x0;(void)y0;(void)x1;(void)y1;
char p[512]; snprintf(p,sizeof p,"%s/%03d.ppm",g_dir,g_frame++);
FILE *f=fopen(p,"wb"); fprintf(f,"P6 128 128 255\n");
for(int i=0;i<128*128;i++){ u16 c=fb[i]; u8 r=(u8)((c>>11)<<3), g=(u8)(((c>>5)&63)<<2), b=(u8)((c&31)<<3); fputc(r,f); fputc(g,f); fputc(b,f); }
fclose(f);
}
void hw_back_to_paradise(void){ printf("BACK TO PARADISE\n"); longjmp(g_jb,1); }
void host_exit(const char *why){ printf("ENDE %s\n",why); longjmp(g_jb,1); }
void hw_tone(u32 hz){(void)hz;} void hw_backlight(int on){(void)on;} void hw_bl_pwm_off(void){}
void flash_prog4k(u32 addr, const void *src){ memcpy(host_flash+(addr&0xFFFFFF),src,0x1000); }
void flash_erase4k(u32 addr){ memset(host_flash+(addr&0xFFFFFF),0xFF,0x1000); }
void flash_read(u32 addr, void *dst, u32 len){ memcpy(dst,host_flash+(addr&0xFFFFFF),len); }
int flash_same(u32 addr, const void *src, u32 len){ return !memcmp(host_flash+(addr&0xFFFFFF),src,len); }
int flash_update4k(u32 addr, const void *src){ if(flash_same(addr,src,0x1000)) return 0; flash_prog4k(addr,src); return 1; }
int host_input(int *step){
for(;;){
char c=g_seq[g_pos]; if(!c){ printf("FOLGE ZU ENDE\n"); longjmp(g_jb,1); }
g_pos++;
switch(c){ case 'n': *step=1; return 1; case 'p': *step=-1; return 1; case 'a': return 10; case 'b': return 2; case 'c': return 3; default: break; }
}
}
void host_main(void);
int main(int argc,char**argv){
if(argc<5){ fprintf(stderr,"menu_host in out dir folge\n"); return 1; }
host_flash=malloc(0x1000000); FILE *f=fopen(argv[1],"rb"); fread(host_flash,1,0x1000000,f); fclose(f);
g_out=argv[2]; g_dir=argv[3]; g_seq=argv[4];
if(!setjmp(g_jb)) host_main();
f=fopen(g_out,"wb"); fwrite(host_flash,1,0x1000000,f); fclose(f);
printf("%d Bilder\n",g_frame); return 0;
}
+5 -5
View File
@@ -1,5 +1,5 @@
/* Only for the PC test (host.c): flash as a memory array, input from a sequence. */
extern unsigned char *host_flash;
#define FLASH_BASE ((volatile u8*)host_flash)
int host_input(int *step);
void host_exit(const char *why);
/* Only for the PC test (host.c): flash as a memory array, input from a sequence. */
extern unsigned char *host_flash;
#define FLASH_BASE ((volatile u8*)host_flash)
int host_input(int *step);
void host_exit(const char *why);
+303 -303
View File
@@ -1,303 +1,303 @@
/* Paradise hardware (SNC73410), taken from the mameise flash app
* (display confirmed on the device). Runs from PRAM 0 after SYSRESETREQ. */
#include "io.h"
#include "hw.h"
#include "disp_power.h"
#define PANEL 0x4000E000u
#define FCTL_ 0x40022000u
#define F_STAT REG(FCTL_+0x000)
static void udelay(volatile u32 n){ while(n--) __asm__ volatile("nop"); }
#define MS(x) udelay((u32)(x)*16000u)
#define BB(reg,bit) (*(volatile u32*)(0x42000000u + (((u32)(reg)-0x40000000u)<<5) + ((u32)(bit)<<2)))
#define GPIO0 0x40018000u
#define GPIO1 0x40019000u
#define GPIO2 0x4001A000u
#define LCD_RST(v) (BB(GPIO0+0x00,4)=(v))
#define LCD_DC(v) (BB(GPIO0+0x00,5)=(v))
#define SPI_CTRL REG(PANEL+0x00)
#define SPI_STAT REG(PANEL+0x0C)
#define SPI_DATA REG(PANEL+0x1C)
#define SPIWAIT 200000u
#define CT2 0x40002000u
TC_INIT static void clock_init(void){
REG(CLK+0x00) |= 1u;
REG(CLK+0x0C) = 0;
REG(CLK+0x00) = 0x41u;
{ u32 r = (REG(CLK+0x34) & 0xF00u) | 0xA55A0000u; REG(CLK+0x04) = r; }
REG(CLK+0x18) = 0x21u;
REG(CLK+0x50) = 0;
REG(CLK+0x10C) = 0x001FFFFDu;
REG(CLK+0x110) = 0;
REG(CLK+0x108) = 0;
REG(CLK+0x10) = 0;
REG(CLK+0x00) |= 0x10u;
for(u32 g=0; !((REG(CLK+0x08) >> 4) & 1u) && g<4000000u; g++){}
REG(CLK+0x00) |= 0x4000u;
REG(CLK+0x04) &= ~1u;
REG(CLK+0x00) |= 0x8000u;
for(u32 g=0; !((REG(CLK+0x08) >> 6) & 1u) && g<4000000u; g++){}
{ u32 r = (REG(CLK+0x0C) & ~7u) | 4u; REG(CLK+0x0C) = r; }
for(u32 g=0; ((REG(CLK+0x0C) >> 4) & 7u) != (REG(CLK+0x0C) & 7u) && g<4000000u; g++){} /* bounded: never hang forever */
REG(CLK+0x100) = 0x00157EB7u;
}
TC_INIT static void flashctl_init(void){
/* 1.4.2: enable XIP. We read through the 0x60000000 window that the XIP block
* maps in. Without XIP that window only shows the config register (0x40), not
* the flash data. The real Flash Utility does this at startup, our app did not
* do it after reset until now. That is exactly what was missing. */
REG(0x4002F004u)=0x60011000u;
REG(0x4002F000u)=0x00000003u;
/* 1.4.1: controller init word for word like the real Flash Utility (0x40022000).
* This includes setting the read command/mode in 0x008 and 0x00c (0x3077 / 0xf000),
* otherwise the chip only returns its config register (0x40) instead of flash data. */
F_STAT=0x0000d018u;
F_STAT=0x0000d000u;
F_STAT=0x0000d080u;
F_STAT=0x0000d088u;
REG(FCTL+0x008)=0x00003077u; /* read command/mode */
REG(FCTL+0x00C)=0x0000f000u;
REG(FCTL+0x004)=0x00000400u;
REG(FCTL+0x004)=0x00004000u;
}
TC_INIT static void wdt_off(void){
/* Set up the system/power block EXACTLY like the real Flash Utility. The only
point where we deliberately differed before (bit0 of 0x40008000) might be the
master enable for the display domain. The FU runs with bit0=1 without a
reset, so we copy it 1:1 and feed the watchdog in the loop. */
REG(0x4000900Cu)=0x5AFA55AAu; REG(0x40009000u)=0x5AFA0000u; /* WDT1 */
REG(0x40008000u)=0x5AFA0000u; /* unlock */
REG(0x40008004u)=0x5AFA0002u;
REG(0x40008008u)=0x5AFA00FFu; /* power/clock domains on (incl. display) */
REG(0x4000800Cu)=0x5AFA55AAu; /* feed the watchdog */
/* Do NOT set bit0 (watchdog enable): otherwise it resets the Tama during
display init (back to the planet). */
}
TC_INIT static void mailbox_clear(void){
REG(0x20000000u)=0; REG(0x20000004u)=0; REG(0x20000008u)=0; REG(0x2000000Cu)=0;
}
TC_INIT static void periph_enable(void){ REG(CLK+0x20)=0x40u; }
TC_INIT static void pin_set(u8 id, u8 mode){ *(volatile u8*)(0xE000E400u + id) = (u8)(mode<<4); }
TC_INIT static void pin_mux(void){
static const u8 m12[]={6,7,8,9,0xf,0x10,0x11,0x12,0x13,0x14,0x19,0x1f,0x20,0x22,
0x24,0x25,0x2e,0x2f,0x35,0x36,0x1a,0x1b,0x1c,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x3a,0x3f};
static const u8 m8[]={0,1,2,3};
static const u8 m4[]={0x15,0x17};
for(unsigned i=0;i<sizeof m12;i++) pin_set(m12[i],0xC);
for(unsigned i=0;i<sizeof m8;i++) pin_set(m8[i],0x8);
for(unsigned i=0;i<sizeof m4;i++) pin_set(m4[i],0x4);
}
TC_INIT static void display_power(void){
/* Sequence from the real FU (clock enable, pin setup, timer CT32B3, GPIO1).
As in the FU, 0x45000210..218 get the current contents of the GPIO
data registers (the emulator had returned 0 there). */
for(unsigned i=0;i<DISP_POWER_N;i++){
u32 a=disp_power_seq[i][0], v=disp_power_seq[i][1];
if(a>=0x45000210u && a<=0x45000218u) v=REG(0x4001803Cu + ((a-0x45000210u)>>2)*0x1000u);
REG(a)=v;
}
/* Make sure the panel pins are outputs: reset, D/C, CS (P1.5 low), supply (P1.9 low) */
LCD_RST(1); BB(GPIO0+0x04,4)=1;
LCD_DC(0); BB(GPIO0+0x04,5)=1;
BB(GPIO1+0x00,5)=0; BB(GPIO1+0x04,5)=1;
BB(GPIO1+0x00,9)=0; BB(GPIO1+0x04,9)=1;
MS(20);
}
TC_INIT static void spi_init(void){
/* like FU 0x3f44, as read-modify-write */
#ifdef LCD_FASTCLK
REG(PANEL+0x08)=0; /* clock divider: test in v0.8.18, twice as fast? */
#else
REG(PANEL+0x08)=1; /* clock divider */
#endif
SPI_CTRL &= ~(1u<<18);
REG(PANEL+0x04) &= ~6u; REG(PANEL+0x04) &= ~1u;
SPI_CTRL &= ~0x10u; SPI_CTRL &= ~0x08u;
REG(PANEL+0x20)=0;
SPI_CTRL = (SPI_CTRL & ~0xF00u) | 0x700u; /* 8 bit */
REG(PANEL+0x24) |= 0x80000000u;
REG(PANEL+0x24) &= ~0xFF0000u;
REG(PANEL+0x24) |= 0x80000000u;
REG(PANEL+0x24) &= ~0xFFu;
SPI_CTRL |= 1u; /* SPI on */
SPI_CTRL |= 0xC0u; /* flush FIFOs */
}
static void spi_tx(const u8* p, u32 n){
for(u32 i=0;i<n;i++){
for(u32 g=0; (SPI_STAT & 2u) && g<SPIWAIT; g++){}
SPI_DATA=p[i];
}
udelay(8);
for(u32 g=0; (SPI_STAT & 0x10u) && g<SPIWAIT; g++){}
SPI_CTRL |= 0xC0u;
}
static void lcd_cmd(u8 c, const u8* par, u32 n){
LCD_DC(0); spi_tx(&c,1);
if(n){ LCD_DC(1); spi_tx(par,n); LCD_DC(0); }
}
static const u8 p36[]={0x08}, p3a[]={0x05}, p26[]={0x01},
pb1[]={0x08,0x3b,0x3b}, pb2[]={0x08,0x3b,0x3b}, pb3[]={0x08,0x3b,0x3b,0x08,0x3b,0x3b},
pb4[]={0x03}, pc0[]={0xe0,0x00,0x84}, pc1[]={0xc4}, pc2[]={0x0d,0x00}, pc3[]={0x8d,0x2a},
pc4[]={0x8d,0xee}, pc5[]={0x06},
pe0[]={0x0d,0x17,0x16,0x28,0x3f,0x39,0x30,0x31,0x2c,0x28,0x2f,0x39,0x00,0x04,0x01,0x10},
pe1[]={0x0a,0x15,0x18,0x25,0x3f,0x37,0x2e,0x30,0x2f,0x2c,0x33,0x3f,0x00,0x03,0x04,0x10},
p35[]={0x00}, pcas0[]={0x00,0x02,0x00,0x83}, pras0[]={0x00,0x01,0x00,0x81},
pcas[]={0x00,0x02,0x00,0x81}, pras[]={0x00,0x01,0x00,0x80};
TC_INIT static void display_init(void){
spi_init();
LCD_RST(1); MS(10); LCD_RST(0); MS(20); LCD_RST(1); MS(150); /* panel reset */
lcd_cmd(0x11,0,0); MS(150); /* SLPOUT */
lcd_cmd(0x36,p36,1); lcd_cmd(0x3a,p3a,1); lcd_cmd(0x26,p26,1); lcd_cmd(0x20,0,0);
lcd_cmd(0xb1,pb1,3); lcd_cmd(0xb2,pb2,3); lcd_cmd(0xb3,pb3,6); lcd_cmd(0xb4,pb4,1);
lcd_cmd(0xc0,pc0,3); lcd_cmd(0xc1,pc1,1); lcd_cmd(0xc2,pc2,2); lcd_cmd(0xc3,pc3,2);
lcd_cmd(0xc4,pc4,2); lcd_cmd(0xc5,pc5,1);
lcd_cmd(0xe0,pe0,16); lcd_cmd(0xe1,pe1,16);
lcd_cmd(0x35,p35,1);
lcd_cmd(0x29,0,0); MS(20); /* DISPON */
lcd_cmd(0x2a,pcas0,4); lcd_cmd(0x2b,pras0,4);
lcd_cmd(0x11,0,0); MS(150);
}
static void pwm2(u32 mr1, int first){
if(first) REG(CT2+0x34)=0;
REG(CT2+0x00)=0;
REG(CT2+0x18)=0; REG(CT2+0x1C)=0; REG(CT2+0x20)=0; REG(CT2+0x24)=0;
REG(CT2+0x14)=0;
REG(CT2+0x00)=2; REG(CT2+0x08)=0; REG(CT2+0x00)=0;
REG(CT2+0x14)=0x400u;
REG(CT2+0x24)=0x17700u;
REG(CT2+0x1C)=mr1;
REG(CT2+0x14)=0;
REG(CT2+0x34)=0x00200002u;
REG(CT2+0x00)=2;
REG(CT2+0x3C)=0x1Fu;
REG(CT2+0x00)=1;
}
TC_INIT static void backlight_on(void){
REG(0x40007034u)=0;
pwm2(0x17700u,1);
REG(0x40009000u)=0x5AFA0000u; REG(0x40008000u)=0x5AFA0000u; /* like FU */
REG(0x40018034u)=0x15555155u; REG(0x40019034u)=0x55540140u;
pwm2(0,0);
REG(CLK+0x20)=0x42u;
}
/* ---------------- our own additions ---------------- */
/* Buzzer on timer 7, started and stopped exactly like the firmware does:
* period in 72 MHz clock ticks, short pulse (quiet, like on the Paradise). */
#define CT7 0x40007000u
#ifdef TONE_FIX
/* v0.8.15: the counter runs periodically (MCTRL bit 10 = restart at MR3, like the backlight with 0x400).
* Before, MCTRL ended up at 0: only a single pulse per call, so a click instead of a tone.
* If only the pitch changes, only MR0/MR3 are set again (no restart, no click). */
void hw_tone(u32 hz){
static u32 on;
if(!hz){ REG(CT7+0x34)=0; REG(CT7+0x00)=0; on=0; return; }
u32 per = 72000000u / hz, mr0 = per - per/32u;
if(on){ REG(CT7+0x24)=per; REG(CT7+0x18)=mr0; return; }
REG(CT7+0x34)=0;
REG(CT7+0x00)=2; REG(CT7+0x08)=0; REG(CT7+0x00)=0;
REG(CT7+0x18)=mr0; REG(CT7+0x1C)=0; REG(CT7+0x20)=0;
REG(CT7+0x24)=per;
REG(CT7+0x14)=0x400u;
REG(CT7+0x34)=0x00100001u;
REG(CT7+0x3C)=0x1Fu;
REG(CT7+0x00)=1;
on=1;
}
#else
void hw_tone(u32 hz){
if(!hz){ REG(CT7+0x34)=0; return; }
u32 per = 72000000u / hz, mr0 = per - per/32u;
REG(CT7+0x34)=0;
REG(CT7+0x00)=0;
REG(CT7+0x18)=0; REG(CT7+0x1C)=0; REG(CT7+0x20)=0; REG(CT7+0x24)=0;
REG(CT7+0x14)=0;
REG(CT7+0x00)=2; REG(CT7+0x08)=0; REG(CT7+0x00)=0;
REG(CT7+0x14)=0x600u;
REG(CT7+0x24)=per;
REG(CT7+0x18)=mr0;
REG(CT7+0x14)=0;
REG(CT7+0x34)=0x00100001u;
REG(CT7+0x00)=2;
REG(CT7+0x3C)=0x1Fu;
REG(CT7+0x00)=1;
}
#endif
void hw_bl_pwm_off(void){ REG(CT2+0x00)=0; REG(CT2+0x34)=0; } /* backlight off only (when leaving) */
#ifdef BL_SLEEP
/* v0.8.18: off = put the display to sleep (DISPOFF, SLPIN) and stop the backlight timer,
* PWM output off (like panel_down in the Flash Tool). On = SLPOUT, short wait, DISPON, restart backlight.
* MR1 values alone (v0.8.17) had no effect on the device. */
void hw_backlight(int on){
static int is_on=1;
if(on){ if(is_on) return; lcd_cmd(0x11,0,0); MS(10); lcd_cmd(0x29,0,0); pwm2(0u,1); is_on=1; }
else { if(!is_on) return; REG(CT2+0x00)=0; REG(CT2+0x34)=0; lcd_cmd(0x28,0,0); lcd_cmd(0x10,0,0); is_on=0; }
}
#elif defined(BL_OFFFIX)
/* v0.8.17: duty cycle 0 = full brightness. MR1 equal to the period (0x17700) never matches, so it stayed bright.
* One tick before the end of the period is practically dark. */
void hw_backlight(int on){ pwm2(on ? 0u : 0x176FFu, 0); }
#else
void hw_backlight(int on){ pwm2(on ? 0u : 0x17700u, 0); }
#endif
void hw_wdt_feed(void){ REG(0x4000800Cu)=0x5AFA55AAu; REG(0x4000900Cu)=0x5AFA55AAu; }
TC_INIT void hw_init(void){
wdt_off(); mailbox_clear(); clock_init(); periph_enable(); flashctl_init(); pin_mux();
display_power(); display_init(); backlight_on();
/* Buttons: P0.8 wheel, P0.9 A, P0.10 C, P0.11 B as inputs (active low) */
REG(GPIO0+0x04) &= ~((1u<<8)|(1u<<9)|(1u<<10)|(1u<<11));
flashctl_init();
}
u32 hw_buttons(void){
u32 d = REG(GPIO0+0x00);
u32 b = 0;
if(!(d & (1u<<9))) b |= BTN_A;
if(!(d & (1u<<11))) b |= BTN_B;
if(!(d & (1u<<10))) b |= BTN_C;
if(!(d & (1u<<8))) b |= BTN_WHEEL;
return b;
}
/* Send rectangle x0..x1-1, y0..y1-1 from a 128 wide framebuffer (RGB565) to the panel. */
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1){
u8 ca[4]={0x00,(u8)(x0+2),0x00,(u8)(x1+1)};
u8 ra[4]={0x00,(u8)(y0+1),0x00,(u8)(y1)};
lcd_cmd(0x2a,ca,4); lcd_cmd(0x2b,ra,4);
LCD_DC(0); { u8 c=0x2c; spi_tx(&c,1); }
LCD_DC(1);
for(u32 y=y0;y<y1;y++){
const u16* r=fb+y*stride;
for(u32 x=x0;x<x1;x++){
u8 two[2]={(u8)(r[x]>>8),(u8)r[x]};
spi_tx(&two[0],1); spi_tx(&two[1],1); /* byte by byte like the FU (1.3.8) */
}
}
LCD_DC(0);
}
#ifdef FAST_LCD
/* v0.8.17: pixel output in one go per rectangle, 16 bytes per SPI pass (like the gamma tables
* in display init, which work this way on the device). Before, per byte: wait, pause of 8, wait. */
void hw_px_begin(u32 x0, u32 y0, u32 x1, u32 y1){
u8 ca[4]={0x00,(u8)(x0+2),0x00,(u8)(x1+1)};
u8 ra[4]={0x00,(u8)(y0+1),0x00,(u8)(y1)};
lcd_cmd(0x2a,ca,4); lcd_cmd(0x2b,ra,4);
LCD_DC(0); { u8 c=0x2c; spi_tx(&c,1); }
LCD_DC(1);
}
void hw_px_row(const u16* r, u32 n){
u8 b[16]; u32 k=0;
for(u32 i=0;i<n;i++){ b[k++]=(u8)(r[i]>>8); b[k++]=(u8)r[i]; if(k==16u){ spi_tx(b,16); k=0; } }
if(k) spi_tx(b,k);
}
void hw_px_end(void){ LCD_DC(0); }
#endif
/* Back to the Paradise: firmware routine that reloads the encrypted PRAM image
and restarts (flash 0x110568, XIP 0x100FF569). */
void hw_back_to_paradise(void){
__asm__ volatile("cpsid i");
((void(*)(void))(PARADISE_REBOOT|1u))();
for(;;){}
}
/* Paradise hardware (SNC73410), taken from the mameise flash app
* (display confirmed on the device). Runs from PRAM 0 after SYSRESETREQ. */
#include "io.h"
#include "hw.h"
#include "disp_power.h"
#define PANEL 0x4000E000u
#define FCTL_ 0x40022000u
#define F_STAT REG(FCTL_+0x000)
static void udelay(volatile u32 n){ while(n--) __asm__ volatile("nop"); }
#define MS(x) udelay((u32)(x)*16000u)
#define BB(reg,bit) (*(volatile u32*)(0x42000000u + (((u32)(reg)-0x40000000u)<<5) + ((u32)(bit)<<2)))
#define GPIO0 0x40018000u
#define GPIO1 0x40019000u
#define GPIO2 0x4001A000u
#define LCD_RST(v) (BB(GPIO0+0x00,4)=(v))
#define LCD_DC(v) (BB(GPIO0+0x00,5)=(v))
#define SPI_CTRL REG(PANEL+0x00)
#define SPI_STAT REG(PANEL+0x0C)
#define SPI_DATA REG(PANEL+0x1C)
#define SPIWAIT 200000u
#define CT2 0x40002000u
TC_INIT static void clock_init(void){
REG(CLK+0x00) |= 1u;
REG(CLK+0x0C) = 0;
REG(CLK+0x00) = 0x41u;
{ u32 r = (REG(CLK+0x34) & 0xF00u) | 0xA55A0000u; REG(CLK+0x04) = r; }
REG(CLK+0x18) = 0x21u;
REG(CLK+0x50) = 0;
REG(CLK+0x10C) = 0x001FFFFDu;
REG(CLK+0x110) = 0;
REG(CLK+0x108) = 0;
REG(CLK+0x10) = 0;
REG(CLK+0x00) |= 0x10u;
for(u32 g=0; !((REG(CLK+0x08) >> 4) & 1u) && g<4000000u; g++){}
REG(CLK+0x00) |= 0x4000u;
REG(CLK+0x04) &= ~1u;
REG(CLK+0x00) |= 0x8000u;
for(u32 g=0; !((REG(CLK+0x08) >> 6) & 1u) && g<4000000u; g++){}
{ u32 r = (REG(CLK+0x0C) & ~7u) | 4u; REG(CLK+0x0C) = r; }
for(u32 g=0; ((REG(CLK+0x0C) >> 4) & 7u) != (REG(CLK+0x0C) & 7u) && g<4000000u; g++){} /* bounded: never hang forever */
REG(CLK+0x100) = 0x00157EB7u;
}
TC_INIT static void flashctl_init(void){
/* 1.4.2: enable XIP. We read through the 0x60000000 window that the XIP block
* maps in. Without XIP that window only shows the config register (0x40), not
* the flash data. The real Flash Utility does this at startup, our app did not
* do it after reset until now. That is exactly what was missing. */
REG(0x4002F004u)=0x60011000u;
REG(0x4002F000u)=0x00000003u;
/* 1.4.1: controller init word for word like the real Flash Utility (0x40022000).
* This includes setting the read command/mode in 0x008 and 0x00c (0x3077 / 0xf000),
* otherwise the chip only returns its config register (0x40) instead of flash data. */
F_STAT=0x0000d018u;
F_STAT=0x0000d000u;
F_STAT=0x0000d080u;
F_STAT=0x0000d088u;
REG(FCTL+0x008)=0x00003077u; /* read command/mode */
REG(FCTL+0x00C)=0x0000f000u;
REG(FCTL+0x004)=0x00000400u;
REG(FCTL+0x004)=0x00004000u;
}
TC_INIT static void wdt_off(void){
/* Set up the system/power block EXACTLY like the real Flash Utility. The only
point where we deliberately differed before (bit0 of 0x40008000) might be the
master enable for the display domain. The FU runs with bit0=1 without a
reset, so we copy it 1:1 and feed the watchdog in the loop. */
REG(0x4000900Cu)=0x5AFA55AAu; REG(0x40009000u)=0x5AFA0000u; /* WDT1 */
REG(0x40008000u)=0x5AFA0000u; /* unlock */
REG(0x40008004u)=0x5AFA0002u;
REG(0x40008008u)=0x5AFA00FFu; /* power/clock domains on (incl. display) */
REG(0x4000800Cu)=0x5AFA55AAu; /* feed the watchdog */
/* Do NOT set bit0 (watchdog enable): otherwise it resets the Tama during
display init (back to the planet). */
}
TC_INIT static void mailbox_clear(void){
REG(0x20000000u)=0; REG(0x20000004u)=0; REG(0x20000008u)=0; REG(0x2000000Cu)=0;
}
TC_INIT static void periph_enable(void){ REG(CLK+0x20)=0x40u; }
TC_INIT static void pin_set(u8 id, u8 mode){ *(volatile u8*)(0xE000E400u + id) = (u8)(mode<<4); }
TC_INIT static void pin_mux(void){
static const u8 m12[]={6,7,8,9,0xf,0x10,0x11,0x12,0x13,0x14,0x19,0x1f,0x20,0x22,
0x24,0x25,0x2e,0x2f,0x35,0x36,0x1a,0x1b,0x1c,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x3a,0x3f};
static const u8 m8[]={0,1,2,3};
static const u8 m4[]={0x15,0x17};
for(unsigned i=0;i<sizeof m12;i++) pin_set(m12[i],0xC);
for(unsigned i=0;i<sizeof m8;i++) pin_set(m8[i],0x8);
for(unsigned i=0;i<sizeof m4;i++) pin_set(m4[i],0x4);
}
TC_INIT static void display_power(void){
/* Sequence from the real FU (clock enable, pin setup, timer CT32B3, GPIO1).
As in the FU, 0x45000210..218 get the current contents of the GPIO
data registers (the emulator had returned 0 there). */
for(unsigned i=0;i<DISP_POWER_N;i++){
u32 a=disp_power_seq[i][0], v=disp_power_seq[i][1];
if(a>=0x45000210u && a<=0x45000218u) v=REG(0x4001803Cu + ((a-0x45000210u)>>2)*0x1000u);
REG(a)=v;
}
/* Make sure the panel pins are outputs: reset, D/C, CS (P1.5 low), supply (P1.9 low) */
LCD_RST(1); BB(GPIO0+0x04,4)=1;
LCD_DC(0); BB(GPIO0+0x04,5)=1;
BB(GPIO1+0x00,5)=0; BB(GPIO1+0x04,5)=1;
BB(GPIO1+0x00,9)=0; BB(GPIO1+0x04,9)=1;
MS(20);
}
TC_INIT static void spi_init(void){
/* like FU 0x3f44, as read-modify-write */
#ifdef LCD_FASTCLK
REG(PANEL+0x08)=0; /* clock divider: test in v0.8.18, twice as fast? */
#else
REG(PANEL+0x08)=1; /* clock divider */
#endif
SPI_CTRL &= ~(1u<<18);
REG(PANEL+0x04) &= ~6u; REG(PANEL+0x04) &= ~1u;
SPI_CTRL &= ~0x10u; SPI_CTRL &= ~0x08u;
REG(PANEL+0x20)=0;
SPI_CTRL = (SPI_CTRL & ~0xF00u) | 0x700u; /* 8 bit */
REG(PANEL+0x24) |= 0x80000000u;
REG(PANEL+0x24) &= ~0xFF0000u;
REG(PANEL+0x24) |= 0x80000000u;
REG(PANEL+0x24) &= ~0xFFu;
SPI_CTRL |= 1u; /* SPI on */
SPI_CTRL |= 0xC0u; /* flush FIFOs */
}
static void spi_tx(const u8* p, u32 n){
for(u32 i=0;i<n;i++){
for(u32 g=0; (SPI_STAT & 2u) && g<SPIWAIT; g++){}
SPI_DATA=p[i];
}
udelay(8);
for(u32 g=0; (SPI_STAT & 0x10u) && g<SPIWAIT; g++){}
SPI_CTRL |= 0xC0u;
}
static void lcd_cmd(u8 c, const u8* par, u32 n){
LCD_DC(0); spi_tx(&c,1);
if(n){ LCD_DC(1); spi_tx(par,n); LCD_DC(0); }
}
static const u8 p36[]={0x08}, p3a[]={0x05}, p26[]={0x01},
pb1[]={0x08,0x3b,0x3b}, pb2[]={0x08,0x3b,0x3b}, pb3[]={0x08,0x3b,0x3b,0x08,0x3b,0x3b},
pb4[]={0x03}, pc0[]={0xe0,0x00,0x84}, pc1[]={0xc4}, pc2[]={0x0d,0x00}, pc3[]={0x8d,0x2a},
pc4[]={0x8d,0xee}, pc5[]={0x06},
pe0[]={0x0d,0x17,0x16,0x28,0x3f,0x39,0x30,0x31,0x2c,0x28,0x2f,0x39,0x00,0x04,0x01,0x10},
pe1[]={0x0a,0x15,0x18,0x25,0x3f,0x37,0x2e,0x30,0x2f,0x2c,0x33,0x3f,0x00,0x03,0x04,0x10},
p35[]={0x00}, pcas0[]={0x00,0x02,0x00,0x83}, pras0[]={0x00,0x01,0x00,0x81},
pcas[]={0x00,0x02,0x00,0x81}, pras[]={0x00,0x01,0x00,0x80};
TC_INIT static void display_init(void){
spi_init();
LCD_RST(1); MS(10); LCD_RST(0); MS(20); LCD_RST(1); MS(150); /* panel reset */
lcd_cmd(0x11,0,0); MS(150); /* SLPOUT */
lcd_cmd(0x36,p36,1); lcd_cmd(0x3a,p3a,1); lcd_cmd(0x26,p26,1); lcd_cmd(0x20,0,0);
lcd_cmd(0xb1,pb1,3); lcd_cmd(0xb2,pb2,3); lcd_cmd(0xb3,pb3,6); lcd_cmd(0xb4,pb4,1);
lcd_cmd(0xc0,pc0,3); lcd_cmd(0xc1,pc1,1); lcd_cmd(0xc2,pc2,2); lcd_cmd(0xc3,pc3,2);
lcd_cmd(0xc4,pc4,2); lcd_cmd(0xc5,pc5,1);
lcd_cmd(0xe0,pe0,16); lcd_cmd(0xe1,pe1,16);
lcd_cmd(0x35,p35,1);
lcd_cmd(0x29,0,0); MS(20); /* DISPON */
lcd_cmd(0x2a,pcas0,4); lcd_cmd(0x2b,pras0,4);
lcd_cmd(0x11,0,0); MS(150);
}
static void pwm2(u32 mr1, int first){
if(first) REG(CT2+0x34)=0;
REG(CT2+0x00)=0;
REG(CT2+0x18)=0; REG(CT2+0x1C)=0; REG(CT2+0x20)=0; REG(CT2+0x24)=0;
REG(CT2+0x14)=0;
REG(CT2+0x00)=2; REG(CT2+0x08)=0; REG(CT2+0x00)=0;
REG(CT2+0x14)=0x400u;
REG(CT2+0x24)=0x17700u;
REG(CT2+0x1C)=mr1;
REG(CT2+0x14)=0;
REG(CT2+0x34)=0x00200002u;
REG(CT2+0x00)=2;
REG(CT2+0x3C)=0x1Fu;
REG(CT2+0x00)=1;
}
TC_INIT static void backlight_on(void){
REG(0x40007034u)=0;
pwm2(0x17700u,1);
REG(0x40009000u)=0x5AFA0000u; REG(0x40008000u)=0x5AFA0000u; /* like FU */
REG(0x40018034u)=0x15555155u; REG(0x40019034u)=0x55540140u;
pwm2(0,0);
REG(CLK+0x20)=0x42u;
}
/* ---------------- our own additions ---------------- */
/* Buzzer on timer 7, started and stopped exactly like the firmware does:
* period in 72 MHz clock ticks, short pulse (quiet, like on the Paradise). */
#define CT7 0x40007000u
#ifdef TONE_FIX
/* v0.8.15: the counter runs periodically (MCTRL bit 10 = restart at MR3, like the backlight with 0x400).
* Before, MCTRL ended up at 0: only a single pulse per call, so a click instead of a tone.
* If only the pitch changes, only MR0/MR3 are set again (no restart, no click). */
void hw_tone(u32 hz){
static u32 on;
if(!hz){ REG(CT7+0x34)=0; REG(CT7+0x00)=0; on=0; return; }
u32 per = 72000000u / hz, mr0 = per - per/32u;
if(on){ REG(CT7+0x24)=per; REG(CT7+0x18)=mr0; return; }
REG(CT7+0x34)=0;
REG(CT7+0x00)=2; REG(CT7+0x08)=0; REG(CT7+0x00)=0;
REG(CT7+0x18)=mr0; REG(CT7+0x1C)=0; REG(CT7+0x20)=0;
REG(CT7+0x24)=per;
REG(CT7+0x14)=0x400u;
REG(CT7+0x34)=0x00100001u;
REG(CT7+0x3C)=0x1Fu;
REG(CT7+0x00)=1;
on=1;
}
#else
void hw_tone(u32 hz){
if(!hz){ REG(CT7+0x34)=0; return; }
u32 per = 72000000u / hz, mr0 = per - per/32u;
REG(CT7+0x34)=0;
REG(CT7+0x00)=0;
REG(CT7+0x18)=0; REG(CT7+0x1C)=0; REG(CT7+0x20)=0; REG(CT7+0x24)=0;
REG(CT7+0x14)=0;
REG(CT7+0x00)=2; REG(CT7+0x08)=0; REG(CT7+0x00)=0;
REG(CT7+0x14)=0x600u;
REG(CT7+0x24)=per;
REG(CT7+0x18)=mr0;
REG(CT7+0x14)=0;
REG(CT7+0x34)=0x00100001u;
REG(CT7+0x00)=2;
REG(CT7+0x3C)=0x1Fu;
REG(CT7+0x00)=1;
}
#endif
void hw_bl_pwm_off(void){ REG(CT2+0x00)=0; REG(CT2+0x34)=0; } /* backlight off only (when leaving) */
#ifdef BL_SLEEP
/* v0.8.18: off = put the display to sleep (DISPOFF, SLPIN) and stop the backlight timer,
* PWM output off (like panel_down in the Flash Tool). On = SLPOUT, short wait, DISPON, restart backlight.
* MR1 values alone (v0.8.17) had no effect on the device. */
void hw_backlight(int on){
static int is_on=1;
if(on){ if(is_on) return; lcd_cmd(0x11,0,0); MS(10); lcd_cmd(0x29,0,0); pwm2(0u,1); is_on=1; }
else { if(!is_on) return; REG(CT2+0x00)=0; REG(CT2+0x34)=0; lcd_cmd(0x28,0,0); lcd_cmd(0x10,0,0); is_on=0; }
}
#elif defined(BL_OFFFIX)
/* v0.8.17: duty cycle 0 = full brightness. MR1 equal to the period (0x17700) never matches, so it stayed bright.
* One tick before the end of the period is practically dark. */
void hw_backlight(int on){ pwm2(on ? 0u : 0x176FFu, 0); }
#else
void hw_backlight(int on){ pwm2(on ? 0u : 0x17700u, 0); }
#endif
void hw_wdt_feed(void){ REG(0x4000800Cu)=0x5AFA55AAu; REG(0x4000900Cu)=0x5AFA55AAu; }
TC_INIT void hw_init(void){
wdt_off(); mailbox_clear(); clock_init(); periph_enable(); flashctl_init(); pin_mux();
display_power(); display_init(); backlight_on();
/* Buttons: P0.8 wheel, P0.9 A, P0.10 C, P0.11 B as inputs (active low) */
REG(GPIO0+0x04) &= ~((1u<<8)|(1u<<9)|(1u<<10)|(1u<<11));
flashctl_init();
}
u32 hw_buttons(void){
u32 d = REG(GPIO0+0x00);
u32 b = 0;
if(!(d & (1u<<9))) b |= BTN_A;
if(!(d & (1u<<11))) b |= BTN_B;
if(!(d & (1u<<10))) b |= BTN_C;
if(!(d & (1u<<8))) b |= BTN_WHEEL;
return b;
}
/* Send rectangle x0..x1-1, y0..y1-1 from a 128 wide framebuffer (RGB565) to the panel. */
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1){
u8 ca[4]={0x00,(u8)(x0+2),0x00,(u8)(x1+1)};
u8 ra[4]={0x00,(u8)(y0+1),0x00,(u8)(y1)};
lcd_cmd(0x2a,ca,4); lcd_cmd(0x2b,ra,4);
LCD_DC(0); { u8 c=0x2c; spi_tx(&c,1); }
LCD_DC(1);
for(u32 y=y0;y<y1;y++){
const u16* r=fb+y*stride;
for(u32 x=x0;x<x1;x++){
u8 two[2]={(u8)(r[x]>>8),(u8)r[x]};
spi_tx(&two[0],1); spi_tx(&two[1],1); /* byte by byte like the FU (1.3.8) */
}
}
LCD_DC(0);
}
#ifdef FAST_LCD
/* v0.8.17: pixel output in one go per rectangle, 16 bytes per SPI pass (like the gamma tables
* in display init, which work this way on the device). Before, per byte: wait, pause of 8, wait. */
void hw_px_begin(u32 x0, u32 y0, u32 x1, u32 y1){
u8 ca[4]={0x00,(u8)(x0+2),0x00,(u8)(x1+1)};
u8 ra[4]={0x00,(u8)(y0+1),0x00,(u8)(y1)};
lcd_cmd(0x2a,ca,4); lcd_cmd(0x2b,ra,4);
LCD_DC(0); { u8 c=0x2c; spi_tx(&c,1); }
LCD_DC(1);
}
void hw_px_row(const u16* r, u32 n){
u8 b[16]; u32 k=0;
for(u32 i=0;i<n;i++){ b[k++]=(u8)(r[i]>>8); b[k++]=(u8)r[i]; if(k==16u){ spi_tx(b,16); k=0; } }
if(k) spi_tx(b,k);
}
void hw_px_end(void){ LCD_DC(0); }
#endif
/* Back to the Paradise: firmware routine that reloads the encrypted PRAM image
and restarts (flash 0x110568, XIP 0x100FF569). */
void hw_back_to_paradise(void){
__asm__ volatile("cpsid i");
((void(*)(void))(PARADISE_REBOOT|1u))();
for(;;){}
}
+24 -24
View File
@@ -1,24 +1,24 @@
#ifndef HW_H
#define HW_H
#include "io.h"
#define BTN_A 1u
#define BTN_B 2u
#define BTN_C 4u
#define BTN_WHEEL 8u
#ifndef PARADISE_REBOOT
#define PARADISE_REBOOT 0x100FF568u
#endif
void hw_init(void);
void hw_wdt_feed(void);
u32 hw_buttons(void);
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1);
void hw_back_to_paradise(void);
void hw_backlight(int on);
void hw_bl_pwm_off(void);
void hw_tone(u32 hz); /* 0 = off */
#ifdef FAST_LCD
void hw_px_begin(u32 x0, u32 y0, u32 x1, u32 y1);
void hw_px_row(const u16* r, u32 n);
void hw_px_end(void);
#endif
#endif
#ifndef HW_H
#define HW_H
#include "io.h"
#define BTN_A 1u
#define BTN_B 2u
#define BTN_C 4u
#define BTN_WHEEL 8u
#ifndef PARADISE_REBOOT
#define PARADISE_REBOOT 0x100FF568u
#endif
void hw_init(void);
void hw_wdt_feed(void);
u32 hw_buttons(void);
void hw_push(const u16* fb, u32 stride, u32 x0, u32 y0, u32 x1, u32 y1);
void hw_back_to_paradise(void);
void hw_backlight(int on);
void hw_bl_pwm_off(void);
void hw_tone(u32 hz); /* 0 = off */
#ifdef FAST_LCD
void hw_px_begin(u32 x0, u32 y0, u32 x1, u32 y1);
void hw_px_row(const u16* r, u32 n);
void hw_px_end(void);
#endif
#endif
+13 -13
View File
@@ -1,13 +1,13 @@
#ifndef IO_H
#define IO_H
typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8;
#define REG(a) (*(volatile u32*)(a))
#define UART 0x4000B000u
#define FCTL 0x40022000u
#define CLK 0x45000000u
static inline void dsb(void){ __asm__ volatile("dsb":::"memory"); }
#ifndef TC_INIT
#define TC_INIT __attribute__((section(".initcode"), noinline))
#endif
#endif
#ifndef IO_H
#define IO_H
typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8;
#define REG(a) (*(volatile u32*)(a))
#define UART 0x4000B000u
#define FCTL 0x40022000u
#define CLK 0x45000000u
static inline void dsb(void){ __asm__ volatile("dsb":::"memory"); }
#ifndef TC_INIT
#define TC_INIT __attribute__((section(".initcode"), noinline))
#endif
#endif
+14 -14
View File
@@ -1,14 +1,14 @@
#include <stddef.h>
void *memset(void *d, int c, size_t n){ unsigned char *p=d; while(n--) *p++=(unsigned char)c; return d; }
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; }
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; }
void __aeabi_memcpy(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memcpy4(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memcpy8(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memset(void *d, size_t n, int c){ memset(d,c,n); }
void __aeabi_memset4(void *d, size_t n, int c){ memset(d,c,n); }
void __aeabi_memclr(void *d, size_t n){ memset(d,0,n); }
void __aeabi_memclr4(void *d, size_t n){ memset(d,0,n); }
void __aeabi_memclr8(void *d, size_t n){ memset(d,0,n); }
#include <stddef.h>
void *memset(void *d, int c, size_t n){ unsigned char *p=d; while(n--) *p++=(unsigned char)c; return d; }
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; }
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; }
void __aeabi_memcpy(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memcpy4(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memcpy8(void *d, const void *s, size_t n){ memcpy(d,s,n); }
void __aeabi_memset(void *d, size_t n, int c){ memset(d,c,n); }
void __aeabi_memset4(void *d, size_t n, int c){ memset(d,c,n); }
void __aeabi_memclr(void *d, size_t n){ memset(d,0,n); }
void __aeabi_memclr4(void *d, size_t n){ memset(d,0,n); }
void __aeabi_memclr8(void *d, size_t n){ memset(d,0,n); }
+20 -20
View File
@@ -1,20 +1,20 @@
ENTRY(Reset_Handler)
MEMORY {
PRAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x10000
SRAM (rw) : ORIGIN = 0x18000000, LENGTH = 0x1E000
}
SECTIONS {
.text : {
KEEP(*(.vectors))
KEEP(*(.pmxcfg))
*(.text*)
*(.rodata*)
KEEP(*(.initcode))
KEEP(*(.initdata*))
. = ALIGN(4);
} > PRAM
.bss (NOLOAD) : { __bss_start = .; *(.bss*) *(COMMON) . = ALIGN(4); __bss_end = .; } > SRAM
ASSERT(SIZEOF(.data) == 0, "no initialised data allowed")
.data : { *(.data*) } > SRAM
/DISCARD/ : { *(.comment) *(.ARM.*) *(.note*) }
}
ENTRY(Reset_Handler)
MEMORY {
PRAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x10000
SRAM (rw) : ORIGIN = 0x18000000, LENGTH = 0x1E000
}
SECTIONS {
.text : {
KEEP(*(.vectors))
KEEP(*(.pmxcfg))
*(.text*)
*(.rodata*)
KEEP(*(.initcode))
KEEP(*(.initdata*))
. = ALIGN(4);
} > PRAM
.bss (NOLOAD) : { __bss_start = .; *(.bss*) *(COMMON) . = ALIGN(4); __bss_end = .; } > SRAM
ASSERT(SIZEOF(.data) == 0, "no initialised data allowed")
.data : { *(.data*) } > SRAM
/DISCARD/ : { *(.comment) *(.ARM.*) *(.note*) }
}
+1830 -1830
View File
File diff suppressed because it is too large. Load diff
+31 -31
View File
@@ -1,31 +1,31 @@
/* Synthetic PC-only fixture: contains no vendor ROM or device data. */
#define HOST
#include "main-ko.c"
#define main upstream_host_main
#define g_out host_output_path
#include "host.c"
#undef g_out
#undef main
static void scenario(void (*fn)(void), const char *keys){
g_seq=keys;g_pos=0;if(!setjmp(g_jb))fn();
}
static void show_fields(void){field_menu(0,0);}
static void sample_message(void){message("\200\200","","");}
int main(int argc,char **argv){
if(argc!=2)return 2;
g_dir=argv[1];g_frame=0;host_flash=malloc(0x1000000);memset(host_flash,0xFF,0x1000000);
for(u32 i=0;i<PAGE;i++)g_ff[i]=255;
g_cfg.flags=F_FIELDS|F_BAG|F_TAMA|F_SAVES;
g_cfg.version=9;g_cfg.nfields=3;g_cfg.nslots=3;g_cfg.slot_off=0x800000;g_cfg.slot_size=0x10000;
g_cfg.cat_n=0;g_cfg.tama_off=0x200;g_cfg.level_off=0x240;
g_cfg.money_off=0x250;g_cfg.list_off=0x300;g_cfg.count_off=0x900;g_cfg.field_byte=443;
g_cur=0;g_act=0;g_napp=2;strcpy(g_appnm[0],"TAMA-GO");strcpy(g_appnm[1],"V3");
memset(g_set,0,PAGE);g_set[0x1c]=2026&255;g_set[0x1d]=2026>>8;g_set[0x1e]=11;g_set[0x20]=10;
g_set[g_cfg.tama_off+0x1c]=6;g_set[g_cfg.tama_off+0x1d]=20;g_set[g_cfg.level_off]=5;
g_set[g_cfg.money_off]=0x39;g_set[g_cfg.money_off+1]=0x30;
stamp(g_set);memcpy(host_flash+SET_A,g_set,PAGE);memcpy(host_flash+SET_B,g_set,PAGE);
scenario(main_menu,"nnnnc");scenario(tama_menu,"nnc");scenario(show_fields,"nc");
scenario(points_menu,"c");scenario(level_edit,"c");scenario(care_full,"c");
printf("Synthetic menu frames: %d\n",g_frame);
free(host_flash);return 0;
}
/* Synthetic PC-only fixture: contains no vendor ROM or device data. */
#define HOST
#include "main-ko.c"
#define main upstream_host_main
#define g_out host_output_path
#include "host.c"
#undef g_out
#undef main
static void scenario(void (*fn)(void), const char *keys){
g_seq=keys;g_pos=0;if(!setjmp(g_jb))fn();
}
static void show_fields(void){field_menu(0,0);}
static void sample_message(void){message("\200\200","","");}
int main(int argc,char **argv){
if(argc!=2)return 2;
g_dir=argv[1];g_frame=0;host_flash=malloc(0x1000000);memset(host_flash,0xFF,0x1000000);
for(u32 i=0;i<PAGE;i++)g_ff[i]=255;
g_cfg.flags=F_FIELDS|F_BAG|F_TAMA|F_SAVES;
g_cfg.version=9;g_cfg.nfields=3;g_cfg.nslots=3;g_cfg.slot_off=0x800000;g_cfg.slot_size=0x10000;
g_cfg.cat_n=0;g_cfg.tama_off=0x200;g_cfg.level_off=0x240;
g_cfg.money_off=0x250;g_cfg.list_off=0x300;g_cfg.count_off=0x900;g_cfg.field_byte=443;
g_cur=0;g_act=0;g_napp=2;strcpy(g_appnm[0],"TAMA-GO");strcpy(g_appnm[1],"V3");
memset(g_set,0,PAGE);g_set[0x1c]=2026&255;g_set[0x1d]=2026>>8;g_set[0x1e]=11;g_set[0x20]=10;
g_set[g_cfg.tama_off+0x1c]=6;g_set[g_cfg.tama_off+0x1d]=20;g_set[g_cfg.level_off]=5;
g_set[g_cfg.money_off]=0x39;g_set[g_cfg.money_off+1]=0x30;
stamp(g_set);memcpy(host_flash+SET_A,g_set,PAGE);memcpy(host_flash+SET_B,g_set,PAGE);
scenario(main_menu,"nnnnc");scenario(tama_menu,"nnc");scenario(show_fields,"nc");
scenario(points_menu,"c");scenario(level_edit,"c");scenario(care_full,"c");
printf("Synthetic menu frames: %d\n",g_frame);
free(host_flash);return 0;
}
+346 -346
View File
@@ -1,346 +1,346 @@
@ Stub in XIP flash: copies the app image to PRAM 0 and restarts.
@ APP_SRC (XIP address of the image) is set at build time.
@ With HOOKS: four entry points for the home screen handlers. They count how
@ long A and C are held together, start the emulator after LIMIT calls and
@ otherwise call the original handler.
.syntax unified
.thumb
@ Autostart (v1.2.8): with AUTO set, the stub decides once per boot (first home screen call)
@ whether to start the emulator right away. Mailbox word 0x20000FFC (kept over a restart and
@ the reset button, lost in the Paradise's deep sleep):
@ "PMXL" written by the emulator when going back: stay in the Paradise
@ "PMXR" written here: any later restart with it (reset button) starts the emulator
@ other power-on or waking from deep sleep: the Paradise's seconds counter tells them
@ apart (it starts at 0 after power-on and when the clock is set)
@ Holding B skips the emulator. "Decided this boot" is kept in the UsageFault priority
@ (SHPR1 byte 2): it is cleared by every reset and the firmware does not use it.
@ AUTO is a placeholder the Studio sets to 0 or 1.
#ifndef AUTO
#define AUTO 0
#endif
.macro AUTOSTART
#if defined(HOOKS)
ldr r2, =AUTO
cbz r2, 7f
ldr r2, =0xE000ED18
ldrb r3, [r2, #2]
cbnz r3, 7f @ already decided in this boot
movs r3, #0xFF
strb r3, [r2, #2]
ldrb r3, [r2, #2]
cbz r3, 7f @ cannot keep the flag: never autostart
ldr r2, =0x20000FFC
ldr r3, [r2]
ldr r0, =0x4C584D50 @ "PMXL": back from the emulator
cmp r3, r0
beq 8f
ldr r0, =0x52584D50 @ "PMXR": restart while running
cmp r3, r0
beq 9f
ldr r0, =0x45000304 @ mailbox lost: deep sleep (clock ran) or power-on (clock new)
ldr r0, [r0]
cmp r0, #30
bhs 8f
9:
ldr r0, =0x52584D50
str r0, [r2]
tst r1, #0x800 @ B (P0.11) held: stay in the Paradise
beq 7f
b start
8:
ldr r0, =0x52584D50
str r0, [r2]
7:
ldr r0, =0x40018000
#endif
.endm
@ 1.7.2 test19 (BFALL): C held when the Paradise comes up after switching on (or after the reset button) starts
@ the flash app of the write protection (0xFF0000, its load table at 0xFFE000), a way back when a program or a
@ save leaves the screen black. Once per boot (BusFault priority byte as the flag, the firmware does not use it);
@ not when back from a program on purpose ("PMXL") and not after waking from deep sleep (mailbox lost, clock ran).
#ifndef NO_BFALL
.macro BFALL
ldr r2, =0xE000ED19
ldrb r3, [r2]
cbnz r3, 7f
movs r3, #0xFF
strb r3, [r2]
ldrb r3, [r2]
cbz r3, 7f
tst r1, #0x400 @ C (P0.10); B at switching on already skips the autostart
bne 7f
#ifndef BFALL_WITH_A
@ 1.7.3 test29 (BFALL_NOA): not with A held too. A and C is the program key on the home screen; the first home
@ handler call of a boot with A+C held (within 30 s of switching on, or after a reset) started the flash app instead.
tst r1, #0x200 @ A (P0.9) held: the menu key, no way back
beq 7f
#endif
ldr r2, =0x20000FFC
ldr r2, [r2]
ldr r0, =0x4C584D50
cmp r2, r0
beq 7f
ldr r0, =0x45000304
ldr r0, [r0]
cmp r0, #30
blo 6f
ldr r0, =0x52584D50 @ "PMXR" / "PMXM": a reset, the mailbox was kept
cmp r2, r0
beq 6f
ldr r0, =0x4D584D50
cmp r2, r0
bne 7f
6:ldr r0, =0x60FFE000 @ load table of the flash app, uncached flash
ldr r2, [r0]
ldr r3, =0x494E4F53 @ "SONI"
cmp r2, r3
bne 7f
ldr r2, [r0, #0x10]
ldr r3, =0x60FF0000
cmp r2, r3
bne 7f
cpsid i
mov r4, r3
b realstart
7:
ldr r0, =0x40018000
ldr r1, [r0]
.endm
#else
.macro BFALL
.endm
#endif
.global start
.thumb_func
start:
cpsid i
#ifdef FELD
ldr r4, app_src
b.w realstart
.align 2
app_src: .word APP_SRC
@ 1.6.0: start the program image at r0 (XIP address), fixed at +0x0C. The menu starts its
@ other programs (more emulators) through here.
.global start_src
.thumb_func
start_src:
cpsid i
mov r4, r0
@ 1.6.6: the cached window (0x10000000) shows only 1 MB from 0x11000; programs further up (more emulators
@ from 0xD40000 down) came out as garbage. Copy from the uncached flash (0x60000000 + offset) instead.
add r4, r4, #0x50000000
add r4, r4, #0x11000
b.w realstart
@ 1.6.8: launcher ROM ("only a start device for programs"): the Studio points the handlers of every
@ scene after the setup (home, events, care ...) here, so the menu starts instead of the Paradise game.
.org 0x20
.global launch
.thumb_func
launch:
cpsid i
ldr r4, feld_src
b.w realstart
.align 2
feld_src: .word FELD_SRC
@ 1.6.8: entry for the start device's trampolines (r12 = the scene's original handler): the menu starts
@ only once the Paradise has a save (settings block 0xEFE000 stamped, date set), otherwise the original
@ handler runs, so a setup after "reset" can finish in the Paradise itself.
.org 0x2C
.global lcheck_e
.thumb_func
lcheck_e:
b.w lcheck
#else
ldr r4, =APP_SRC
b.w realstart
.ltorg
#endif
#if defined(HOOKS) && !defined(FELD)
.org 0x40 @ hooks fixed at 0x40 (Studio: HOOK_OFF), original handlers at 0x94
.global hook0, hook1, hook2, hook3
.thumb_func
hook0: ldr.w r12, orig0
b check
.thumb_func
hook1: ldr.w r12, orig1
b check
.thumb_func
hook2: ldr.w r12, orig2
b check
.thumb_func
hook3: ldr.w r12, orig3
b check
.org 0x94
orig0: .word ORIG0
orig1: .word ORIG1
orig2: .word ORIG2
orig3: .word ORIG3
.thumb_func
check:
push {r0-r3, r12, lr}
ldr r0, =0x40018000 @ GPIO0: A = P0.9, C = P0.10, pressed = 0
ldr r1, [r0]
BFALL
AUTOSTART
ldr r2, =0x20000FF8 @ counter at the end of the mailbox
ldr r3, [r2]
tst r1, #0x600
bne 5f
lsrs r0, r3, #16
movw r1, #0xE7A1
cmp r0, r1
beq 4f
movw r3, #0
movt r3, #0xE7A1
4:
adds r3, #1
str r3, [r2]
uxth r0, r3
cmp r0, #LIMIT
bhs start
b 6f
5:
movs r3, #0
str r3, [r2]
6:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
#if defined(HOOKS) && defined(FELD)
@ With field switch: A+C starts the field switch (FELD_SRC), which in turn also
@ offers the program (APP_SRC). Return targets fixed at 0x94 as before.
.org 0x40
.global hook0, hook1, hook2, hook3
.thumb_func
hook0: ldr.w r12, orig0
b check
.thumb_func
hook1: ldr.w r12, orig1
b check
.thumb_func
hook2: ldr.w r12, orig2
b check
.thumb_func
hook3: ldr.w r12, orig3
b check
.org 0x94
orig0: .word ORIG0
orig1: .word ORIG1
orig2: .word ORIG2
orig3: .word ORIG3
.thumb_func
check:
push {r0-r3, r12, lr}
ldr r0, =0x40018000 @ GPIO0: A = P0.9, C = P0.10, pressed = 0
ldr r1, [r0]
BFALL
AUTOSTART
ldr r2, =0x20000FF8 @ counter at the end of the mailbox
ldr r3, [r2]
#ifndef HOOK_TEST
tst r1, #0x600
bne 5f
#endif
lsrs r0, r3, #16
movw r1, #0xE7A1
cmp r0, r1
beq 4f
movw r3, #0
movt r3, #0xE7A1
4:
adds r3, #1
str r3, [r2]
uxth r0, r3
cmp r0, #LIMIT
blo 6f
ldr.w r4, feld_src
cmp r4, #0
beq start
cpsid i
b realstart
5:
movs r3, #0
str r3, [r2]
6:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
#if defined(HOOKS) && defined(FELD)
.thumb_func
lcheck:
push {r0-r3, r12, lr}
ldr r0, =0x60EFE000 @ settings block, uncached flash
ldrh r1, [r0, #0]
ldrh r2, [r0, #2]
mvns r2, r2
uxth r2, r2
cmp r1, r2 @ stamp: CRC and its inverse
bne 1f
ldrh r1, [r0, #0x1C] @ year 2020..2099
movw r2, #2020
cmp r1, r2
blo 1f
movw r2, #2099
cmp r1, r2
bhi 1f
ldrh r1, [r0, #0x1E] @ month 1..12
subs r1, #1
cmp r1, #12
bhs 1f
cpsid i
ldr.w r4, feld_src
b realstart
1:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
@ Restart like the firmware itself (routine at flash 0x110568): first switch the
@ clock to source 4 (0x45000000 = 0x8041, 0x4500000C = 4, wait for 0x44), then
@ copy the image to PRAM 0, then SYSRESETREQ. v0.8 without this sequence froze
@ the real device after A+C (suspected: clock), the emulator did not show it.
.thumb_func
realstart:
cpsid i
ldr r3, =0x45000000
movw r2, #0x8041
str r2, [r3]
movs r2, #4
str r2, [r3, #0xC]
ldr r1, =0x400000
3:
ldr r2, [r3, #0xC]
cmp r2, #0x44
beq 4f
subs r1, #1
bne 3b
4:
mov r0, r4
movs r1, #0
ldr r2, =0x10000
1:
ldr r3, [r0], #4
str r3, [r1], #4
subs r2, #4
bne 1b
dsb
isb
ldr r0, =0xE000ED08 @ VTOR = 0, as after a real reset
movs r1, #0
str r1, [r0]
ldr r0, =0xE000ED0C @ AIRCR: keep priority grouping, SYSRESETREQ
ldr r1, [r0]
and r1, r1, #0x700
ldr r2, =0x05FA0004
orrs r1, r2
str r1, [r0]
dsb
2:
b 2b
.ltorg
@ Stub in XIP flash: copies the app image to PRAM 0 and restarts.
@ APP_SRC (XIP address of the image) is set at build time.
@ With HOOKS: four entry points for the home screen handlers. They count how
@ long A and C are held together, start the emulator after LIMIT calls and
@ otherwise call the original handler.
.syntax unified
.thumb
@ Autostart (v1.2.8): with AUTO set, the stub decides once per boot (first home screen call)
@ whether to start the emulator right away. Mailbox word 0x20000FFC (kept over a restart and
@ the reset button, lost in the Paradise's deep sleep):
@ "PMXL" written by the emulator when going back: stay in the Paradise
@ "PMXR" written here: any later restart with it (reset button) starts the emulator
@ other power-on or waking from deep sleep: the Paradise's seconds counter tells them
@ apart (it starts at 0 after power-on and when the clock is set)
@ Holding B skips the emulator. "Decided this boot" is kept in the UsageFault priority
@ (SHPR1 byte 2): it is cleared by every reset and the firmware does not use it.
@ AUTO is a placeholder the Studio sets to 0 or 1.
#ifndef AUTO
#define AUTO 0
#endif
.macro AUTOSTART
#if defined(HOOKS)
ldr r2, =AUTO
cbz r2, 7f
ldr r2, =0xE000ED18
ldrb r3, [r2, #2]
cbnz r3, 7f @ already decided in this boot
movs r3, #0xFF
strb r3, [r2, #2]
ldrb r3, [r2, #2]
cbz r3, 7f @ cannot keep the flag: never autostart
ldr r2, =0x20000FFC
ldr r3, [r2]
ldr r0, =0x4C584D50 @ "PMXL": back from the emulator
cmp r3, r0
beq 8f
ldr r0, =0x52584D50 @ "PMXR": restart while running
cmp r3, r0
beq 9f
ldr r0, =0x45000304 @ mailbox lost: deep sleep (clock ran) or power-on (clock new)
ldr r0, [r0]
cmp r0, #30
bhs 8f
9:
ldr r0, =0x52584D50
str r0, [r2]
tst r1, #0x800 @ B (P0.11) held: stay in the Paradise
beq 7f
b start
8:
ldr r0, =0x52584D50
str r0, [r2]
7:
ldr r0, =0x40018000
#endif
.endm
@ 1.7.2 test19 (BFALL): C held when the Paradise comes up after switching on (or after the reset button) starts
@ the flash app of the write protection (0xFF0000, its load table at 0xFFE000), a way back when a program or a
@ save leaves the screen black. Once per boot (BusFault priority byte as the flag, the firmware does not use it);
@ not when back from a program on purpose ("PMXL") and not after waking from deep sleep (mailbox lost, clock ran).
#ifndef NO_BFALL
.macro BFALL
ldr r2, =0xE000ED19
ldrb r3, [r2]
cbnz r3, 7f
movs r3, #0xFF
strb r3, [r2]
ldrb r3, [r2]
cbz r3, 7f
tst r1, #0x400 @ C (P0.10); B at switching on already skips the autostart
bne 7f
#ifndef BFALL_WITH_A
@ 1.7.3 test29 (BFALL_NOA): not with A held too. A and C is the program key on the home screen; the first home
@ handler call of a boot with A+C held (within 30 s of switching on, or after a reset) started the flash app instead.
tst r1, #0x200 @ A (P0.9) held: the menu key, no way back
beq 7f
#endif
ldr r2, =0x20000FFC
ldr r2, [r2]
ldr r0, =0x4C584D50
cmp r2, r0
beq 7f
ldr r0, =0x45000304
ldr r0, [r0]
cmp r0, #30
blo 6f
ldr r0, =0x52584D50 @ "PMXR" / "PMXM": a reset, the mailbox was kept
cmp r2, r0
beq 6f
ldr r0, =0x4D584D50
cmp r2, r0
bne 7f
6:ldr r0, =0x60FFE000 @ load table of the flash app, uncached flash
ldr r2, [r0]
ldr r3, =0x494E4F53 @ "SONI"
cmp r2, r3
bne 7f
ldr r2, [r0, #0x10]
ldr r3, =0x60FF0000
cmp r2, r3
bne 7f
cpsid i
mov r4, r3
b realstart
7:
ldr r0, =0x40018000
ldr r1, [r0]
.endm
#else
.macro BFALL
.endm
#endif
.global start
.thumb_func
start:
cpsid i
#ifdef FELD
ldr r4, app_src
b.w realstart
.align 2
app_src: .word APP_SRC
@ 1.6.0: start the program image at r0 (XIP address), fixed at +0x0C. The menu starts its
@ other programs (more emulators) through here.
.global start_src
.thumb_func
start_src:
cpsid i
mov r4, r0
@ 1.6.6: the cached window (0x10000000) shows only 1 MB from 0x11000; programs further up (more emulators
@ from 0xD40000 down) came out as garbage. Copy from the uncached flash (0x60000000 + offset) instead.
add r4, r4, #0x50000000
add r4, r4, #0x11000
b.w realstart
@ 1.6.8: launcher ROM ("only a start device for programs"): the Studio points the handlers of every
@ scene after the setup (home, events, care ...) here, so the menu starts instead of the Paradise game.
.org 0x20
.global launch
.thumb_func
launch:
cpsid i
ldr r4, feld_src
b.w realstart
.align 2
feld_src: .word FELD_SRC
@ 1.6.8: entry for the start device's trampolines (r12 = the scene's original handler): the menu starts
@ only once the Paradise has a save (settings block 0xEFE000 stamped, date set), otherwise the original
@ handler runs, so a setup after "reset" can finish in the Paradise itself.
.org 0x2C
.global lcheck_e
.thumb_func
lcheck_e:
b.w lcheck
#else
ldr r4, =APP_SRC
b.w realstart
.ltorg
#endif
#if defined(HOOKS) && !defined(FELD)
.org 0x40 @ hooks fixed at 0x40 (Studio: HOOK_OFF), original handlers at 0x94
.global hook0, hook1, hook2, hook3
.thumb_func
hook0: ldr.w r12, orig0
b check
.thumb_func
hook1: ldr.w r12, orig1
b check
.thumb_func
hook2: ldr.w r12, orig2
b check
.thumb_func
hook3: ldr.w r12, orig3
b check
.org 0x94
orig0: .word ORIG0
orig1: .word ORIG1
orig2: .word ORIG2
orig3: .word ORIG3
.thumb_func
check:
push {r0-r3, r12, lr}
ldr r0, =0x40018000 @ GPIO0: A = P0.9, C = P0.10, pressed = 0
ldr r1, [r0]
BFALL
AUTOSTART
ldr r2, =0x20000FF8 @ counter at the end of the mailbox
ldr r3, [r2]
tst r1, #0x600
bne 5f
lsrs r0, r3, #16
movw r1, #0xE7A1
cmp r0, r1
beq 4f
movw r3, #0
movt r3, #0xE7A1
4:
adds r3, #1
str r3, [r2]
uxth r0, r3
cmp r0, #LIMIT
bhs start
b 6f
5:
movs r3, #0
str r3, [r2]
6:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
#if defined(HOOKS) && defined(FELD)
@ With field switch: A+C starts the field switch (FELD_SRC), which in turn also
@ offers the program (APP_SRC). Return targets fixed at 0x94 as before.
.org 0x40
.global hook0, hook1, hook2, hook3
.thumb_func
hook0: ldr.w r12, orig0
b check
.thumb_func
hook1: ldr.w r12, orig1
b check
.thumb_func
hook2: ldr.w r12, orig2
b check
.thumb_func
hook3: ldr.w r12, orig3
b check
.org 0x94
orig0: .word ORIG0
orig1: .word ORIG1
orig2: .word ORIG2
orig3: .word ORIG3
.thumb_func
check:
push {r0-r3, r12, lr}
ldr r0, =0x40018000 @ GPIO0: A = P0.9, C = P0.10, pressed = 0
ldr r1, [r0]
BFALL
AUTOSTART
ldr r2, =0x20000FF8 @ counter at the end of the mailbox
ldr r3, [r2]
#ifndef HOOK_TEST
tst r1, #0x600
bne 5f
#endif
lsrs r0, r3, #16
movw r1, #0xE7A1
cmp r0, r1
beq 4f
movw r3, #0
movt r3, #0xE7A1
4:
adds r3, #1
str r3, [r2]
uxth r0, r3
cmp r0, #LIMIT
blo 6f
ldr.w r4, feld_src
cmp r4, #0
beq start
cpsid i
b realstart
5:
movs r3, #0
str r3, [r2]
6:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
#if defined(HOOKS) && defined(FELD)
.thumb_func
lcheck:
push {r0-r3, r12, lr}
ldr r0, =0x60EFE000 @ settings block, uncached flash
ldrh r1, [r0, #0]
ldrh r2, [r0, #2]
mvns r2, r2
uxth r2, r2
cmp r1, r2 @ stamp: CRC and its inverse
bne 1f
ldrh r1, [r0, #0x1C] @ year 2020..2099
movw r2, #2020
cmp r1, r2
blo 1f
movw r2, #2099
cmp r1, r2
bhi 1f
ldrh r1, [r0, #0x1E] @ month 1..12
subs r1, #1
cmp r1, #12
bhs 1f
cpsid i
ldr.w r4, feld_src
b realstart
1:
pop {r0-r3, r12, lr}
bx r12
.ltorg
#endif
@ Restart like the firmware itself (routine at flash 0x110568): first switch the
@ clock to source 4 (0x45000000 = 0x8041, 0x4500000C = 4, wait for 0x44), then
@ copy the image to PRAM 0, then SYSRESETREQ. v0.8 without this sequence froze
@ the real device after A+C (suspected: clock), the emulator did not show it.
.thumb_func
realstart:
cpsid i
ldr r3, =0x45000000
movw r2, #0x8041
str r2, [r3]
movs r2, #4
str r2, [r3, #0xC]
ldr r1, =0x400000
3:
ldr r2, [r3, #0xC]
cmp r2, #0x44
beq 4f
subs r1, #1
bne 3b
4:
mov r0, r4
movs r1, #0
ldr r2, =0x10000
1:
ldr r3, [r0], #4
str r3, [r1], #4
subs r2, #4
bne 1b
dsb
isb
ldr r0, =0xE000ED08 @ VTOR = 0, as after a real reset
movs r1, #0
str r1, [r0]
ldr r0, =0xE000ED0C @ AIRCR: keep priority grouping, SYSRESETREQ
ldr r1, [r0]
and r1, r1, #0x700
ldr r2, =0x05FA0004
orrs r1, r2
str r1, [r0]
dsb
2:
b 2b
.ltorg