;;; -*- TI-Asm -*-
;;;
;;; Mimas - Assembly language IDE for the TI-83 Plus
;;;
;;; Copyright (C) 2010 Benjamin Moody
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see .
;; SkipExprHL:
;;
;; Skip over an expression.
;;
;; Input:
;; - HL = expression pointer
;; - C = expression byte count + 1
;;
;; Output:
;; - HL and C updated
;; - Carry flag set if expression incomplete
;;
;; Destroys:
;; - AF, B
SkipExprHL:
ld b,1
SkipExpr_Loop:
dec c
scf
ret z
ld a,(hl)
inc hl
add a,a
jr c,SkipExpr_Dec6OrOperator
;; 0xxxxxxx
add a,a
jr c,SkipExpr_Constant
;; 00xxxxxx xxxxxxxx: symbol value
SkipExpr_OneByte:
dec c
scf
ret z
inc hl
SkipExpr_GotSubexp:
djnz SkipExpr_Loop
or a
ret
SkipExpr_Constant:
;; 01xxxxxx
add a,a
jr c,SkipExpr_WordConstant
;; 010xxxxx
add a,a
jr c,SkipExpr_OneByte ; byte constant
;; 0100xxxx: special constant
jr SkipExpr_GotSubexp
SkipExpr_WordConstant:
add a,a
call c,Error_Bytecode
;; 0110xxxx xxxxxxxx xxxxxxxx: word constant
dec c
scf
ret z
inc hl
jr SkipExpr_OneByte
SkipExpr_Dec6OrOperator:
;; 1xxxxxxx
add a,a
jr c,SkipExpr_GotSubexp ; dec6 constant
;; 10xxxxxx
add a,a
jr c,SkipExpr_Binary
;; 100xxxxx
add a,a
call nc,Error_Bytecode
;; 1001xxxx : unary operator
jr SkipExpr_Loop
SkipExpr_Binary:
;; 101xxxxx : binary operator
inc b
jr SkipExpr_Loop
;; CopyConstExpr:
;;
;; Copy an expression. Throw an error if the expression contains any
;; non-constant subexpressions. Also simplify the expression by
;; removing X_PAREN operators.
;;
;; Input:
;; - HL = address of expression
;; - DE = buffer to place copy
;;
;; Output:
;; - DE = end of copied expression
;;
;; Destroys:
;; - AF, BC, HL
CopyConstExpr:
ld b,1
dec hl
CopyConstExpr_Skip:
inc hl
CopyConstExpr_Loop:
call CheckInstrBufOverflow
ld c,-1
ld a,(hl)
cp X_PAREN
jr z,CopyConstExpr_Skip
cp X_REGVAL
jr z,Error_ExpressionNotConstant
cp X_ARGVAL
jr z,Error_ExpressionNotConstant
add a,a
jr c,CopyConstExpr_Dec6OrOperator
;; 0xxxxxxx
add a,a
jr c,CopyConstExpr_Constant
;; 00xxxxxx xxxxxxxx: symbol
CopyConstExpr_TwoBytes:
ldi
call CheckInstrBufOverflow
CopyConstExpr_OneByte:
ldi
djnz CopyConstExpr_Loop
ret
Error_ExpressionNotConstant:
ld hl,emsg_ExpressionNotConstant
call ThrowLineError
;; UNREACHABLE
CopyConstExpr_Constant:
;; 01xxxxxx
add a,a
jr c,CopyConstExpr_WordConstant
;; 010xxxxx
add a,a
jr c,CopyConstExpr_TwoBytes ; byte constant
jr CopyConstExpr_OneByte ; special constant
CopyConstExpr_WordConstant:
add a,a
call c,Error_Bytecode
;; 0110xxxx xxxxxxxx xxxxxxxx: word constant
ldi
call CheckInstrBufOverflow
jr CopyConstExpr_TwoBytes
CopyConstExpr_Dec6OrOperator:
;; 1xxxxxxx
add a,a
jr c,CopyConstExpr_OneByte ; dec6 constant
;; 10xxxxxx
add a,a
jr c,CopyConstExpr_Binary
;; 100xxxxx
add a,a
call nc,Error_Bytecode
;; 1001xxxx : unary operator
dec b
CopyConstExpr_Binary:
;; 101xxxxx : binary operator
inc b
ldi
jr CopyConstExpr_Loop