min/max byte arrays

This commit is contained in:
Irmen de Jong 2018-12-21 01:06:01 +01:00
parent ee893e5a2c
commit 4c2a81c452
17 changed files with 201 additions and 181 deletions

View File

@ -10,7 +10,7 @@
byte v1
byte v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
v1 = 100
@ -110,7 +110,7 @@
else
c64.STROUT("error in 22>=22!\n")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -10,7 +10,7 @@
float v1
float v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
v1 = 1.11
@ -110,7 +110,7 @@
else
c64.STROUT("error in -22.2>=-22.2!\n")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -10,7 +10,7 @@
ubyte v1
ubyte v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
v1 = 100
@ -110,7 +110,7 @@
else
c64.STROUT("error in 22>=22!\n")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -10,7 +10,7 @@
uword v1
uword v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
v1 = 100
@ -110,7 +110,7 @@
else
c64.STROUT("error in 322>=322!\n")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -10,7 +10,7 @@
word v1
word v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
v1 = 100
@ -110,7 +110,7 @@
else
c64.STROUT("error in -222>=-222!\n")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -11,7 +11,7 @@
; check stack usage:
c64.STROUT("signed byte ")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT(' ')
cr=v1==v2
@ -39,7 +39,7 @@
cr=v1>=v2
cr=v1>=v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; comparisons:
@ -58,7 +58,7 @@
c64.STROUT("v1=20, v2=-111\n")
compare()
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
return

View File

@ -13,7 +13,7 @@
; check stack usage:
c64.STROUT("floating point ")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT(' ')
cr=v1==v2
@ -41,7 +41,7 @@
cr=v1>=v2
cr=v1>=v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; comparisons:
@ -75,7 +75,7 @@
c64.STROUT("v1 = v2 = 0\n")
compare()
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
return

View File

@ -11,7 +11,7 @@
; check stack usage:
c64.STROUT("unsigned byte ")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT(' ')
cr=v1==v2
@ -39,7 +39,7 @@
cr=v1>=v2
cr=v1>=v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; comparisons:
@ -58,7 +58,7 @@
c64.STROUT("v1=220, v2=10\n")
compare()
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
return

View File

@ -11,7 +11,7 @@
; check stack usage:
c64.STROUT("unsigned word ")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT(' ')
cr=v1==v2
@ -39,7 +39,7 @@
cr=v1>=v2
cr=v1>=v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; comparisons:
@ -88,7 +88,7 @@
c64.STROUT("v1 = v2 = aa\n")
compare()
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
return

View File

@ -12,7 +12,7 @@
; check stack usage:
c64.STROUT("signed word ")
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT(' ')
cr=v1==v2
@ -40,7 +40,7 @@
cr=v1>=v2
cr=v1>=v2
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; comparisons:
@ -125,7 +125,7 @@
c64.STROUT("v1 = v2 = aa\n")
compare()
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
return

View File

@ -7,7 +7,7 @@
const ubyte max_iter = 16
sub start() {
c64scr.print_string("calculating mandelbrot fractal...\n")
c64scr.print("calculating mandelbrot fractal...\n")
c64.TIME_HI=0
c64.TIME_MID=0
@ -38,8 +38,8 @@
c64.CHROUT('\n')
}
float duration = floor((c64.TIME_LO + c64.TIME_MID*256.0 + c64.TIME_HI*65536.0)/60.0)
c64scr.print_string("finished in ")
c64flt.print_float(duration)
c64scr.print_string(" seconds!\n")
c64scr.print("finished in ")
c64flt.print_f(duration)
c64scr.print(" seconds!\n")
}
}

View File

@ -39,7 +39,7 @@
ask_guess:
c64.STROUT("\nYou have ")
c64scr.print_ubyte(attempts_left)
c64scr.print_ub(attempts_left)
c64.STROUT(" guess")
if(attempts_left>1)
c64.STROUT("es")
@ -66,7 +66,7 @@ ask_guess:
; game over.
c64.STROUT("\nToo bad! It was: ")
c64scr.print_ubyte(secretnumber)
c64scr.print_ub(secretnumber)
c64.CHROUT('\n')
goodbye:

View File

@ -13,48 +13,48 @@
ubyte secretnumber = rnd() % 99 + 1 ; random number 1..100
c64.VMCSB |= 2 ; switch lowercase chars
c64scr.print_string("Please introduce yourself: ")
c64scr.print("Please introduce yourself: ")
c64scr.input_chars(name)
c64scr.print_string("\n\nHello, ")
c64scr.print_string(name)
c64scr.print_string(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
c64scr.print("\n\nHello, ")
c64scr.print(name)
c64scr.print(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
for ubyte attempts_left in 10 to 1 step -1 {
; stackptr debugging
; c64scr.print_byte(X)
; c64scr.print_b(X)
; c64.CHROUT('\n')
c64scr.print_string("\nYou have ")
c64scr.print_ubyte(attempts_left)
c64scr.print_string(" guess")
c64scr.print("\nYou have ")
c64scr.print_ub(attempts_left)
c64scr.print(" guess")
if attempts_left>1
c64scr.print_string("es")
c64scr.print_string(" left.\nWhat is your next guess? ")
c64scr.print("es")
c64scr.print(" left.\nWhat is your next guess? ")
c64scr.input_chars(input)
ubyte guess = str2ubyte(input)
; debug info
; c64scr.print_string(" > attempts left=")
; c64scr.print_byte(attempts_left)
; c64scr.print_string("\n > secretnumber=")
; c64scr.print_byte(secretnumber)
; c64scr.print_string("\n > input=")
; c64scr.print_string(input)
; c64scr.print_string("\n > guess=")
; c64scr.print_byte(guess)
; c64scr.print(" > attempts left=")
; c64scr.print_b(attempts_left)
; c64scr.print("\n > secretnumber=")
; c64scr.print_b(secretnumber)
; c64scr.print("\n > input=")
; c64scr.print(input)
; c64scr.print("\n > guess=")
; c64scr.print_b(guess)
; c64.CHROUT('\n')
; c64scr.print_byte(X) ; stackptr debugging
; c64scr.print_b(X) ; stackptr debugging
; c64.CHROUT('\n')
if guess==secretnumber {
return ending(true)
} else {
c64scr.print_string("\n\nThat is too ")
c64scr.print("\n\nThat is too ")
if guess<secretnumber
c64scr.print_string("low!\n")
c64scr.print("low!\n")
else
c64scr.print_string("high!\n")
c64scr.print("high!\n")
}
}
@ -63,15 +63,15 @@
sub ending(ubyte success) {
if success
c64scr.print_string("\n\nYou guessed it, impressive!\n")
c64scr.print("\n\nYou guessed it, impressive!\n")
else {
c64scr.print_string("\nToo bad! My number was: ")
c64scr.print_ubyte(secretnumber)
c64scr.print_string(".\n")
c64scr.print("\nToo bad! My number was: ")
c64scr.print_ub(secretnumber)
c64scr.print(".\n")
}
c64scr.print_string("Thanks for playing, ")
c64scr.print_string(name)
c64scr.print_string(".\n")
c64scr.print("Thanks for playing, ")
c64scr.print(name)
c64scr.print(".\n")
}
}
}

View File

@ -8,73 +8,52 @@
sub start() {
ubyte ub1
ubyte ub2
ubyte ub3
byte b1
byte b2
byte b3
uword uw1
uword uw2
uword uw3
word w1
word w2
word w3
float f1
float f2
float f3
byte[4] ba = [-1,2,-10,30]
ubyte[4] uba = [4,200,10,15]
word[4] wa = [400,-200,-1000,1500]
uword[4] uwa = [4000,200,1000,150]
float[4] fa = [-2.22, 3.33, -5.55, 1.11]
c64scr.print(" X=")
c64scr.print_ub(X)
c64.CHROUT('\n')
ub1=20
ub2=6
ub3=ub1*ub2
c64scr.print_ub(ub3) ; 120
c64.CHROUT('\n')
uw1=900
uw2=66
uw3=uw1*uw2
c64scr.print_uw(uw3) ; 59400
c64.CHROUT('\n')
byte bmin = min(ba)
byte bmax = max(ba)
ubyte ubmin = min(uba)
ubyte ubmax = max(uba)
; word wmin = min(wa)
; word wmax = max(wa)
; uword uwmin = min(uwa)
; uword uwmax = max(uwa)
; float fmin = min(fa)
; float fmax = max(fa)
b1=20
b2=6
b3=b1*b2
c64scr.print_b(b3) ; 120
c64scr.print_b(bmin)
c64.CHROUT(',')
c64scr.print_b(bmax)
c64.CHROUT('\n')
w1=500
w2=44
w3=w1*w2
c64scr.print_w(w3) ; 22000
c64.CHROUT('\n')
b1=20
b2=-6
b3=b1*b2
c64scr.print_b(b3) ; -120
c64.CHROUT('\n')
w1=500
w2=-44
w3=w1*w2
c64scr.print_w(w3) ; -22000
c64.CHROUT('\n')
b1=-20
b2=-6
b3=b1*b2
c64scr.print_b(b3) ; 120
c64.CHROUT('\n')
w1=-500
w2=-44
w3=w1*w2
c64scr.print_w(w3) ; 22000
c64.CHROUT('\n')
f1=-500.11
f2=44.4
f3=f1*f2
c64flt.print_f(f3)
c64scr.print_ub(ubmin)
c64.CHROUT(',')
c64scr.print_ub(ubmax)
c64.CHROUT('\n')
; c64scr.print_w(wmin)
; c64.CHROUT(',')
; c64scr.print_w(wmax)
; c64.CHROUT('\n')
; c64scr.print_uw(uwmin)
; c64.CHROUT(',')
; c64scr.print_uw(uwmax)
; c64.CHROUT('\n')
;
; c64flt.print_f(fmin)
; c64.CHROUT(',')
; c64flt.print_f(fmax)
; c64.CHROUT('\n')
c64scr.print(" X=")
c64scr.print_ub(X)
c64.CHROUT('\n')
; ub3 = 200/67 as ubyte
; ub3 = 200//67
@ -100,33 +79,6 @@
; c64scr.print_uw(uw3)
; c64.CHROUT('\n')
;
; f3 = 999/44
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = 999//44
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = f1/f2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = f1//f2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = ub1/ub2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = ub1//ub2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = uw1/uw2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
; f3 = uw1//uw2
; c64flt.print_f(f3)
; c64.CHROUT('\n')
c64scr.print(" X=")
c64scr.print_ub(X)
c64.CHROUT('\n')
; const byte width=20
; word w1
@ -134,10 +86,10 @@
; ubyte ub1
; float x = 3.45
; b1 = fintb(x * flt(width)/4.2) + width//2
; c64scr.print_byte(b1)
; c64scr.print_b(b1)
; c64.CHROUT('\n')
; b1 = fintb(x/4.2 * flt(width)) + width//2
; c64scr.print_byte(b1)
; c64scr.print_b(b1)
; c64.CHROUT('\n')
; ub1 = b2ub(fintb(x * flt(width)/4.2) + width//2)
; c64scr.print_ub(ub1)
@ -146,10 +98,10 @@
; c64scr.print_ub(ub1)
; c64.CHROUT('\n')
; w1 = fintw(x * flt(width)/4.2) + width//2
; c64scr.print_word(w1)
; c64scr.print_w(w1)
; c64.CHROUT('\n')
; w1 = fintw(x/4.2 * flt(width)) + width//2
; c64scr.print_word(w1)
; c64scr.print_w(w1)
; c64.CHROUT('\n')
;uw1 = w2uw(fintw(x * flt(width)/4.2) + width//2) ; @todo w2uw

View File

@ -35,59 +35,59 @@
str_ps psstring = "hello123"
c64.CHROUT('x')
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
; @todo implement max and min, AND FIX STACKPTR (X) ERRORS!
ub1 = max(uba)
c64scr.print_ubyte(ub1)
c64scr.print_ub(ub1)
c64.CHROUT('\n')
b1 = max(ba)
c64scr.print_byte(b1)
c64scr.print_b(b1)
c64.CHROUT('\n')
uw1 = max(uwa)
c64scr.print_uword(uw1)
c64scr.print_uw(uw1)
c64.CHROUT('\n')
w1 = max(wa0)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
w1 = max(wa1)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
w1 = max(wa2)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
f1 = max(fa1)
c64flt.print_float(f1)
c64flt.print_f(f1)
c64.CHROUT('\n')
c64.CHROUT('x')
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
ub1 = min(uba)
c64scr.print_ubyte(ub1)
c64scr.print_ub(ub1)
c64.CHROUT('\n')
b1 = min(ba)
c64scr.print_byte(b1)
c64scr.print_b(b1)
c64.CHROUT('\n')
uw1 = min(uwa)
c64scr.print_uword(uw1)
c64scr.print_uw(uw1)
c64.CHROUT('\n')
w1 = min(wa0)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
w1 = min(wa1)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
w1 = min(wa2)
c64scr.print_word(w1)
c64scr.print_w(w1)
c64.CHROUT('\n')
f1 = min(fa1)
c64flt.print_float(f1)
c64flt.print_f(f1)
c64.CHROUT('\n')
c64.CHROUT('x')
c64scr.print_ubyte(X)
c64scr.print_ub(X)
c64.CHROUT('\n')
}

View File

@ -89,7 +89,7 @@ mult16 lda #$00
bne -
rts
multiply_words_result .fill 4
multiply_words_result .byte 0,0,0,0
}}
}

View File

@ -302,8 +302,8 @@ pop_2_floats_f2_in_fac1 .proc
jmp c64.MOVFM
.pend
fmath_float1 .fill 5 ; storage for a mflpt5 value
fmath_float2 .fill 5 ; storage for a mflpt5 value
fmath_float1 .byte 0,0,0,0,0 ; storage for a mflpt5 value
fmath_float2 .byte 0,0,0,0,0 ; storage for a mflpt5 value
push_fac1_as_result .proc
; -- push the float in FAC1 onto the stack, and return from calculation
@ -1154,15 +1154,43 @@ _cmp_mod cpy #255 ; modified
.pend
func_max_ub .proc
inx
jsr pop_array_and_lengthY
lda #0
sta SCRATCH_ZPB1
dey
- lda (SCRATCH_ZPWORD1),y
cmp SCRATCH_ZPB1
bcc +
sta SCRATCH_ZPB1
+ dey
cpy #255
bne -
lda SCRATCH_ZPB1
sta ESTACK_LO,x
dex
rts
.warn "todo func_max_ub"
.pend
func_max_b .proc
inx
jsr pop_array_and_lengthY
lda #-128
sta SCRATCH_ZPB1
dey
- lda (SCRATCH_ZPWORD1),y
sec
sbc SCRATCH_ZPB1
bvc +
eor #$80
+ bmi +
lda (SCRATCH_ZPWORD1),y
sta SCRATCH_ZPB1
+ dey
cpy #255
bne -
lda SCRATCH_ZPB1
sta ESTACK_LO,x
dex
rts
.warn "todo func_max_b"
.pend
func_max_uw .proc
@ -1178,21 +1206,61 @@ func_max_w .proc
.pend
func_max_f .proc
inx
dex
rts
.warn "todo func_max_f"
.pend
func_min_ub .proc
pop_array_and_lengthY .proc
inx
ldy ESTACK_LO,x
lda ESTACK_LO+1,x
sta SCRATCH_ZPWORD1
lda ESTACK_HI+1,x
sta SCRATCH_ZPWORD1+1
inx
rts
.warn "todo func_min_ub"
.pend
func_min_b .proc
inx
func_min_ub .proc
jsr pop_array_and_lengthY
lda #255
sta SCRATCH_ZPB1
dey
- lda (SCRATCH_ZPWORD1),y
cmp SCRATCH_ZPB1
bcs +
sta SCRATCH_ZPB1
+ dey
cpy #255
bne -
lda SCRATCH_ZPB1
sta ESTACK_LO,x
dex
rts
.pend
func_min_b .proc
jsr pop_array_and_lengthY
lda #127
sta SCRATCH_ZPB1
dey
- lda (SCRATCH_ZPWORD1),y
clc
sbc SCRATCH_ZPB1
bvc +
eor #$80
+ bpl +
lda (SCRATCH_ZPWORD1),y
sta SCRATCH_ZPB1
+ dey
cpy #255
bne -
lda SCRATCH_ZPB1
sta ESTACK_LO,x
dex
rts
.warn "todo func_min_b"
.pend
func_min_uw .proc
@ -1208,7 +1276,7 @@ func_min_w .proc
.pend
func_min_f .proc
inx
dex
rts
.warn "todo func_min_f"
.pend
@ -1267,7 +1335,7 @@ func_rndf .proc
lda #<_rndf_rnum5
ldy #>_rndf_rnum5
jmp push_float
_rndf_rnum5 .fill 5
_rndf_rnum5 .byte 0,0,0,0,0
.pend