⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot.asm

📁 bootload 汇编语言
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;
        bsr     BootProg                    ; go accept S19 records and program the Flash
        bra     Boot                        ; return to top of control loop


;*  Program Flash Subroutine  ===============================================================
;*
;*  This subroutine will copy the Flash Program algorithm into RAM and execute it in
;*  conjunction with the S19 record retrieval to program the required Flash pages between
;*  address pointers "flash_first" and "flash_last".
;*
;*  Calling convention:
;*
;*      jsr     BootProg                    ; retrieve S19 records and program Flash
;*
;*  Returns:    nothing
;*
;*  Changes:    everything
;*
BootProg:
        ldhx    #ProgramRamSize             ; initialize pointer
BootProg1:
        lda     Delay-1,x                   ; get program from Flash
        sta     ram_exec-1,x                ; copy into RAM
        dbnzx   BootProg1                   ; decrement pointer and loop back until done
        ldhx    #msg_waiting                ; point to waiting message
        bsr     PrintString                 ; output it
;
;   Get S-Record from host.
;
BootProg2:
        tsx                                 ; get the Stack Pointer
        sthx    temp_sp                     ; save it temporarily
        ais     #-36                        ; allocate stack space for data
        bsr     GetSRec                     ; get an S-Record
        bne     BootProg5                   ; indicate error if S-Record is invalid
        pula                                ; get S-Record type
        cmp     #'0'                        ; check for text header record type
        beq     BootProg3                   ; ignore and get next record
        cmp     #'9'                        ; check for end record type
        beq     BootProg4                   ; indicate operation complete
        cmp     #'1'                        ; check for data record type
        bne     BootProg5                   ; indicate error if S-Record is invalid
;
;   Program Flash.
;
        jsr     {ram_exec+ProgramRam}       ; execute Program Flash algorithm from RAM
BootProg3:
        ais     #35                         ; deallocate stack space
        bra     BootProg2                   ; loop back for next S-Record
;
BootProg4:
        ais     #35                         ; deallocate stack space
        brclr   SCRF,scs1,BootDone          ; skip if SCI receiver is empty
        bsr     GetChar                     ; else, clear last ASCII carriage return from SCI
        brclr   SCRF,scs1,BootDone          ; skip if SCI receiver is empty
        bsr     GetChar                     ; else, clear last ASCII line feed from the SCI
        ldhx    #msg_complete               ; point to operation complete message
        bra     BootProg6                   ; go output it
;
BootProg5:
        ais     #36                         ; deallocate stack space
        ldhx    #msg_error                  ; point to error message
BootProg6:
        bsr     PrintString                 ; output it
        rts                                 ; return


;*  Upgrade Flash Command Check  ============================================================
;*
Boot4:
        cmp     #cmd_upgrade                ; check for Upgrade Flash command
        bne     Boot5                       ; skip if not
;
        ldhx    #init_first                 ; force
        sthx    flash_first                 ;  first Flash address
        ldhx    #init_last                  ; force
        sthx    flash_last                  ;  last Flash address
        bsr     EraseFlash                  ; go erase Flash
        bra     BootProg                    ; go program Flash


;*  Multiple Flash Page Erase Subroutine  ===================================================
;*
;*  This subroutine will copy the Flash Erase algorithm into RAM and execute it to erase
;*  all pages between address pointers "flash_first" and "flash_last".
;*
;*  Calling convention:
;*
;*      ldhx    #init_first                 ; initialize
;*      sthx    flash_first                 ;  first Flash address
;*      ldhx    #init_last                  ; initialize
;*      sthx    flash_last                  ;  last Flash address
;*      jsr     EraseFlash                  ; go erase flash
;*
;*  Returns:    nothing
;*
;*  Changes:    everything
;*
EraseFlash:
        ldhx    #EraseRamSize               ; initialize pointer
EraseFlash1:
        lda     MassErase-1,x               ; get program from Flash
        sta     ram_exec-1,x                ; copy into RAM
        dbnzx   EraseFlash1                 ; decrement pointer and loop back until done
        jmp     ram_exec                    ; execute Flash Mass Erase algorithm from RAM


;*  GetChar Subroutine  =====================================================================
;*
;*  This subroutine will wait forever for a character to be received by the SCI and then
;*  returns with that character in ACC.  No error checking is performed.  Note that this
;*  is the primary loop where the COP counter is cleared.
;*
;*  C function prototype:
;*
;*      char GetChar (void);
;*
;*  Calling convention:
;*
;*      jsr     GetChar                     ; get a character from the SCI
;*
;*  Returns:
;*      ACC= data
;*
GetChar:
        sta     copctl                      ; clear the COP counter
        brclr   SCRF,scs1,GetChar           ; wait forever until SCI receiver is full
        lda     scdr                        ; get data
        rts                                 ; return


;*  GetSRec Subroutine  =====================================================================
;*
;*  This subroutine will retrieve data in S19 record format via the SCI.
;*
;*  Calling convention:
;*
;*      ais     #-buffer_length             ; allocate stack space for data
;*      jsr     GetSRec                     ; go get S-record data
;*
;*  Returns:    CCRZ= 1 if valid S-Record retrieved.  Otherwise, CCRZ= 0.
;*              S-Record Type at SP+1     (1 byte)
;*              S-Record Size at SP+2     (1 byte)
;*              S-Record Address at SP+3  (2 bytes)
;*              S-Record Data at SP+5     (up to 32 bytes, typically)
;*
;*              |                |    <-sp (after local space allocation)
;*      H:X->   | SRecCount      |
;*              | SRecChkSum     |    <-sp (when called)
;*              | ReturnAddr msb |
;*              | ReturnAddr lsb |    <-sp (upon return)
;*              | SRecType       |
;*              | SRecSize       |
;*      H:X->   | SRecAddr msb   |
;*              | SRecAddr lsb   |
;*              | SRecData 00    |
;*              | SRecData 01    |  etc..
;*
;*  Changes:    everything
;*
SRecCount:      equ     1                   ; stack pointer offset for S-Record Counter
SRecChkSum:     equ     2                   ; stack pointer offset for S-Record Check Sum
SRecType:       equ     5                   ; stack pointer offset for S-Record Type
SRecSize:       equ     6                   ; stack pointer offset for S-Record Size
SRecAddr:       equ     7                   ; stack pointer offset for S-Record Address
SRedData:       equ     8                   ; stack pointer offset for S-Record Data
;
GetSRec:
        ais     #-2                         ; allocate local variable space
        clr     SRecSize,sp                 ; initialize S-Record size
GetSRec1:
        bsr     GetChar                     ; get a character from the SCI
        cmp     #ascii_CR                   ; check for ASCII carriage return
        bne     GetSRec1a                   ; just loop back if so
        lda     #ascii_LF                   ; get ASCII line feed
GetSRec1a:
        cmp     #'S'                        ; check for start of record character
        bne     GetSRec1                    ; loop back if not
        bsr     GetChar                     ; else, get next character from the SCI
        cmp     #'0'                        ; check for header record type
        beq     GetSRec1                    ; loop back if so
        cmp     #'9'                        ; else, check for end record type
        beq     GetSRec2                    ; continue if so
        cmp     #'1'                        ; else, check for data record type
        bne     GetSRec1                    ; loop back if not
GetSRec2:
        sta     SRecType,sp                 ; save S-Record type
        bsr     GetHexByte                  ; get the S-Record length
        bne     GetSRec4                    ; exit if not a valid hex byte
        sta     SRecCount,sp                ; initialize S-Record counter
        sta     SRecChkSum,sp               ; initialize S-Record check sum
        sub     #3                          ; adjust for address and checksum
        sta     SRecSize,sp                 ; save S-Record size
        tsx                                 ; use H:X as data stack frame pointer
        aix     #{SRecAddr-1}               ; adjust so pointer starts at S-Record Address
GetSRec3:
        bsr     GetHexByte                  ; get next S-Record hex byte
        bne     GetSRec4                    ; exit if not a valid hex byte
        sta     ,x                          ; save data in stack frame
        add     SRecChkSum,sp               ; add data to check sum
        sta     SRecChkSum,sp               ; save new check sum
        aix     #1                          ; move data stack frame pointer
        dbnz    SRecCount,sp,GetSRec3       ; loop back until all data has been received
        inc     SRecChkSum,sp               ; final calculation zeros check sum if it's okay
GetSRec4:
        ais     #2                          ; deallocate local variables
        rts                                 ; return


;*  Help Command Response  ==================================================================
;*
Boot5:
        cmp     #cmd_help                   ; check for Help command
        beq     Boot6                       ; continue if so
        cmp     #cmd_help1                  ; check for alternate Help command
        bne     Boot7                       ; skip if not
boot6:
        ldhx    #msg_help                   ; point to Help command message
        jmp     BootDone1                   ; go output it


;*  Unknown Command Response  ===============================================================
;*
Boot7:
        ldhx    #msg_what                   ; point to unknown command message
        jmp     BootDone1                   ; go output it


;*  GetHexByte Subroutine  ==================================================================
;*
;*  This subroutine retrieves two ASCII bytes via the SCI and converts (packs) them into one
;*  hex byte, which is returned in ACC.
;*
;*  Calling convention:
;*
;*      jsr     GetHexByte
;*
;*  Returns:    CCRZ= 1 if valid hex byte retrieved.  Otherwise, CCRZ= 0.
;*              ACC= data
;*
;*  Changes:    ACC
;*
GetHexByte:
        bsr     GetChar                     ; get msb character from the SCI
        bsr     IsHex                       ; check if valid ASCII hex character
        bne     GetHexByte2                 ; exit if not
        bsr     ToHex                       ; convert ASCII hex character to hex value
        nsa                                 ; swap lower nibble up
        psha                                ; save temporarily
        jsr     GetChar                     ; get lsb character from the SCI
        bsr     IsHex                       ; check if valid ASCII hex character
        bne     GetHexByte1                 ; exit if not
        bsr     ToHex                       ; convert ASCII hex character to hex value
        add     1,sp                        ; combine msb and lsb nibbles
        bit     #0                          ; CCRZ= 1
GetHexByte1:
        ais     #1                          ; deallocate local variable
GetHexByte2:
        rts                                 ; return


;*  ToHex Subroutine  =======================================================================
;*
;*  This subroutine converts the ASCII hex value passed in ACC to a binary hex value.
;*
;*  Calling convention:
;*
;*      lda     data
;*      jsr     ToHex
;*
;*  Returns:    ACC= data.
;*
;*  Changes:    ACC
;*
ToHex:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -