chore: version Zelda 1 port and engineering records

This commit is contained in:
Nilton Constantino
2026-11-16 15:22:13 +00:00
commit 6f2fa420c2
4282 changed files with 822198 additions and 0 deletions
+157
View File
@@ -0,0 +1,157 @@
# Vida de Link
A vida agora usa os slots originais `Items[$18]` e `Items[$19]`, e os corações
do HUD são desenhados a partir desses valores. Há dano nas duas fogueiras da
caverna, redução por anel, recuo, invulnerabilidade temporária, morte e retorno
com três corações ao pressionar Start depois de GAME OVER.
A recuperação por coração, fada e recipiente está implementada como aquisição
de itens na API. Esses objetos ainda não foram colocados no mapa nem gerados
por inimigos. Não foram adicionadas teclas de debug ao jogo normal.
## Representação e aritmética da ROM
| Dado | Representação |
| --- | --- |
| `Items[$18] / HeartValues` | Nibble alto: recipientes menos um; nibble baixo: corações inteiros |
| `Items[$19] / HeartPartial` | Fração do coração, de `$00` a `$FF` |
| `Items[$0B] / InvRing` | Grau 0, 1 ou 2; divide o dano por 1, 2 ou 4 |
| Novo jogo | `$22,$FF`: três recipientes e três corações visualmente cheios |
| Limite | 16 recipientes; as duas linhas de oito corações do HUD |
`Inventory.damage_life(amount)` recebe uma quantidade fixa de 16 bits: 256
representa um coração, 128 meio coração. Retorna 0 para pedido inválido, 1 para
dano sobrevivido e 2 para o ramo de morte da ROM. É o redutor dos bytes, sem
controlar invulnerabilidade, animação ou movimento. Atacantes devem usar
`Link.hurt(amount, attacker_x, attacker_y)`, que aplica essas regras do personagem.
`Link_BeHarmed` empresta `$FF`, não `$100`. Partindo de `$22,$FF`, dois danos de
128 deixam `$21,$FE`, e não uma fração `$FF`. Chegar exatamente a zero não aciona
a morte: o ramo de morte só é tomado quando o dano ultrapassa o saldo. Essa
regra foi preservada, incluindo a necessidade de mais um dano nesse caso.
A cura segue `TakeHeartsNoSound`: acrescenta corações inteiros mantendo a fração,
e preenche a fração quando encontra o limite de recipientes. Por isso, recuperar
um coração a partir de `$21,$7F` resulta em `$22,$7F`; uma cura seguinte preenche
`$FF`. Recipientes acrescentam `$11` a HeartValues, preservando a fração e
limitando o total a 16, como no original.
| Item ID | Efeito implementado |
| --- | --- |
| `$22` (34) | Coração: recupera um coração |
| `$23` (35) | Fada: recupera três corações |
| `$1A` (26) | Recipiente: acrescenta capacidade e um coração inteiro |
`Link.take_life_item(id)` recusa aquisição durante a morte. `Inventory` preserva
as tabelas item→slot/descritor; `take_equipment(id)` usa a classe 2 para níveis
de equipamento, incluindo os anéis, sem rebaixar o grau existente.
## Colisão e reação
`UpdateStandingFire` chama `CheckLinkCollision` na ROM. As fogueiras da caverna
estão em `(72,128)` e `(168,128)`. A colisão usa distância estritamente menor
que nove pixels em ambos os eixos; o tipo `$40` causa `$80` de dano, meio coração.
A proteção da aquisição (ação `$40`) e dos percursos automáticos é preservada.
Um contato aceito arma o contador de invulnerabilidade em `$18`. Ele é reduzido
em frames alternados, como `DecrementInvincibilityTimer`, dando aproximadamente
48 frames de proteção conforme a paridade. Link troca entre as quatro paletas
originais em vez de simplesmente desaparecer. O grau do anel também altera a
cor normal de Link. O ataque continua possível fora dos períodos de bloqueio.
O recuo tem 32 pixels, com inicialização em um frame e até quatro pixels por
frame depois dela. Consulta o terreno na grade e interrompe ao encontrar
parede ou limite. A posição é alinhada como `EnsureObjectAligned` durante o
recuo. Entre células, a escolha de eixo considera a orientação de Link; numa
interseção, esta implementação usa a maior separação ao atacante. A rotina NES
usa também o temporário `$0B`, cujo estado nem sempre é inicializado para fogo
segundo a referência consultada; a equivalência desse caso requer comparação
contra uma execução completa do NES.
## Morte e continuação
O ramo de morte mantém os recipientes, zera a vida e bloqueia comandos e cura.
A apresentação inclui o período inicial, quatro rotações, pose cinza, as duas
faíscas originais, apagamento e texto GAME OVER. Após o período de espera,
Start continua no overworld em `(120,141)`, olhando para cima, com três corações.
Inventário, recipientes e flags de itens coletados permanecem na mesma partida.
A sequência visual de morte ainda não é um port completo do modo `$11`: não
emula os fades de fundo, waits de transferência PPU nem o menu completo
CONTINUE/SAVE/RETRY. Start implementa diretamente a continuação; não há save em
disco nesta etapa. Não há áudio. Os tempos dos principais passos visuais são
explícitos em `LinkVitals`; não se afirma sincronismo global com a execução NES.
## Organização
- `src/inventory/life.pbs`: aritmética dos bytes de vida, cura e classificação
dos 16 espaços de corações; usa o mesmo array Items do inventário.
- `src/link/vitals.pbs`: imunidade, recuo e estado/apresentação da morte.
- `src/link/main.pbs`: integra os efeitos ao personagem e expõe dano/aquisição.
- `src/stages/cave_start`: fornece a colisão com as fogueiras existentes.
- `src/hud`: desenha os corações em vez de usar imagens fixas de três corações.
- `src/stage`: controla apenas o vínculo das telas de apagamento/GAME OVER.
- `src/main.pbs`: encaminha Start para continuar e conserva o fluxo normal.
Assets: HUD base no glyph slot 2, corações/fontes no slot 6, faíscas no slot 7.
Os índices 0–16 do banco HUD foram preservados; 17–19 removem apenas os corações
pré-renderizados, mantendo as bordas das caixas. As paletas adicionais dos três
bancos de Link mantêm os índices originais dos pixels. Novas scenes: 4, tela
apagada; 5, GAME OVER. Nenhum slot anterior foi renumerado.
## Regeneração e testes
```sh
python3 tools/prepare_life.py
python3 tools/validate_life_rom.py
python3 tools/validate_life_captures.py
```
`prepare_life.py` também prepara a base do HUD e preserva os IDs dos assets.
Executá-lo depois de regenerar os bancos de Link/caverna reaplica as paletas de
vida. O gerador é idempotente para as mesmas entradas e substitui os artefatos
gerados, sem editar o código do jogo.
A referência de aritmética executa uma parte limitada dos bytes 6502 da ROM:
7.392 casos de dano, incluindo anéis, e 672 de cura coincidiram com o modelo.
O código comum é mapeado de PRG `$6500` para CPU `$6C90`, conforme a rotina de
cópia; efeitos externos de EndGameMode são substituídos no ensaio, preservando
os bytes de vida e a identificação do ramo de morte. Ver `rom-validation.json`.
Um cartucho de testes temporário executou 79 casos no próprio runtime e os
estados de imunidade/morte/continuação até o frame 470. As 21 capturas completas
coincidiram pixel a pixel com posições de corações, paletas e poses esperadas.
O pixel verde no canto pertence apenas ao protocolo dessa entrada de testes;
qualquer asserção falha o tornaria vermelho de forma persistente.
A entrada é gerada por `tools/generate_life_fixture.py` em
`.tmp/life-fixture-main.pbs`. Durante o teste, `src/main.pbs` foi temporariamente
substituído, com backup em `.tmp/life-production-main.pbs`, e depois restaurado
antes do build jogável. Para repetir esse teste no Studio, é necessário fazer
a mesma troca de forma controlada e restaurar a entrada normal. O gerador não
instala a entrada automaticamente. Não confundir o cartucho de testes com o jogo.
O teste jogável usou apenas controles normais: entrada na caverna, seis contatos
válidos com a fogueira, GAME OVER e Start. A redução dos corações e o retorno
foram conferidos nas capturas. As 28 capturas anteriores de aquisição da espada
continuaram idênticas. `validation/results.json` e `validation/runs.json`
registram resultados, builds e sequência de entrada. Os validadores comparam
capturas salvas; não comandam o Studio.
Os 12 arquivos PBS envolvidos tiveram diagnostics vazios, e o build de produção
foi restaurado. Nenhuma fonte Java foi necessária.
Referências: `Link_BeHarmed`, `TakeHeartsNoSound`, `FormatHeartsInTextBuf` e
`BeginShove` em [Z_01.asm](https://github.com/aldonunez/zelda1-disassembly/blob/master/src/Z_01.asm),
`UpdateStandingFire` em [Z_04.asm](https://github.com/aldonunez/zelda1-disassembly/blob/master/src/Z_04.asm),
`UpdateMode11Death_Full` em [Z_05.asm](https://github.com/aldonunez/zelda1-disassembly/blob/master/src/Z_05.asm),
e `DecrementInvincibilityTimer`/`Obj_Shove` em
[Z_07.asm](https://github.com/aldonunez/zelda1-disassembly/blob/master/src/Z_07.asm).
Atualização do ciclo externo: a entrada jogável agora começa na abertura.
Após GAME OVER surge CONTINUE/RETRY: Select escolhe e Start confirma, seguido
por 64 ticks. Start não reinicia diretamente no estado de morte. Continue
preserva espada/coletas e restaura vida; Retry retorna ao título. Consulte
`../game_flow/README.md`. As capturas acima documentam a implementação anterior;
a nova sessão completa e suas capturas estão em `../game_flow/validation`.
Para fixtures futuras, faça backup do main atual antes da troca temporária.
Binary file not shown.

After

Width:  |  Height:  |  Size: 807 B

+114
View File
@@ -0,0 +1,114 @@
{
"arithmetic_cases": 79,
"final_frame": 470,
"captures": [
{
"name": "damage-r0-128",
"frame": 4,
"packed": 34,
"partial": 127,
"palette": 0
},
{
"name": "damage-r0-384",
"frame": 8,
"packed": 33,
"partial": 127,
"palette": 0
},
{
"name": "damage-r1-128",
"frame": 17,
"packed": 34,
"partial": 191,
"palette": 0
},
{
"name": "damage-r2-128",
"frame": 30,
"packed": 34,
"partial": 223,
"palette": 0
},
{
"name": "containers-13",
"frame": 74,
"packed": 255,
"partial": 255,
"palette": 0
},
{
"name": "empty-life-exact",
"frame": 77,
"packed": 32,
"partial": 0,
"palette": 0
},
{
"name": "heart-item",
"frame": 78,
"packed": 34,
"partial": 127,
"palette": 0
},
{
"name": "fairy-item",
"frame": 79,
"packed": 34,
"partial": 255,
"palette": 0
},
{
"name": "hurt",
"frame": 80
},
{
"name": "immune",
"frame": 81
},
{
"name": "immune_last",
"frame": 126
},
{
"name": "hurt_again",
"frame": 127
},
{
"name": "death_start",
"frame": 175
},
{
"name": "death_spin",
"frame": 208
},
{
"name": "death_grey",
"frame": 288
},
{
"name": "death_spark",
"frame": 312
},
{
"name": "death_large_spark",
"frame": 322
},
{
"name": "death_blank",
"frame": 327
},
{
"name": "game_over",
"frame": 373
},
{
"name": "continue_ready",
"frame": 469
},
{
"name": "continued",
"frame": 470
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

+48
View File
@@ -0,0 +1,48 @@
{
"rom_sha256": "89232edf4f9b52e3cb872094bc78973de080befca2ddea893b6e936066514d4e",
"heart_tiles": [
242,
101,
102,
36
],
"invincibility_counter": 24,
"invincibility_tick_divisor": 2,
"damage_palettes": [
[
15,
41,
39,
23
],
[
15,
2,
34,
48
],
[
15,
22,
39,
48
],
[
15,
12,
28,
44
]
],
"ring_link_colors": [
41,
50,
22
],
"life_slots": [
24,
25
],
"damage_fire": 128,
"source": "Link_BeHarmed, FormatHeartsInTextBuf, TakeHeartsNoSound, DecrementInvincibilityTimer, UpdateMode11Death in local disassembly."
}
+14
View File
@@ -0,0 +1,14 @@
{
"rom_sha256": "89232edf4f9b52e3cb872094bc78973de080befca2ddea893b6e936066514d4e",
"damage_cases": 7392,
"healing_cases": 672,
"mismatches": 0,
"damage_entry": "0x7b5b",
"heal_entry": "0x7450",
"ram_copy": {
"prg": 25856,
"cpu": 27792,
"length": 4720
},
"scope": "Bounded original 6502 life routines versus port arithmetic model; EndGameMode side effects outside life bytes are stubbed."
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

+145
View File
@@ -0,0 +1,145 @@
{
"guest_arithmetic_cases": 79,
"guest_final_frame": 470,
"fixture_captures": 21,
"fixture_full_frame_differences": 0,
"checks": [
{
"name": "damage-r0-128",
"different_pixels": 0
},
{
"name": "damage-r0-384",
"different_pixels": 0
},
{
"name": "damage-r1-128",
"different_pixels": 0
},
{
"name": "damage-r2-128",
"different_pixels": 0
},
{
"name": "containers-13",
"different_pixels": 0
},
{
"name": "empty-life-exact",
"different_pixels": 0
},
{
"name": "heart-item",
"different_pixels": 0
},
{
"name": "fairy-item",
"different_pixels": 0
},
{
"name": "hurt",
"different_pixels": 0
},
{
"name": "immune",
"different_pixels": 0
},
{
"name": "immune_last",
"different_pixels": 0
},
{
"name": "hurt_again",
"different_pixels": 0
},
{
"name": "death_start",
"different_pixels": 0
},
{
"name": "death_spin",
"different_pixels": 0
},
{
"name": "death_grey",
"different_pixels": 0
},
{
"name": "death_spark",
"different_pixels": 0
},
{
"name": "death_large_spark",
"different_pixels": 0
},
{
"name": "death_blank",
"different_pixels": 0
},
{
"name": "game_over",
"different_pixels": 0
},
{
"name": "continue_ready",
"different_pixels": 0
},
{
"name": "continued",
"different_pixels": 0
}
],
"natural_fire_hits": [
{
"hit": 1,
"hearts": [
"full",
"full",
"half"
]
},
{
"hit": 2,
"hearts": [
"full",
"full",
"empty"
]
},
{
"hit": 3,
"hearts": [
"full",
"half",
"empty"
]
},
{
"hit": 4,
"hearts": [
"full",
"empty",
"empty"
]
},
{
"hit": 5,
"hearts": [
"half",
"empty",
"empty"
]
},
{
"hit": 6,
"hearts": [
"empty",
"empty",
"empty"
]
}
],
"natural_death_continue": true,
"healthy_inventory_regression_frames": 28,
"scope": "Fixture checks and full frames; real cave fire contacts and Start continue. Other heart/fairy world drops and full NES death fade/menu are outside this wave."
}
+144
View File
@@ -0,0 +1,144 @@
{
"fixtureBuildId": "fbb4326d-3fc3-4a66-ae94-9f3e24d0ead1",
"productionBuildId": "20a0f966-639d-4d25-a908-eaf2dc1e4c6c",
"productionEntrypointRestored": true,
"naturalPlaySequence": [
[
"initial",
1,
{}
],
[
"left",
40,
{
"left": true
}
],
[
"up",
43,
{
"up": true
}
],
[
"cave",
96,
{}
],
[
"align_fire",
29,
{
"left": true
}
],
[
"near_fire",
26,
{
"up": true
}
],
[
"touch_fire",
1,
{
"up": true
}
],
[
"hit_wait",
10,
{}
],
[
"first_fire_damage",
1,
{
"up": true
}
],
[
"immunity_wait",
60,
{}
],
[
"fire_hit_2",
30,
{
"up": true
}
],
[
"recover_2",
60,
{}
],
[
"fire_hit_3",
30,
{
"up": true
}
],
[
"recover_3",
60,
{}
],
[
"fire_hit_4",
30,
{
"up": true
}
],
[
"recover_4",
60,
{}
],
[
"fire_hit_5",
30,
{
"up": true
}
],
[
"recover_5",
60,
{}
],
[
"fire_hit_6",
30,
{
"up": true
}
],
[
"recover_6",
60,
{}
],
[
"game_over",
300,
{}
],
[
"continue",
1,
{
"start": true
}
]
],
"healthyRegressionSource": "extracted/inventory/validation/sequence.json",
"finalProductionBuildId": "804a9149-6fe1-40da-87fd-f54f34c211fd",
"finalInitialFrameMatchesBaseline": true
}