Skip to content

Commit

Permalink
Adds a %TIME floating-point function to return 24bit time.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsc committed May 6, 2024
1 parent f072bd0 commit 9472f7b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ A800_FP_AS_SRC=\
src/interp/atarifp/fp_str.asm\
src/interp/atarifp/fp_sub.asm\
src/interp/atarifp/fp_val.asm\
src/interp/atarifp/fp_time.asm\
src/interp/atarifp/fpmain.asm\
src/interp/atarifp/mul6.asm\

Expand Down
13 changes: 12 additions & 1 deletion manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,9 @@ and the abbreviated syntax.
32767, or about 9 minutes in NTSC, and
a little less than 11 minutes in PAL,
after this the value will become
negative.
negative. If you need to measure more
than this amount, consider using the
floating-point version `%TIME`
Note: TIME is special, and does not
need parentheses.

Expand Down Expand Up @@ -860,6 +862,15 @@ will return an invalid value, and the
- SQR(_n_) / SQ.(_n_) :
Square root of _n_.

- %TIME / %T. :
This is the same as the `TIME` integer
function, but returning a 24 bit
number that does not wrap until more
than 3 days.
Note: Don't use the `TIMER` statement
if you are using this function, as the
returned value will be invalid.


String Functions
----------------
Expand Down
73 changes: 73 additions & 0 deletions src/interp/atarifp/fp_time.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
;
; FastBasic - Fast basic interpreter for the Atari 8-bit computers
; Copyright (C) 2017-2024 Daniel Serpell
;
; 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 2 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 <http://www.gnu.org/licenses/>
;
; In addition to the permissions in the GNU General Public License, the
; authors give you unlimited permission to link the compiled version of
; this file into combinations with other programs, and to distribute those
; combinations without any restriction coming from the use of this file.
; (The General Public License restrictions do apply in other respects; for
; example, they cover modification of the file, and distribution when not
; linked into a combine executable.)


; Floating Point TIME function
; ----------------------------

.import push_fr0
.importzp next_instruction

.include "atari.inc"

.segment "RUNTIME"

.proc EXE_FP_TIME
jsr push_fr0
; Get jiffies
retry: lda RTCLOK+2
ldy RTCLOK+1
ldx RTCLOK
cmp RTCLOK+2
bne retry
pha
; Convert high two bytes to float
stx FR0+1
sty FR0
jsr IFP
; Multiply the result by 256
ldx #<fp_256
ldy #>fp_256
jsr FLD1R
jsr FMUL
jsr FMOVE
; Convert low byte to float
pla
sta FR0
lda #0
sta FR0+1
jsr IFP
; Add
jsr FADD
jmp next_instruction
.endproc

fp_256: ; 256 in floating point
.byte $41,$02,$56,$00,$00,$00

.include "deftok.inc"
deftoken "FP_TIME"

; vi:syntax=asm_ca65
3 changes: 2 additions & 1 deletion src/syntax/float.syn
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TOKENS {
TOK_FP_DIV, TOK_FP_MUL, TOK_FP_SUB, TOK_FP_ADD, TOK_FP_STORE, TOK_FP_LOAD
TOK_FP_EXP, TOK_FP_EXP10, TOK_FP_LOG, TOK_FP_LOG10, TOK_FP_INT, TOK_FP_CMP
TOK_FP_IPOW, TOK_FP_RND, TOK_FP_SQRT, TOK_FP_SIN, TOK_FP_COS, TOK_FP_ATN
TOK_FP_STR
TOK_FP_STR, TOK_FP_TIME
# Used for floating point array access
TOK_MUL6
}
Expand Down Expand Up @@ -82,6 +82,7 @@ FP_FUNCS:
"COs" FP_T_EXPR emit TOK_FP_COS
"Val" STR_EXPR emit TOK_FP_VAL
"RNd()" emit TOK_FP_RND
"%Time" emit TOK_FP_TIME
"%" PAR_EXPR emit TOK_FP_LOAD

ADR_EXPR:
Expand Down
6 changes: 6 additions & 0 deletions testsuite/tests/abbrev.bas
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ PA.1 ' PAUSE
PA. ' PAUSE 0
PRI.T. ' PRINT TIME

T.
POKE 18,1
?%T.
PA.0
?%TIME

R. ' REPEAT
? "R"
U.1 ' UNTIL
Expand Down
2 changes: 2 additions & 0 deletions testsuite/tests/abbrev.chk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ N
?EXT LINE
BBBBB
3
65536
65537
R
W2
W1
Expand Down

0 comments on commit 9472f7b

Please sign in to comment.