; NOTE: I probably won't have to modify the SRAM loader; it seemingly ; just transfers all the junk in the SRAM to the WRAM. It's the saving ; and access code I'll be concerned with. ;SRAM Loader ;=========== ;When this block is first called, A is set to 1D9. A is ;transferred to Y, which is then used as the loop counter. ;So I guess this goes through a loop $1D9 times to load SRAM? ;Hm... Not quite. The SRAM data is quite a bit more than 1D9 ;bytes. ;Okay, hold on! The loop _decrements_ Y. When A is set to 1D9, ;this reads everything from 1F8 backwards to 20. (I think it ;starts at 20 to skip that signature and whatnot: The current ;position of SRAM data ($6020) is stored at $00:1E7A. ;Another value tracks the current position in the WRAM. ;A is set to 1D9, and data from cur+1D9 (61F9) to cur(6020) is ;read. This is the first block of SRAM data, just before character ;data starts. ;Then, the current position is incremented by the value put ;into the accumulator before the loader subroutine call (1D9). ;(Same with WRAM tracker) ;The WRAM and SRAM trackers are shuffled around some other values ;between each read, I think, but the current WRAM position winds ;up at address DP+$0E, and the SRAM position winds up at DP+$12 ;(See code below) In other (and better) words, there is a counter for the current positions in both SRAM and WRAM. Near the beginning of the routine that makes several calls to the below routine, these are set to $6020 (SRAM) and $97F5 (WRAM). These values are stored to, loaded from, and repetitively stored to a number of places in the same area, in a seemingly redundant and confusing manner. The upshot, however, is that before each call to the routine below, the current SRAM position is at $1E74+12, and the WRAM position at $1E74+0E. (This is because DP is 1E74 when this is called, and does not seem to change) Before each call, A is loaded with the number of bytes to read from SRAM. The routine reads the bytes in reverse, from curpos+count to curpos. After the call, A is again loaded with the number of bytes read. The current position counters are then incremented by this amount, shuffled around confusingly again before settling into their accustomed locations, and the call is repeated with a new number of bytes. Bytes are read in this fashion: Read 1: 0020-01F8 (SRM relative, inclusive) This is the first chunk, containing basic information about the save Read 2: 01F9-0432 Character data. Read 3: 0433-04B3 Event flags. There must be some reason the data is read in chunks; and some meaning to those weird shuffles between each load. Ah well, I do not think it concerns me at present. 00/8000: A8 TAY ; transfer a to y 00/8001: E2 20 SEP #$20 ; Make accumulator 8-bit (this reads one byte at a time from SRAM) 00/8003: 80 04 BRA $8009 ; Branch always to --> 00/8005: B7 12 LDA [$12],Y ; This apparently reads the byte from SRAM... 00/8007: 97 0E STA [$0E],Y ; ...and stores it to WRAM 00/8009: 88 DEY ; <-- Decrement y. This is the loop counter. 00/800A: 10 F9 BPL $8005 ; If negative flag clear, go to 8005 (above) (Only read byte while Y > 0) ; If Y has hit zero... 00/800C: C2 30 REP #$30 ; Make accumulator and registers 16-bit 00/800E: 6B RTL ; Return to caller ;Notes: ; These two instructions... 00/8005: B7 12 LDA [$12],Y ; This apparently reads the byte from SRAM... 00/8007: 97 0E STA [$0E],Y ; ...and stores it to WRAM ;I wonder; both use exactly the same syntax: how then ;does the first read from $30:XXXX and the second from ;$7E:XXXX? ; This stuff is apparently other routines 00/800F: 9B TXY ; Move X to Y 00/8010: AA TAX ; Move A to X 00/8011: 98 TYA 00/8012: 4A LSR 00/8013: A8 TAY 00/8014: E2 20 SEP #$20 00/8016: A5 0E LDA $0E 00/8018: EB XBA 00/8019: A5 0E LDA $0E 00/801B: C2 20 REP #$20 00/801D: 80 05 BRA $8024 00/801F: 9D 00 00 STA $0000,X 00/8022: E8 INX 00/8023: E8 INX 00/8024: 88 DEY 00/8025: 10 F8 BPL $801F 00/8027: 6B RTL 00/8028: E2 20 SEP #$20 00/802A: 9B TXY 00/802B: 88 DEY 00/802C: 30 04 BMI $8032 00/802E: 97 0E STA [$0E],Y 00/8030: 80 F9 BRA $802B 00/8032: C2 30 REP #$30 00/8034: 6B RTL 00/8035: E2 30 SEP #$30 00/8037: A0 FF LDY #$FF 00/8039: C8 INY 00/803A: B7 0E LDA [$0E],Y 00/803C: D0 FB BNE $8039 00/803E: C2 30 REP #$30 00/8040: 98 TYA 00/8041: 6B RTL 00/8042: E2 20 SEP #$20 00/8044: A0 FF LDY #$FF 00/8046: FF C8 B7 0E SBC $0EB7C8,X 00/804A: F0 06 BEQ $8052 00/804C: D7 12 CMP [$12],Y 00/804E: F0 F7 BEQ $8047 00/8050: A9 01 LDA #$01 00/8052: C2 30 REP #$30 00/8054: 6B RTL 00/8055: C2 30 REP #$30 00/8057: A8 TAY 00/8058: 8B PHB 00/8059: F4 00 00 PEA $0000 00/805C: AB PLB 00/805D: AB PLB 00/805E: A3 01 LDA $01,S 00/8060: 99 00 00 STA $0000,Y 00/8063: A3 03 LDA $03,S 00/8065: 99 02 00 STA $0002,Y 00/8068: 08 PHP 00/8069: 08 PHP 00/806A: 68 PLA 00/806B: 99 04 00 STA $0004,Y 00/806E: 7B TDC 00/806F: 99 05 00 STA $0005,Y 00/8072: 3B TSC 00/8073: 99 07 00 STA $0007,Y 00/8076: AB PLB 00/8077: A9 00 LDA #$00 00/8079: 00 6B BRK $6B 00/807B: C2 30 REP #$30 00/807D: A8 TAY 00/807E: F4 00 00 PEA $0000 00/8081: AB PLB 00/8082: AB PLB 00/8083: B9 07 00 LDA $0007,Y 00/8086: 1B TCS 00/8087: B9 05 00 LDA $0005,Y 00/808A: 5B TCD 00/808B: B9 03 00 LDA $0003,Y 00/808E: 48 PHA 00/808F: 28 PLP 00/8090: 28 PLP 00/8091: B9 00 00 LDA $0000,Y 00/8094: 83 01 STA $01,S 00/8096: B9 02 00 LDA $0002,Y 00/8099: 83 03 STA $03,S 00/809B: AB PLB 00/809C: 8A TXA 00/809D: 6B RTL 00/809E: E2 20 SEP #$20 00/80A0: AD 00 00 LDA $0000 00/80A3: CD 01 00 CMP $0001 00/80A6: D0 FB BNE $80A3 00/80A8: C2 30 REP #$30 00/80AA: 6B RTL 00/80AB: 80 FE BRA $80AB 00/80AD: 00 01 BRK $01 00/80AF: 00 02 BRK $02 00/80B1: 00 00 BRK $00