OpenCores
URL https://opencores.org/ocsvn/rtf65002/rtf65002/trunk

Subversion Repositories rtf65002

[/] [rtf65002/] [trunk/] [software/] [asm/] [TinyBasic65002.asm] - Diff between revs 28 and 39

Show entire file | Details | Blame | View Log

Rev 28 Rev 39
Line 46... Line 46...
CTRLS   EQU     0x13
CTRLS   EQU     0x13
CTRLX   EQU     0x18
CTRLX   EQU     0x18
XON             EQU     0x11
XON             EQU     0x11
XOFF    EQU     0x13
XOFF    EQU     0x13
 
 
CursorFlash     EQU             0xFC4
CursorFlash     EQU             0x7C4
IRQFlag         EQU             0xFC6
IRQFlag         EQU             0x7C6
 
 
OSSP            EQU             0xF00
OUTPTR          EQU             0x778
TXTUNF          EQU             0xF01
INPPTR          EQU             0x779
VARBGN          EQU             0xF02
FILENAME        EQU             0x6C0
LOPVAR          EQU             0xF03
FILEBUF         EQU             0x01F60000
STKGOS          EQU             0xF04
OSSP            EQU             0x700
CURRNT          EQU             0xF05
TXTUNF          EQU             0x701
BUFFER          EQU             0xF06
VARBGN          EQU             0x702
 
LOPVAR          EQU             0x703
 
STKGOS          EQU             0x704
 
CURRNT          EQU             0x705
 
BUFFER          EQU             0x706
BUFLEN          EQU             84
BUFLEN          EQU             84
LOPPT           EQU             0xF60
LOPPT           EQU             0x760
LOPLN           EQU             0xF61
LOPLN           EQU             0x761
LOPINC          EQU             0xF62
LOPINC          EQU             0x762
LOPLMT          EQU             0xF63
LOPLMT          EQU             0x763
NUMWKA          EQU             0xF64
NUMWKA          EQU             0x764
STKINP          EQU             0xF74
STKINP          EQU             0x774
STKBOT          EQU             0xF75
STKBOT          EQU             0x775
usrJmp          EQU             0xF76
usrJmp          EQU             0x776
IRQROUT         EQU             0xF77
IRQROUT         EQU             0x777
 
 
 
 
 
 
                cpu     rtf65002
                cpu     rtf65002
                code
                code
                org             $FFFFEC00
                org             $FFFFEC80
GOSTART:
GOSTART:
                jmp     CSTART  ;       Cold Start entry point
                jmp     CSTART  ;       Cold Start entry point
GOWARM:
GOWARM:
                jmp     WSTART  ;       Warm Start entry point
                jmp     WSTART  ;       Warm Start entry point
GOOUT:
GOOUT:
Line 91... Line 95...
;
;
; Modifiable system constants:
; Modifiable system constants:
;
;
                align   4
                align   4
;THRD_AREA      dw      0x04000000      ; threading switch area 0x04000000-0x40FFFFF
;THRD_AREA      dw      0x04000000      ; threading switch area 0x04000000-0x40FFFFF
;bitmap dw      0x04100000      ; bitmap graphics memory 0x04100000-0x417FFFF
;bitmap dw      0x00100000      ; bitmap graphics memory 0x04100000-0x417FFFF
TXTBGN  dw      0x04180000      ;TXT            ;beginning of program memory
TXTBGN  dw      0x01800000      ;TXT            ;beginning of program memory
ENDMEM  dw      0x057FFFFF      ;       end of available memory
ENDMEM  dw      0x018EFFFF      ;       end of available memory
STACKOFFS       dw      0x058FFFFF      ; stack offset - leave a little room for the BIOS stacks
STACKOFFS       dw      0x018FFFFF      ; stack offset - leave a little room for the BIOS stacks
;
;
; The main interpreter starts here:
; The main interpreter starts here:
;
;
; Usage
; Usage
; r1 = temp
; r1 = temp
Line 502... Line 506...
        lda             IRQROUT         ; are we handling IRQ's ?
        lda             IRQROUT         ; are we handling IRQ's ?
        beq             RUN1
        beq             RUN1
        ld              r0,IRQFlag              ; was there an IRQ ?
        ld              r0,IRQFlag              ; was there an IRQ ?
        beq             RUN1
        beq             RUN1
        stz             IRQFlag
        stz             IRQFlag
        jsr             PUSHA           ; the same code as a GOSUB
        jsr             PUSHA_          ; the same code as a GOSUB
        push    r8
        push    r8
        lda             CURRNT
        lda             CURRNT
        pha                                     ; found it, save old 'CURRNT'...
        pha                                     ; found it, save old 'CURRNT'...
        lda             STKGOS
        lda             STKGOS
        pha                                     ; and 'STKGOS'
        pha                                     ; and 'STKGOS'
Line 539... Line 543...
; 'GOTO expr' evaluates the expression, finds the target
; 'GOTO expr' evaluates the expression, finds the target
; line, and jumps to 'RUNTSL' to do it.
; line, and jumps to 'RUNTSL' to do it.
;
;
GOTO
GOTO
        jsr             OREXPR          ;evaluate the following expression
        jsr             OREXPR          ;evaluate the following expression
        jsr             DisplayWord
;       jsr             DisplayWord
        ld      r5,r1
        ld      r5,r1
        jsr     ENDCHK          ;must find end of line
        jsr     ENDCHK          ;must find end of line
        ld      r1,r5
        ld      r1,r5
        jsr     FNDLN           ; find the target line
        jsr     FNDLN           ; find the target line
        cmp             #0
        cmp             #0
Line 721... Line 725...
; in the initialization section of the interpreter), but we still
; in the initialization section of the interpreter), but we still
; save it as a flag for no further 'RETURN's.
; save it as a flag for no further 'RETURN's.
;******************************************************************
;******************************************************************
;
;
GOSUB:
GOSUB:
        jsr             PUSHA           ; save the current 'FOR' parameters
        jsr             PUSHA_          ; save the current 'FOR' parameters
        jsr             OREXPR          ; get line number
        jsr             OREXPR          ; get line number
        jsr             FNDLN           ; find the target line
        jsr             FNDLN           ; find the target line
        cmp             #0
        cmp             #0
        bne             gosub1
        bne             gosub1
        lda             #msgBadGotoGosub
        lda             #msgBadGotoGosub
Line 760... Line 764...
        pla
        pla
        sta             STKGOS          ; and the old 'STKGOS'
        sta             STKGOS          ; and the old 'STKGOS'
        pla
        pla
        sta             CURRNT          ; and the old 'CURRNT'
        sta             CURRNT          ; and the old 'CURRNT'
        pop             r8                      ; and the old text pointer
        pop             r8                      ; and the old text pointer
        jsr             POPA            ;and the old 'FOR' parameters
        jsr             POPA_           ;and the old 'FOR' parameters
        jmp             FINISH          ;and we are back home
        jmp             FINISH          ;and we are back home
 
 
;******************************************************************
;******************************************************************
; *** FOR *** & NEXT ***
; *** FOR *** & NEXT ***
;
;
Line 783... Line 787...
; currently active 'FOR' loop.  If that is the case, then the old
; currently active 'FOR' loop.  If that is the case, then the old
; 'FOR' loop is deactivated. (i.e. purged from the stack)
; 'FOR' loop is deactivated. (i.e. purged from the stack)
;******************************************************************
;******************************************************************
;
;
FOR:
FOR:
        jsr             PUSHA           ; save the old 'FOR' save area
        jsr             PUSHA_          ; save the old 'FOR' save area
        jsr             SETVAL          ; set the control variable
        jsr             SETVAL          ; set the control variable
        sta             LOPVAR          ; save its address
        sta             LOPVAR          ; save its address
        ld              r9,#TAB5
        ld              r9,#TAB5
        ld              r10,#TAB5_1     ; use 'EXEC' to test for 'TO'
        ld              r10,#TAB5_1     ; use 'EXEC' to test for 'TO'
        jmp             EXEC
        jmp             EXEC
Line 861... Line 865...
        lda             #msgNextFor
        lda             #msgNextFor
        bra             ERROR
        bra             ERROR
NX5:
NX5:
        cmp             r1,r9
        cmp             r1,r9
        beq             NX2             ; else we check them OK, they agree
        beq             NX2             ; else we check them OK, they agree
        jsr             POPA            ; nope, let's see the next frame
        jsr             POPA_           ; nope, let's see the next frame
        bra             NX0
        bra             NX0
NX2:
NX2:
        lda             (r9)            ; get control variable's value
        lda             (r9)            ; get control variable's value
        ldx             LOPINC
        ldx             LOPINC
        add             r1,r1,r2        ; add in loop increment
        add             r1,r1,r2        ; add in loop increment
Line 887... Line 891...
        ld              r8,LOPLN        ; Within limit, go back to the...
        ld              r8,LOPLN        ; Within limit, go back to the...
        st              r8,CURRNT
        st              r8,CURRNT
        ld              r8,LOPPT        ; saved 'CURRNT' and text pointer.
        ld              r8,LOPPT        ; saved 'CURRNT' and text pointer.
        jmp             FINISH
        jmp             FINISH
NXPurge:
NXPurge:
    jsr    POPA        ; purge this loop
    jsr    POPA_        ; purge this loop
    jmp     FINISH
    jmp     FINISH
 
 
 
 
;******************************************************************
;******************************************************************
; *** REM *** IF *** INPUT *** LET (& DEFLT) ***
; *** REM *** IF *** INPUT *** LET (& DEFLT) ***
Line 1082... Line 1086...
LODEND:
LODEND:
        st              r8,TXTUNF       ; set end-of program pointer
        st              r8,TXTUNF       ; set end-of program pointer
        jmp             WSTART          ; back to direct mode
        jmp             WSTART          ; back to direct mode
 
 
 
 
; get character from input (16 bit value)
; get character from input (32 bit value)
GCHAR:
GCHAR:
        push    r5
        push    r5
        push    r6
        push    r6
        ld              r6,#3       ; repeat four times
        ld              r6,#8       ; repeat eight times
        ld              r5,#0
        ld              r5,#0
GCHAR1:
GCHAR1:
        jsr             GOAUXI          ; get a char
        jsr             GOAUXI          ; get a char
        cmp             #0
        cmp             #0
        beq             GCHAR1
        beq             GCHAR1
        bcc             GCHAR1
        bcc             GCHAR1
        jsr             asciiToHex
        jsr             asciiToHex
        asl             r5,r5
        asl             r5,r5,#4
        asl             r5,r5
 
        asl             r5,r5
 
        asl             r5,r5
 
        or              r5,r5,r1
        or              r5,r5,r1
        dec             r6
        dec             r6
        bne             GCHAR1
        bne             GCHAR1
        ld              r1,r5
        ld              r1,r5
        pop             r6
        pop             r6
Line 1121... Line 1122...
a2h1:
a2h1:
        sub             #'0'
        sub             #'0'
        and             #15                     ; make sure a nybble
        and             #15                     ; make sure a nybble
        rts
        rts
 
 
LOAD3:
GetFilename:
        jsr             spi_init
        ldy             #'"'
 
        ld              r4,#gfn1
 
        jsr             TSTC
 
        ldy             #0
 
gfn2:
 
        ld              r1,(r8)         ; get text character
 
        inc             r8
 
        cmp             #'"'
 
        beq             gfn3
        cmp             #0
        cmp             #0
        bne             WSTART
        beq             gfn3
        lda             #5000
        sb              r1,FILENAME,y
 
        iny
 
        cpy             #32
 
        bne             gfn2
 
        rts
 
gfn3:
 
        lda             #' '
 
        sb              r1,FILENAME,y
 
        iny
 
        cpy             #32
 
        bne             gfn3
 
        rts
 
gfn1:
 
        jmp             WSTART
 
 
 
LOAD3:
 
        jsr             GetFilename
 
        jsr             AUXIN_INIT
 
        jmp             LOAD
 
 
 
;       jsr             OREXPR          ;evaluate the following expression
 
;       lda             #5000
        ldx             #$E00
        ldx             #$E00
        jsr             spi_read_sector
        jsr             SDReadSector
        lda             #5001
        ina
        ldx             TXTBGN>>2
        ldx             TXTBGN>>2
        asl             r2,r2,#2
        asl             r2,r2,#2
LOAD4:
LOAD4:
        pha
        pha
        jsr             spi_read_sector
        jsr             SDReadSector
        add             r2,r2,#512
        add             r2,r2,#512
        pla
        pla
        ina
        ina
        ld              r4,TXTBGN>>2
        ld              r4,TXTBGN>>2
        asl             r4,r4,#2
        asl             r4,r4,#2
        add             r4,r4,#65536
        add             r4,r4,#65536
        cmp             r2,r4
        cmp             r2,r4
        bmi             LOAD4
        bmi             LOAD4
 
LOAD5:
        bra             WSTART
        bra             WSTART
 
 
SAVE3:
SAVE3:
        jsr             spi_init
        jsr             GetFilename
        cmp             #0
        jsr             AUXOUT_INIT
        bne             WSTART
        jmp             SAVE
        lda             #5000           ; starting sector
 
 
        jsr             OREXPR          ;evaluate the following expression
 
;       lda             #5000           ; starting sector
        ldx             #$E00           ; starting address to write
        ldx             #$E00           ; starting address to write
        jsr             spi_write_sector
        jsr             SDWriteSector
        lda             #5001
        ina
        ldx             TXTBGN>>2
        ldx             TXTBGN>>2
        asl             r2,r2,#2
        asl             r2,r2,#2
SAVE4:
SAVE4:
        pha
        pha
        jsr             spi_write_sector
        jsr             SDWriteSector
        add             r2,r2,#512
        add             r2,r2,#512
        pla
        pla
        ina
        ina
        ld              r4,TXTBGN>>2
        ld              r4,TXTBGN>>2
        asl             r4,r4,#2
        asl             r4,r4,#2
Line 1192... Line 1225...
        lda             #'@'            ; send end-of-program indicator
        lda             #'@'            ; send end-of-program indicator
        jsr             GOAUXO
        jsr             GOAUXO
        jsr             AUXOCRLF    ; followed by a CR & LF
        jsr             AUXOCRLF    ; followed by a CR & LF
        lda             #$1A            ; and a control-Z to end the CP/M file
        lda             #$1A            ; and a control-Z to end the CP/M file
        jsr             GOAUXO
        jsr             GOAUXO
 
        jsr             AUXOUT_FLUSH
        bra             WSTART          ; then go do a warm start
        bra             WSTART          ; then go do a warm start
 
 
 
 
; output a CR LF sequence to auxillary output
; output a CR LF sequence to auxillary output
; Registers Affected
; Registers Affected
Line 1210... Line 1244...
 
 
; output a word in hex format
; output a word in hex format
; tricky because of the need to reverse the order of the chars
; tricky because of the need to reverse the order of the chars
PWORD:
PWORD:
        push    r5
        push    r5
        ld              r5,#NUMWKA+15
        ld              r5,#NUMWKA+7
        or              r4,r1,r0        ; r4 = value
        or              r4,r1,r0        ; r4 = value
pword1:
pword1:
    or      r1,r4,r0    ; r1 = value
    or      r1,r4,r0    ; r1 = value
    lsr         r4,r4           ; shift over to next nybble
    lsr         r4,r4,#4        ; shift over to next nybble
    lsr         r4,r4
 
    lsr         r4,r4
 
    lsr         r4,r4
 
    jsr         toAsciiHex  ; convert LS nybble to ascii hex
    jsr         toAsciiHex  ; convert LS nybble to ascii hex
    sta     (r5)                ; save in work area
    sta     (r5)                ; save in work area
    sub         r5,r5,#1
    sub         r5,r5,#1
    cmp         r5,#NUMWKA
    cmp         r5,#NUMWKA
    beq         pword1
    beq         pword1
    bcs         pword1
    bcs         pword1
pword2:
pword2:
    add         r5,r5,#1
    add         r5,r5,#1
    lda    (r5)     ; get char to output
    lda    (r5)     ; get char to output
        jsr             GOAUXO          ; send it
        jsr             GOAUXO          ; send it
        cmp             r5,#NUMWKA+15
        cmp             r5,#NUMWKA+7
        bcc             pword2
        bcc             pword2
        pop             r5
        pop             r5
        rts
        rts
 
 
 
 
Line 2155... Line 2186...
        cmp             r1,r3
        cmp             r1,r3
        bne             MVDOWN1
        bne             MVDOWN1
        rts
        rts
 
 
 
 
; 'POPA' restores the 'FOR' loop variable save area from the stack
; 'POPA_' restores the 'FOR' loop variable save area from the stack
;
;
; 'PUSHA' stacks for 'FOR' loop variable save area onto the stack
; 'PUSHA_' stacks for 'FOR' loop variable save area onto the stack
;
;
; Note: a single zero word is stored on the stack in the
; Note: a single zero word is stored on the stack in the
; case that no FOR loops need to be saved. This needs to be
; case that no FOR loops need to be saved. This needs to be
; done because PUSHA / POPA is called all the time.
; done because PUSHA_ / POPA_ is called all the time.
message "POPA"
message "POPA_"
POPA:
POPA_:
        ply
        ply
        pla
        pla
        sta             LOPVAR  ; restore LOPVAR, but zero means no more
        sta             LOPVAR  ; restore LOPVAR, but zero means no more
        beq             PP1
        beq             PP1
        pla
        pla
Line 2180... Line 2211...
        sta             LOPPT
        sta             LOPPT
PP1:
PP1:
        jmp             (y)
        jmp             (y)
 
 
 
 
PUSHA:
PUSHA_:
        ply
        ply
        lda             STKBOT          ; Are we running out of stack room?
        lda             STKBOT          ; Are we running out of stack room?
        add             r1,r1,#5        ; we might need this many words
        add             r1,r1,#5        ; we might need this many words
        tsx
        tsx
        cmp             r2,r1
        cmp             r2,r1
Line 2315... Line 2346...
        cmp             #0
        cmp             #0
        bpl             PN2                     ; is it negative? if not
        bpl             PN2                     ; is it negative? if not
        sub             r1,r0,r1        ; else make it positive
        sub             r1,r0,r1        ; else make it positive
        dec             r5                      ; one less for width count
        dec             r5                      ; one less for width count
PN2:
PN2:
        ld              r3,#10
;       ld              r3,#10
PN1:
PN1:
        mod             r2,r1,r3        ; r2 = r1 mod 10
        mod             r2,r1,#10       ; r2 = r1 mod 10
        div             r1,r1,r3        ; r1 /= 10 divide by 10
        div             r1,r1,#10       ; r1 /= 10 divide by 10
        add             r2,r2,#'0'      ; convert remainder to ascii
        add             r2,r2,#'0'      ; convert remainder to ascii
        stx             (r7)            ; and store in buffer
        stx             (r7)            ; and store in buffer
        inc             r7
        inc             r7
        dec             r5                      ; decrement width
        dec             r5                      ; decrement width
        cmp             #0
        cmp             #0
Line 2429... Line 2460...
PRTLN:
PRTLN:
        push    r5
        push    r5
    ld          r5,r1           ; r5 = pointer
    ld          r5,r1           ; r5 = pointer
    lda         (r5)            ; get the binary line number
    lda         (r5)            ; get the binary line number
    inc         r5
    inc         r5
    ldx         #12       ; display a 0 or more digit line no.
    ldx         #5       ; display a 0 or more digit line no.
        jsr             PRTNUM
        jsr             PRTNUM
        lda             #' '     ; followed by a blank
        lda             #' '     ; followed by a blank
        jsr             GOOUT
        jsr             GOOUT
        ldx             #0       ; stop char. is a zero
        ldx             #0       ; stop char. is a zero
        ld              r1,r5
        ld              r1,r5
Line 2670... Line 2701...
 
 
;*
;*
;* ===== Input a character from the host into register r1 (or
;* ===== Input a character from the host into register r1 (or
;*      return Zero status if there's no character available).
;*      return Zero status if there's no character available).
;*
;*
AUXIN:
AUXIN_INIT:
        jsr             SerialGetChar
        stz             INPPTR
        cmp             #-1
        lda             #FILENAME
        beq             AXIRET_ZERO
        ldx             #FILEBUF<<2
        and             #$7F                            ;zero out the high bit
        ldy             #$10000
AXIRET:
        jsr             do_load
        rts
        rts
AXIRET_ZERO:
 
        lda             #0
AUXIN:
 
        phx
 
        ldx             INPPTR
 
        lb              r1,FILEBUF<<2,x
 
        inx
 
        stx             INPPTR
 
        plx
        rts
        rts
 
 
 
;       jsr             SerialGetChar
 
;       cmp             #-1
 
;       beq             AXIRET_ZERO
 
;       and             #$7F                            ;zero out the high bit
 
;AXIRET:
 
;       rts
 
;AXIRET_ZERO:
 
;       lda             #0
 
;       rts
 
 
; ===== Output character to the host (Port 2) from register r1
; ===== Output character to the host (Port 2) from register r1
;       (Preserves all registers.)
;       (Preserves all registers.)
;
;
AUXOUT
AUXOUT_INIT:
        jmp             SerialPutChar   ; call boot rom routine
        stz             OUTPTR
 
        rts
 
 
 
AUXOUT:
 
        phx
 
        ldx             OUTPTR
 
        sb              r1,FILEBUF<<2,x
 
        inx
 
        stx             OUTPTR
 
        plx
 
        rts
 
 
 
AUXOUT_FLUSH:
 
        lda             #FILENAME
 
        ldx             #FILEBUF<<2
 
        ldy             OUTPTR
 
        jsr             do_save
 
        rts
 
 
 
;       jmp             SerialPutChar   ; call boot rom routine
 
 
 
 
_cls
_cls
        jsr             ClearScreen
        jsr             ClearScreen
        jsr             HomeCursor
        jsr             HomeCursor

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.