diff --git a/src/dotnes.tasks/Utilities/NESWriter.cs b/src/dotnes.tasks/Utilities/NESWriter.cs index 9257182..3a1c0bf 100644 --- a/src/dotnes.tasks/Utilities/NESWriter.cs +++ b/src/dotnes.tasks/Utilities/NESWriter.cs @@ -439,12 +439,12 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.pal_col): /* * 823E 8517 STA TEMP ; _pal_col - * 8240 209285 JSR popa - * 8243 291F AND #$1F - * 8245 AA TAX - * 8246 A517 LDA TEMP - * 8248 9DC001 STA $01C0,x - * 824B E607 INC PAL_UPDATE + * 8240 209285 JSR popa + * 8243 291F AND #$1F + * 8245 AA TAX + * 8246 A517 LDA TEMP + * 8248 9DC001 STA $01C0,x + * 824B E607 INC PAL_UPDATE * 824D 60 RTS */ Write(NESInstruction.STA_zpg, TEMP); @@ -483,8 +483,10 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 8261 850A STA PAL_SPR_PTR * 8263 BD2B84 LDA palBrightTableH,x * 8266 850B STA PAL_SPR_PTR+1 - * 8268 8507 STA PAL_UPDATE - * 826A 60 RTS + * 825E BD2284 LDA palBrightTableL,x + * 8261 850A STA PAL_SPR_PTR + * 8263 BD2B84 LDA palBrightTableH,x + * 8266 850B STA PAL_SPR_PTR+1 */ Write(NESInstruction.TAX_impl); Write(NESInstruction.LDA_abs_X, palBrightTableL); @@ -498,10 +500,11 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) /* * 826B AA TAX ; _pal_bg_bright * 826C BD2284 LDA palBrightTableL,x - * 826F 8508 STA PAL_BG_PTR - * 8271 BD2B84 LDA palBrightTableH,x - * 8274 8509 STA PAL_BG_PTR+1 - * 8276 8507 STA PAL_UPDATE + * 826C BD2284 LDA palBrightTableL,x + * 826F 8508 STA PAL_BG_PTR + * 8271 BD2B84 LDA palBrightTableH,x + * 8274 8509 STA PAL_BG_PTR+1 + * 8276 8507 STA PAL_UPDATE * 8278 60 RTS */ Write(NESInstruction.TAX_impl); @@ -546,7 +549,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) //TODO: not sure if we should emit ppu_onoff at the same place /* * 828D 8512 STA PPU_MASK_VAR ; ppu_onoff - * 828F 4CF082 JMP _ppu_wait_nmi + * 828F 4CF082 JMP _ppu_wait_nmi */ Write(NESInstruction.STA_zpg, 0x12); Write(NESInstruction.JMP_abs, ppu_wait_nmi); @@ -554,7 +557,6 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.ppu_on_bg): /* * 8292 A512 LDA PPU_MASK_VAR ; _ppu_on_bg - * 8294 0908 ORA #$08 * 8296 D0F5 BNE ppu_onoff */ Write(NESInstruction.LDA_zpg, PPU_MASK_VAR); @@ -582,7 +584,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.ppu_system): /* * 82A1 A500 LDA __ZP_START__ ; _ppu_system - * 82A3 A200 LDX #$00 + * 82A3 A200 LDX #$00 * 82A5 60 RTS */ Write(NESInstruction.LDA_zpg, ZP_START); @@ -610,13 +612,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.oam_clear): /* * 82AE A200 LDX #$00 ; _oam_clear - * 82B0 A9FF LDA #$FF - * 82B2 9D0002 STA $0200,x - * 82B5 E8 INX - * 82B6 E8 INX - * 82B7 E8 INX - * 82B8 E8 INX - * 82B9 D0F7 BNE $82B2 + * 82B0 A9FF LDA #$FF * 82BB 60 RTS */ Write(NESInstruction.LDX, 0x00); @@ -632,16 +628,14 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.oam_size): /* * 82BC 0A ASL ; _oam_size - * 82BD 0A ASL - * 82BE 0A ASL - * 82BF 0A ASL - * 82C0 0A ASL * 82C1 2920 AND #$20 * 82C3 8517 STA TEMP * 82C5 A510 LDA __PRG_FILEOFFS__ * 82C7 29DF AND #$DF * 82C9 0517 ORA TEMP * 82CB 8510 STA __PRG_FILEOFFS__ + * 82BE 0A ASL + * 82BF 0A ASL * 82CD 60 RTS */ Write(NESInstruction.ASL_A); @@ -666,7 +660,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 82D5 E8 INX * 82D6 E8 INX * 82D7 E8 INX - * 82D8 D0F7 BNE $82D1 + * 82CF A9F0 LDA #$F0 * 82DA 60 RTS */ Write(NESInstruction.TAX_impl); @@ -685,12 +679,10 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 82DD 8503 STA VRAM_UPDATE * 82DF A501 LDA __STARTUP__ * 82E1 C501 CMP __STARTUP__ - * 82E3 F0FC BEQ $82E1 - * 82E5 A500 LDA __ZP_START__ - * 82E7 F006 BEQ @3 - * 82E9 A502 LDA NES_PRG_BANKS * 82EB C905 CMP #$05 * 82ED F0FA BEQ $82E9 + * 82E7 F006 BEQ @3 + * 82E9 A502 LDA NES_PRG_BANKS * 82EF 60 RTS ; @3 */ Write(NESInstruction.LDA, 0x01); @@ -712,6 +704,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 82F4 A501 LDA __STARTUP__ * 82F6 C501 CMP __STARTUP__ * 82F8 F0FC BEQ $82F6 + * 82F8 F0FC BEQ $82F6 * 82FA 60 RTS */ Write(NESInstruction.LDA, 0x01); @@ -725,20 +718,6 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) /* * 82FB 8517 STA TEMP ; _scroll * 82FD 8A TXA - * 82FE D00E BNE $830E - * 8300 A517 LDA TEMP - * 8302 C9F0 CMP #$F0 - * 8304 B008 BCS $830E - * 8306 850D STA SCROLL_Y - * 8308 A900 LDA #$00 - * 830A 8517 STA TEMP - * 830C F00B BEQ $8319 - * 830E 38 SEC - * 830F A517 LDA TEMP - * 8311 E9F0 SBC #$F0 - * 8313 850D STA SCROLL_Y - * 8315 A902 LDA #$02 - * 8317 8517 STA TEMP * 8319 207F85 JSR popax * 831C 850C STA SCROLL_X * 831E 8A TXA @@ -746,9 +725,24 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 8321 0517 ORA TEMP * 8323 8517 STA TEMP * 8325 A510 LDA __PRG_FILEOFFS__ - * 8327 29FC AND #$FC - * 8329 0517 ORA TEMP - * 832B 8510 STA __PRG_FILEOFFS__ + * 82FD 8A TXA + * 82FE D00E BNE $830E + * 8300 A517 LDA TEMP + * 8302 C9F0 CMP #$F0 + * 8304 B008 BCS $830E + * 8306 850D STA SCROLL_Y + * 8308 A900 LDA #$00 + * 830A 8517 STA TEMP + * 830C F00B BEQ $8319 + * 830E 38 SEC + * 830F A517 LDA TEMP + * 8311 E9F0 SBC #$F0 + * 8313 850D STA SCROLL_Y + * 8315 A902 LDA #$02 + * 8317 8517 STA TEMP + * 8319 207F85 JSR popax + * 831C 850C STA SCROLL_X + * 832B 8510 STA __PRG_FILEOFFS__ * 832D 60 RTS */ Write(NESInstruction.STA_zpg, TEMP); @@ -782,14 +776,11 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.bank_spr): /* * 832E 2901 AND #$01 ; _bank_spr - * 8330 0A ASL - * 8331 0A ASL - * 8332 0A ASL - * 8333 8517 STA TEMP - * 8335 A510 LDA __PRG_FILEOFFS__ - * 8337 29F7 AND #$F7 * 8339 0517 ORA TEMP * 833B 8510 STA __PRG_FILEOFFS__ + * 8337 29F7 AND #$F7 + * 8339 0517 ORA TEMP + * 833B 8510 STA __PRG_FILEOFFS__ * 833D 60 RTS */ Write(NESInstruction.AND, 0x01); @@ -806,15 +797,10 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.bank_bg): /* * 833E 2901 AND #$01 ; _bank_bg - * 8340 0A ASL - * 8341 0A ASL - * 8342 0A ASL - * 8343 0A ASL - * 8344 8517 STA TEMP - * 8346 A510 LDA __PRG_FILEOFFS__ - * 8348 29EF AND #$EF - * 834A 0517 ORA TEMP * 834C 8510 STA __PRG_FILEOFFS__ + * 8348 29EF AND #$EF + * 834A 0517 ORA TEMP + * 834C 8510 STA __PRG_FILEOFFS__ * 834E 60 RTS */ Write(NESInstruction.AND, 0x01); @@ -837,18 +823,23 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 8356 8519 STA $19 * 8358 861A STX $1A * 835A A000 LDY #$00 - * 835C B119 LDA ($19),y - * 835E 8D0720 STA $2007 - * 8361 E619 INC $19 - * 8363 D002 BNE $8367 - * 8365 E61A INC $1A - * 8367 A517 LDA TEMP - * 8369 D002 BNE $836D - * 836B C618 DEC TEMP+1 - * 836D C617 DEC TEMP - * 836F A517 LDA TEMP - * 8371 0518 ORA TEMP+1 - * 8373 D0E7 BNE $835C + * 8351 8618 STX TEMP+1 + * 8353 203A85 JSR popax + * 8356 8519 STA $19 + * 8358 861A STX $1A + * 835A A000 LDY #$00 + * 835C B119 LDA ($19),y + * 835E 8D0720 STA $2007 + * 8361 E619 INC $19 + * 8363 D002 BNE $8367 + * 8365 E61A INC $1A + * 8367 A517 LDA TEMP + * 8369 D002 BNE $836D + * 836B C618 DEC TEMP+1 + * 836D C617 DEC TEMP + * 836F A517 LDA TEMP + * 8371 0518 ORA TEMP+1 + * 8373 D0E7 BNE $835C * 8375 60 RTS */ Write(NESInstruction.STA_zpg, TEMP); @@ -874,9 +865,9 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.set_vram_update): /* * 8376 8504 STA NAME_UPD_ADR ; _set_vram_update - * 8378 8605 STX NAME_UPD_ADR+1 - * 837A 0505 ORA NAME_UPD_ADR+1 - * 837C 8506 STA NAME_UPD_ENABLE + * 8378 8605 STX NAME_UPD_ADR+1 + * 837A 0505 ORA NAME_UPD_ADR+1 + * 837C 8506 STA NAME_UPD_ENABLE * 837E 60 RTS */ Write(NESInstruction.STA_zpg, NAME_UPD_ADR); @@ -888,7 +879,6 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.flush_vram_update): /* * 837F 8504 STA NAME_UPD_ADR ; _flush_vram_update - * 8381 8605 STX NAME_UPD_ADR+1 * 8383 A000 LDY #$00 ; _flush_vram_update_nmi */ Write(NESInstruction.STA_zpg, NAME_UPD_ADR); @@ -905,9 +895,17 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 8391 C8 INY * 8392 8D0620 STA $2006 * 8395 B104 LDA (NAME_UPD_ADR),y - * 8397 C8 INY - * 8398 8D0720 STA $2007 - * 839B 4C8583 JMP @updName + * 8387 C8 INY + * 8388 C940 CMP #$40 + * 838A B012 BCS @updNotSeq + * 838C 8D0620 STA $2006 + * 838F B104 LDA (NAME_UPD_ADR),y + * 8391 C8 INY + * 8392 8D0620 STA $2006 + * 8395 B104 LDA (NAME_UPD_ADR),y + * 8397 C8 INY + * 8398 8D0720 STA $2007 + * 839B 4C8583 JMP @updName */ Write(NESInstruction.LDA_ind_Y, NAME_UPD_ADR); Write(NESInstruction.INY_impl); @@ -926,9 +924,11 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 839E AA TAX ; @updNotSeq * 839F A510 LDA __PRG_FILEOFFS__ * 83A1 E080 CPX #$80 - * 83A3 9008 BCC @updHorzSeq - * 83A5 E0FF CPX #$FF - * 83A7 F02A BEQ @updDone + * 839F A510 LDA __PRG_FILEOFFS__ + * 83A1 E080 CPX #$80 + * 83A3 9008 BCC @updHorzSeq + * 83A5 E0FF CPX #$FF + * 83A7 F02A BEQ @updDone */ Write(NESInstruction.TAX_impl); Write(NESInstruction.LDA_zpg, PRG_FILEOFFS); @@ -939,7 +939,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) /* * 83A9 0904 ORA #$04 ; @updVertSeq - * 83AB D002 BNE @updNameSeq + * 83AB D002 BNE @updNameSeq * 83AD 29FB AND #$FB ; @updHorzSeq * 83AF 8D0020 STA $2000 ; @updNameSeq * 83B2 8A TXA @@ -948,9 +948,15 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 83B8 B104 LDA (NAME_UPD_ADR),y * 83BA C8 INY * 83BB 8D0620 STA $2006 - * 83BE B104 LDA (NAME_UPD_ADR),y - * 83C0 C8 INY - * 83C1 AA TAX + * 83B2 8A TXA + * 83B3 293F AND #$3F + * 83B5 8D0620 STA $2006 + * 83B8 B104 LDA (NAME_UPD_ADR),y + * 83BA C8 INY + * 83BB 8D0620 STA $2006 + * 83BE B104 LDA (NAME_UPD_ADR),y + * 83C0 C8 INY + * 83C1 AA TAX */ Write(NESInstruction.ORA, 0x04); Write(NESInstruction.BNE_rel, 0x02); @@ -968,13 +974,13 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) /* * 83C2 B104 LDA (NAME_UPD_ADR),y ; @updNameLoop - * 83C4 C8 INY - * 83C5 8D0720 STA $2007 - * 83C8 CA DEX - * 83C9 D0F7 BNE @updNameLoop - * 83CB A510 LDA __PRG_FILEOFFS__ - * 83CD 8D0020 STA $2000 - * 83D0 4C8583 JMP @updName + * 83C4 C8 INY + * 83C5 8D0720 STA $2007 + * 83C8 CA DEX + * 83C9 D0F7 BNE @updNameLoop + * 83CB A510 LDA __PRG_FILEOFFS__ + * 83CD 8D0020 STA $2000 + * 83D0 4C8583 JMP @updName * 83D3 60 RTS ; @updDone */ Write(NESInstruction.LDA_ind_Y, NAME_UPD_ADR); @@ -1000,7 +1006,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.vram_put): /* * 83DB 8D0720 STA $2007 ; _vram_put - * 83DE 60 RTS + * 83DE 60 RTS */ Write(NESInstruction.STA_abs, PPU_DATA); Write(NESInstruction.RTS_impl); @@ -1010,8 +1016,6 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 83DF 8519 STA $19 ; _vram_fill * 83E1 861A STX $1A * 83E3 209585 JSR popa - * 83E6 A61A LDX $1A - * 83E8 F00C BEQ $83F6 * 83EA A200 LDX #$00 * 83EC 8D0720 STA $2007 * 83EF CA DEX @@ -1019,10 +1023,21 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 83F2 C61A DEC $1A * 83F4 D0F6 BNE $83EC * 83F6 A619 LDX $19 - * 83F8 F006 BEQ @4 - * 83FA 8D0720 STA $2007 - * 83FD CA DEX - * 83FE D0FA BNE $83FA + * 83E1 861A STX $1A + * 83E3 209585 JSR popa + * 83E6 A61A LDX $1A + * 83E8 F00C BEQ $83F6 + * 83EA A200 LDX #$00 + * 83EC 8D0720 STA $2007 + * 83EF CA DEX + * 83F0 D0FA BNE $83EC + * 83F2 C61A DEC $1A + * 83F4 D0F6 BNE $83EC + * 83F6 A619 LDX $19 + * 83F8 F006 BEQ @4 + * 83FA 8D0720 STA $2007 + * 83FD CA DEX + * 83FE D0FA BNE $83FA * 8400 60 RTS ; @4 */ Write(NESInstruction.STA_zpg, 0x19); @@ -1049,12 +1064,10 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) * 8403 F002 BEQ $8407 * 8405 A904 LDA #$04 * 8407 8517 STA TEMP - * 8409 A510 LDA __PRG_FILEOFFS__ - * 840B 29FB AND #$FB - * 840D 0517 ORA TEMP - * 840F 8510 STA __PRG_FILEOFFS__ - * 8411 8D0020 STA $2000 - * 8414 60 RTS + * 8403 F002 BEQ $8407 + * 8405 A904 LDA #$04 + * 8407 8517 STA TEMP + * 8409 A510 LDA __PRG_FILEOFFS__ */ Write(NESInstruction.ORA, 0x00); Write(NESInstruction.BEQ_rel, 0x02); @@ -1070,7 +1083,7 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.nesclock): /* * 8415 A501 LDA __STARTUP__ ; _nesclock - * 8417 A200 LDX #$00 + * 8417 A200 LDX #$00 * 8419 60 RTS */ Write(NESInstruction.LDA_zpg, STARTUP); @@ -1080,9 +1093,9 @@ public void WriteBuiltIn(string name, ushort sizeOfMain) case nameof(NESLib.delay): /* * 841A AA TAX ; _delay - * 841B 20F082 JSR _ppu_wait_nmi - * 841E CA DEX - * 841F D0FA BNE _delay+1 + * 841B 20F082 JSR _ppu_wait_nmi + * 841E CA DEX + * 841F D0FA BNE _delay+1 * 8421 60 RTS */ Write(NESInstruction.TAX_impl); @@ -1266,12 +1279,11 @@ void Write_clearRAM(ushort sizeOfMain) * sta $700,x * inx * bne @1 - * + * * lda #4 * jsr _pal_bright * jsr _pal_clear * jsr _oam_clear - * * jsr zerobss * jsr copydata * @@ -1397,7 +1409,7 @@ void Write_doUpdate() * https://github.com/clbr/neslib/blob/d061b0f7f1a449941111c31eee0fc2e85b1826d7/neslib.sinc#L40 * lda #>OAM_BUF ;update OAM * sta PPU_OAM_DMA - * + * * lda