Picoblaze

This software and all the accompanying files are provided 'as is' and without any warranties expressed or implied including but not limited to implied warranties of merchantability and fitness for a particular purpose. In no event will the author be liable for any damages whatsoever (including without limitation, damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising out of the use or inability to use this product.

vscode highlighter

In vscode select F1 and enter: ext install, search for: mtx-psm

Picoblaze rijndael.psm (AES128)

Picoblaze picobug.psm

Picoblaze uart.psm

//
// Copyright © 2003..2012 : Henk van Kampen <henk@mediatronix.com>
//
// This file is part of pBlazASM.
//
// pBlazASM is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// pBlazASM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with pBlazASM.  If not, see <http://www.gnu.org/licenses/>.
//

; -------------------------------------------------------------------------------
; UART routines
; -------------------------------------------------------------------------------

        .IF _UART_

_UART_CS    .EQU    _UART + 12          // UART status register
_UART_DA    .EQU    _UART + 13          // UART data in.out registers

puts :                          // put a string pointed at by s1, to the UART
        LD  s0, s1
        ADD s1, 1
        COMP    s0, 0
        RET Z
        CALL    putc
        JUMP    puts

put2hex :                       // put an (8-bit) value in s0 in 2 hex character to the UART
        MOVE    sE, s0
        SR0 s0
        SR0 s0
        SR0 s0
        SR0 s0
        CALL    put1hex
        MOVE    s0, sE
put1hex :                       // put a (4-bit) value in s0 in 1 hex character to the UART
        AND s0, 0x0F
        COMP    s0, 10
        JUMP    C, put1hex1
        ADD s0, 'A' - 10 - '0'
put1hex1 :
        ADD s0, '0'
        JUMP    putc

putsp :                         // put a space char to the UART
        MOVE    s0, ' '
        JUMP    putc

putnl :                         // put CR and LF characters to the UART
        MOVE    s0, '\r'
        CALL    putc
        MOVE    s0, '\n'

putc :                          // put a character in s0 to the UART
        IN  sF, _UART_CS
        TEST    sF, 0b00000001          // space for one in the buffer?
        JUMP    NZ, putc

        OUT s0, _UART_DA
        RET

get1hex:                        // get a character from the UART and interpret as a hex value ('D' => 00001101)
get2hex10:  CALL    getc
        MOVE    sE, s0
        SUB sE, '0'
        COMP    sE, '9' - '0' + 1
        JUMP    C, get2hex20
        SUB sE, 'A' - '0'
        COMP    sE, 'F' - 'A' + 1
        JUMP    C, get2hex30
        SUB sE, 'a' - 'A'
        COMP    sE, 'f' - 'a' + 1
        JUMP    NC, get2hex10           // wait for an acceptable character
get2hex30:  ADD sE, 10
get2hex20:  CALL    putc
        MOVE    s0, sE
        RET


get2hex:                        // get 2 characters from the UART and interpret as a hex value ('2D' => 00101101)
        CALL    get1hex
        MOVE    sD, s0
        SL0 sD
        SL0 sD
        SL0 sD
        SL0 sD
        CALL    get1hex
        OR  s0, sD
        RET

poll :                          // check the status of the UART buffer and report in C
        IN  sF, _UART_CS
        TEST    sF, 0b00100000          // some char in the buffer?
        RET

getc :                          // wait for a character from the UART and return in s0
        IN  sF, _UART_CS
        TEST    sF, 0b00100000          // some char in the buffer?
        JUMP    Z, getc
        IN  s0, _UART_DA

        RET

        .FI

; -----------UART Subroutines end-------------------------------------------------