prog8/prog8lib/prog8lib.p8

586 lines
8.2 KiB
Plaintext
Raw Normal View History

2018-09-15 14:21:05 +00:00
; Prog8 internal library routines - always included by the compiler
2017-12-30 12:34:52 +00:00
;
2018-01-08 02:31:23 +00:00
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
2018-01-13 13:17:18 +00:00
;
2017-12-30 12:34:52 +00:00
; indent format: TABS, size=8
2018-09-15 14:21:05 +00:00
~ prog8_lib {
2018-12-06 23:08:22 +00:00
; @TODO move all this assembly to a real .asm file instead and include that...
2017-12-30 19:03:19 +00:00
; note: the following ZP scratch registers must be the same as in c64lib
2018-12-06 23:08:22 +00:00
memory ubyte SCRATCH_ZPB1 = $02 ; scratch byte 1 in ZP
memory ubyte SCRATCH_ZPREG = $03 ; scratch register in ZP
memory uword SCRATCH_ZPWORD1 = $fb ; scratch word in ZP ($fb/$fc)
memory uword SCRATCH_ZPWORD2 = $fd ; scratch word in ZP ($fd/$fe)
2018-12-06 00:26:38 +00:00
const uword ESTACK_LO = $ce00
const uword ESTACK_HI = $cf00
2017-12-30 12:34:52 +00:00
2018-08-12 23:30:33 +00:00
%asm {{
2017-12-30 12:34:52 +00:00
; 16-bit rotate right (as opposed to the 6502's usual 17-bit rotate with carry)
; the word is placed in SCRATCH_ZPWORD1
2018-12-06 23:08:22 +00:00
ror2_word .proc
lsr SCRATCH_ZPWORD1+1
ror SCRATCH_ZPWORD1
2018-02-03 00:44:14 +00:00
bcc +
lda SCRATCH_ZPWORD1+1
ora #$80
sta SCRATCH_ZPWORD1+1
2018-02-04 21:00:08 +00:00
+ rts
2018-12-06 23:08:22 +00:00
.pend
2018-02-04 21:00:08 +00:00
2018-10-23 23:39:52 +00:00
2018-12-06 00:26:38 +00:00
; @todo: implement stubs!
2018-10-25 21:17:10 +00:00
; @todo: move float operations to their own library (only included when floats are enabled)
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
ub2float .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
b2float .proc
2018-10-26 22:34:42 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-26 22:34:42 +00:00
2018-12-06 23:08:22 +00:00
uw2float .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
w2float .proc
2018-10-26 22:34:42 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-26 22:34:42 +00:00
2018-12-06 23:08:22 +00:00
push_float .proc
2018-12-06 00:26:38 +00:00
; ---- push mflpt5 in A/Y onto stack
; (taking 3 stack positions = 6 bytes of which 1 is padding)
sta SCRATCH_ZPWORD1
sty SCRATCH_ZPWORD1+1
ldy #0
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
sta ESTACK_LO,x
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
sta ESTACK_HI,x
dex
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
sta ESTACK_LO,x
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
sta ESTACK_HI,x
dex
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
sta ESTACK_LO,x
dex
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.pend
2018-12-06 00:26:38 +00:00
2018-12-06 23:08:22 +00:00
push_float_from_indexed_var .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
pop_float .proc
; ---- pops mflpt5 from stack to memory A/Y
2018-12-06 00:26:38 +00:00
; (frees 3 stack positions = 6 bytes of which 1 is padding)
sta SCRATCH_ZPWORD1
sty SCRATCH_ZPWORD1+1
ldy #4
inx
lda ESTACK_LO,x
2018-12-06 23:08:22 +00:00
sta (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
dey
inx
lda ESTACK_HI,x
2018-12-06 23:08:22 +00:00
sta (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
dey
lda ESTACK_LO,x
2018-12-06 23:08:22 +00:00
sta (SCRATCH_ZPWORD1),y
dey
inx
2018-12-06 00:26:38 +00:00
lda ESTACK_HI,x
2018-12-06 23:08:22 +00:00
sta (SCRATCH_ZPWORD1),y
2018-12-06 00:26:38 +00:00
dey
2018-12-06 23:08:22 +00:00
lda ESTACK_LO,x
sta (SCRATCH_ZPWORD1),y
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.pend
2018-12-06 23:08:22 +00:00
pop_float_to_indexed_var .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
pop_mem_float .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
copy_float .proc
2018-12-06 00:26:38 +00:00
; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1,
; into the 5 bytes pointed to by A/Y. Clobbers Y.
sta SCRATCH_ZPWORD2
sty SCRATCH_ZPWORD2+1
ldy #0
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
sta (SCRATCH_ZPWORD2),y
2018-12-06 00:26:38 +00:00
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
sta (SCRATCH_ZPWORD2),y
2018-12-06 00:26:38 +00:00
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
sta (SCRATCH_ZPWORD2),y
2018-12-06 00:26:38 +00:00
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
sta (SCRATCH_ZPWORD2),y
2018-12-06 00:26:38 +00:00
iny
2018-12-06 23:08:22 +00:00
lda (SCRATCH_ZPWORD1),y
sta (SCRATCH_ZPWORD2),y
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
inc_var_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
dec_var_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
div_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
add_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
sub_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
mul_f .proc
2018-10-23 23:39:52 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-23 23:39:52 +00:00
2018-12-06 23:08:22 +00:00
neg_f .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-25 21:17:10 +00:00
2018-12-06 23:08:22 +00:00
add_w .proc
rts ; @todo inline?
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
add_uw .proc
rts ; @todo inline?
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
sub_w .proc
rts ; @todo inline?
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
sub_uw .proc
rts ; @todo inline?
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
mul_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
mul_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
mul_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
mul_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
div_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
div_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
div_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
div_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
remainder_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
remainder_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
remainder_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
remainder_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
remainder_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
equal_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
equal_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
equal_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
equal_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
equal_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
less_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
less_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
less_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
less_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
less_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
lesseq_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
lesseq_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
lesseq_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
lesseq_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
lesseq_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greater_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greater_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greater_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greater_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greater_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greatereq_ub .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greatereq_b .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greatereq_w .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greatereq_uw .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
greatereq_f .proc
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-12-06 23:08:22 +00:00
func_sin .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_cos .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_abs .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_acos .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_asin .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_tan .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_atan .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_ln .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_log2 .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_log10 .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_sqrt .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_rad .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_deg .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_round .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_floor .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_ceil .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_max .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--what does it max over???"
.pend
func_min .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--what does it min over???"
.pend
func_avg .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--what does it avg over???"
.pend
func_sum .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--what does it sum over???"
.pend
func_len .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--of what does it take len?"
.pend
func_any .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--of what does it do any?"
.pend
func_all .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented--of what does it do all?"
.pend
2018-12-06 00:26:38 +00:00
2018-12-06 23:08:22 +00:00
func_rnd .proc
2018-12-06 00:26:38 +00:00
; -- put a random ubyte on the estack
jsr math.randbyte
sta ESTACK_LO,x
dex
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.pend
2018-12-06 00:26:38 +00:00
2018-12-06 23:08:22 +00:00
func_rndw .proc
2018-12-06 00:26:38 +00:00
; -- put a random uword on the estack
jsr math.randword
sta ESTACK_LO,x
tya
sta ESTACK_HI,x
dex
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.pend
2018-12-06 00:26:38 +00:00
2018-12-06 23:08:22 +00:00
func_rndf .proc
2018-12-06 00:26:38 +00:00
; -- put a random floating point value on the stack
2018-12-06 23:08:22 +00:00
stx SCRATCH_ZPREG
lda #1
jsr c64.FREADSA
jsr c64.RND ; rng into fac1
2018-12-06 00:26:38 +00:00
ldx #<_rndf_rnum5
ldy #>_rndf_rnum5
jsr c64.FTOMEMXY ; fac1 to mem X/Y
2018-12-06 23:08:22 +00:00
ldx SCRATCH_ZPREG
2018-12-06 00:26:38 +00:00
lda #<_rndf_rnum5
ldy #>_rndf_rnum5
jmp push_float
_rndf_rnum5 .fill 5
2018-12-06 23:08:22 +00:00
.pend
2018-12-06 00:26:38 +00:00
2018-12-06 23:08:22 +00:00
func_wrd .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_uwrd .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_str2byte .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_str2ubyte .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_str2word .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_str2uword .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
func_str2float .proc
2018-10-25 21:17:10 +00:00
rts
2018-12-06 23:08:22 +00:00
.warn "not implemented"
.pend
2018-10-25 21:17:10 +00:00
2018-08-12 23:30:33 +00:00
}}
2017-12-30 12:34:52 +00:00
}