Changeset 34

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

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/includes/os2.inc

    r31 r34  
    3636;====================================================================== 
    3737_WriteAByte                 EQU 8021h 
     38_FlashToRam2                EQU 8054h 
    3839_ReceiveOS                  EQU 8072h 
     40_EraseFlashPage             EQU 8084h 
    3941_DispBootVer                EQU 808Ah 
    4042_MD5Init                    EQU 808Dh 
     
    5355; 
    5456appSearchPage               EQU    82A3h 
     57; 
     58tempSwapArea                EQU    82A5h 
    5559; 
    5660Abackup                     EQU    83EBh 
  • trunk/page00/boot.asm

    r32 r34  
    554554       jr TurnCalculatorOn 
    555555SwitchOS: 
    556        call IsOS2Running 
    557        jr z,SwitchToTIOS 
    558 ;Switch back to OS2 
     556       ;Copy a loader to RAM which does the following: 
     557       ;      Back up sector 0 to the extra RAM pages 
     558       ;      Copy sector 70h to sector 0 
     559       ;      Erase sector 70h 
     560       ;      Write our backup from the extra RAM pages to sector 70h 
     561       ;      Copy pages 68h and 69h to the extra RAM pages 
     562       ;      Copy pages 7Ch and 7Dh to the extra RAM pages 
     563       ;      Erase sector 7Ch 
     564       ;      Copy pages 6Ah and 6Bh to 7Ch and 7Dh 
     565       ;      Erase sector 68h 
     566       ;      Copy from the extra RAM pages to pages 68h-6Bh 
     567       ;Restart. 
     568       ;NOTE: this loader of the loader needs to execute as if it were either from here or page 70h. 
     569       ;TODO: Uh...not yet! 
    559570       call ClrLCDFull 
    560571       jr TurnCalculatorOn 
     
    590601       DB "enable dual     " 
    591602       DB "booting.",0 
    592 SwitchToTIOS: 
    593        ;TODO: Uh...not yet! 
    594        call ClrLCDFull 
    595        jr TurnCalculatorOn 
    596603 
  • trunk/page00/util.asm

    r30 r34  
    44 PUBLIC _APP_PUSH_ERRORH,_APP_POP_ERRORH,FindSym,PushRealO1,Mov9ToOP1,FPAdd,OP1ToOP2,LCDDelay 
    55 PUBLIC Placeholder005Fh,Placeholder0006h,Placeholder004Eh,Placeholder0003h,Placeholder0035h 
    6  PUBLIC outputPage,NZIf83Plus,ZIfSlowSpeed,GetBytePaged,MakeOffPageCall 
    7  PUBLIC BCALL,BJUMP,JErrorNo,SetupPagedPtr,PagedGet 
     6 PUBLIC outputPage,NZIf83Plus,ZIfSlowSpeed,GetBytePaged,MakeOffPageCall,CopyFlashPage,CopyToRAMPage 
     7 PUBLIC CopyRAMToFlashPage 
     8 PUBLIC BCALL,BJUMP,JErrorNo,SetupPagedPtr,PagedGet,EraseRAMPage 
    89 EXTERN Page0Call,UpdateAPD,PowerOff,GetCSC 
    910 
     
    2021Placeholder004Eh: 
    2122Placeholder005Fh: 
     23       ret 
     24 
     25CopyToRAMPage: 
     26       di 
     27       out (7),a 
     28       ld a,b 
     29       out (5),a 
     30       ld hl,8000h 
     31       ld de,0C000h 
     32       ld bc,4000h 
     33       ldir 
     34       ld a,81h 
     35       out (7),a 
     36       xor a 
     37       out (5),a 
     38       ret 
     39 
     40CopyFlashPage: 
     41       ld hl,4000h 
     42$$:    push af 
     43       push bc 
     44       ld de,tempSwapArea 
     45       ld bc,128 
     46       push hl 
     47       B_CALL FlashToRam2 
     48       pop de 
     49       pop af 
     50       push af 
     51       ld hl,tempSwapArea 
     52       ld bc,128 
     53       push de 
     54       B_CALL WriteFlash 
     55       pop hl 
     56       ld bc,128 
     57       add hl,bc 
     58       pop bc 
     59       pop af 
     60       bit 7,h 
     61       jr z,$B 
     62       ret 
     63 
     64CopyRAMToFlashPage: 
     65       di 
     66       ld hl,4000h 
     67$$:    push af 
     68       push bc 
     69       push hl 
     70       ;Copy from extra RAM page A to Flash page B 
     71       out (5),a 
     72       ld de,8000h 
     73       add hl,de 
     74       ld de,tempSwapArea 
     75       ld bc,128 
     76       ldir 
     77       xor a 
     78       out (5),a 
     79       pop de 
     80       pop af 
     81       push af 
     82       ld hl,tempSwapArea 
     83       ld bc,128 
     84       push de 
     85       B_CALL WriteFlash 
     86       pop hl 
     87       ld bc,128 
     88       add hl,bc 
     89       pop bc 
     90       pop af 
     91       bit 7,h 
     92       jr z,$B 
     93       ret 
     94 
     95EraseRAMPage: 
     96       di 
     97       out (7),a 
     98       ld hl,8000h 
     99       ld (hl),0 
     100       ld de,8001h 
     101       ld bc,4000h-1 
     102       ldir 
     103       ld a,81h 
     104       out (7),a 
    22105       ret 
    23106 
  • trunk/page1C/linkprotocol.asm

    r33 r34  
    66 
    77 PUBLIC SendCommandA,ReceiveHeaderPacket,SendSkipExitPacket,SendCAndAddToChecksum,SendContinue,ReceiveDataPacket 
     8 PUBLIC receiveRestOfDataPacket 
    89 EXTERN SetupPagedPtr,EnableLinkAssist,Send4Bytes,PagedGet,SendAByte,Get4BytesNC,JErrorNo 
    910 EXTERN SendCByte,RecAByteIO,SaveFlashBytes,SendAcknowledge 
     
    101102       ld hl,ioFlag 
    102103       ld a,(header+1) 
     104       cp 15h 
    103105       jp nz,JErrorNo 
    104106       ld hl,(header+2) 
  • 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