Show
Ignore:
Timestamp:
08/03/09 04:24:45 (3 years ago)
Author:
brandonlw
Message:

Some code to actually write the received TI-OS to Flash
It (almost) works, as far as I can tell

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/page1C/silentlink.asm

    r33 r34  
    88 EXTERN JErrorNo,NZIf83Plus,CheckLinkLines,EnableLinkAssist,DisableLinkAssist,ContinueGetByte,Get3Bytes 
    99 EXTERN DispHexA,LdHLInd,SendAcknowledge,ReceiveHeaderPacket,SendSkipExitPacket,Get4BytesNC,SendCommandA 
    10  EXTERN Send4Bytes,SendCAndAddToChecksum,LCDDelay,_LCD_COMMAND,SendAByte,SetXAutoIncrementMode 
    11  EXTERN SetYAutoIncrementMode,SendContinue,ReceiveDataPacket,DispHexHL 
     10 EXTERN Send4Bytes,SendCAndAddToChecksum,LCDDelay,_LCD_COMMAND,SendAByte,SetXAutoIncrementMode,EraseRAMPage 
     11 EXTERN SetYAutoIncrementMode,SendContinue,ReceiveDataPacket,DispHexHL,PutC,receiveRestOfDataPacket 
     12 EXTERN CopyToRAMPage,CopyRAMToFlashPage,EraseEOL,PowerOff 
    1213 
    1314keyscnlnk: 
     
    9798       DB 6Dh 
    9899       DW screenshotPacket 
     100       DB 15h                             ;this is garbage 
     101       DW keyscnlnkEnd 
    99102cmdTableEnd: 
    100103 
     
    167170       bit receiveTIOS,(iy+linkFlags2) 
    168171       jr z,ReceiveNewOS 
     172       ;Wipe the extra RAM pages 
     173       ld a,84h 
     174       call EraseRAMPage 
     175       ld a,85h 
     176       call EraseRAMPage 
     177       ld a,86h 
     178       call EraseRAMPage 
     179       ld a,87h 
     180       call EraseRAMPage 
     181;Receive a copy of the TI-OS to the spare Flash sectors 
     182       ld a,0FFh 
     183       ld (appSearchPage),a 
     184;Back up pages 68h and 69h to RAM pages 04h and 05h 
     185       in a,(modelPort) 
     186       and 3 
     187       ld a,68h 
     188       jr nz,$F 
     189       ld a,38h 
     190$$:    ld b,04h 
     191       push af 
     192       push bc 
     193       call CopyToRAMPage 
     194       pop bc 
     195       pop af 
     196       push af 
     197       inc a 
     198       inc b 
     199       call CopyToRAMPage 
     200       pop af 
     201       push af 
     202;Erase sector 68h 
     203       B_CALL EraseFlashPage 
     204       pop bc 
     205;Copy from RAM pages 04h and 05h back to pages 68h and 69h 
     206       ld a,04h 
     207       push af 
     208       push bc 
     209       call CopyRAMToFlashPage 
     210       pop bc 
     211       pop af 
     212       inc a 
     213       inc b 
     214       call CopyRAMToFlashPage 
    169215       ld hl,receiveTIOSHandler 
    170216       call APP_PUSH_ERRORH 
    171 ;TODO: actually implement all of this 
    172217ReceiveOSPage: 
    173218       ld hl,(curRow) 
     
    179224       ld hl,(ioData+6) 
    180225       call DispHexHL 
     226       call EraseEOL 
    181227       pop hl 
    182228       ld (curRow),hl 
     229       ld a,(ioData+8) 
     230       ld hl,(ioData+6) 
     231       ld b,a 
     232       cp 08h 
     233       jr c,$F 
     234       in a,(statusPort) 
     235       and STATUS_NON_83P_MASK 
     236       ld a,b 
     237       jr z,$F 
     238       in a,(modelPort) 
     239       and 3 
     240       ld a,b 
     241       jr z,is84P 
     242       or 60h 
     243       jr $F 
     244is84P: or 30h 
     245$$:    ;Maybe erase this sector (only if it's 04h, 74h, 78h) 
     246       push af 
     247       push hl 
     248       ld b,a 
     249       ld a,(appSearchPage) 
     250       cp b 
     251       jr z,noSectorErase 
     252       ld a,b 
     253       ld (appSearchPage),a 
     254       cp 04h 
     255       jr z,$F 
     256       cp 34h 
     257       jr z,$F 
     258       cp 74h 
     259       jr z,$F 
     260       cp 18h 
     261       jr z,$F 
     262       cp 38h 
     263       jr z,$F 
     264       cp 78h 
     265       jr z,$F 
     266       jr noSectorErase 
     267$$:    B_CALL EraseFlashPage 
     268noSectorErase: 
    183269       call SendContinue 
    184270       ld bc,(ioData) 
     271       ld de,appData 
     272       push bc 
     273       push de 
     274       call ReceiveDataPacket 
     275       pop de 
     276       pop bc 
     277       pop de 
     278       pop af 
     279       ;Write BC bytes from appData to ADE 
     280       push bc 
     281       cp 04h 
     282       jr nc,$F 
     283       ;This is part of sector 0, translate it to the extra RAM pages and write it 
     284       ld hl,6 
     285       ld (curRow),hl 
     286       push af 
     287       ld a,5 
     288       call PutC 
     289       pop af 
     290       pop bc 
     291       ld hl,8000h 
     292       add hl,de 
     293       ex de,hl 
    185294       ld hl,appData 
    186        ld (iMathPtr5),hl 
    187        call ReceiveDataPacket 
     295       di 
     296       out (5),a 
     297       ldir 
     298       xor a 
     299       out (5),a 
     300       jr dataWritten 
     301$$:    ;Is this page 7Ch or 7Dh? If so, change it to 6Ah or 6Bh 
     302       push af 
     303       ld a,6 
     304       call PutC 
     305       pop af 
     306       cp 7Ch 
     307       ld b,6Ah 
     308       jr z,translatePage 
     309       cp 3Ch 
     310       ld b,3Ah 
     311       jr z,translatePage 
     312       cp 7Dh 
     313       ld b,6Bh 
     314       jr z,translatePage 
     315       cp 3Dh 
     316       ld b,3Bh 
     317       jr z,translatePage 
     318$$:    ;Just write it 
     319       pop bc 
     320       ld hl,appData 
     321       B_CALL WriteFlash 
     322       jr dataWritten 
     323translatePage: 
     324       ld a,b 
     325       jr $B 
     326dataWritten: 
    188327       call Get4BytesNC 
    189328       ld a,(header+1) 
     
    193332       jr ReceiveOSPage 
    194333$$:    call SendAcknowledge 
    195 ;Receive a copy of the TI-OS to the spare Flash sectors 
    196334;Patch the received TI-OS to not erase sector 70h (where we will be backed up) 
    197335;Put the [X,T,theta,N] boot loader in page 0 
    198336       call APP_POP_ERRORH 
     337       ;Seems like the most sensible thing to do after receiving the TI-OS is just shut off 
     338       call PowerOff 
    199339receiveTIOSHandler: 
    200340       jr keyscnlnkEnd