From d1d224b7fcb2f8dfa193302a1e716492400f6de1 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 22 Sep 2020 01:34:05 +0200 Subject: [PATCH] fixed print_f on cx16. Some more examples are now multi-platform. --- compiler/res/prog8lib/cx16/floats.p8 | 4 ++-- examples/arithmetic/div.p8 | 2 -- examples/arithmetic/minus.p8 | 2 -- examples/arithmetic/mult.p8 | 2 -- examples/arithmetic/plus.p8 | 2 -- examples/arithmetic/postincrdecr.p8 | 2 -- examples/hello.p8 | 28 +++++++++++++++++------- examples/mandelbrot.p8 | 32 +++++++++++++++++++++------- examples/screencodes.p8 | 9 +++----- 9 files changed, 49 insertions(+), 34 deletions(-) diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index 3df847859..ed7696dbb 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -143,8 +143,8 @@ sub print_f (float value) { jsr c64.CHROUT iny bne - - plx -+ rts ++ plx + rts }} } diff --git a/examples/arithmetic/div.p8 b/examples/arithmetic/div.p8 index 8a74ad344..28573758f 100644 --- a/examples/arithmetic/div.p8 +++ b/examples/arithmetic/div.p8 @@ -2,8 +2,6 @@ %import textio %zeropage basicsafe -; TODO fix crash on CX16 - main { sub start() { diff --git a/examples/arithmetic/minus.p8 b/examples/arithmetic/minus.p8 index 845f8da02..511fb3a11 100644 --- a/examples/arithmetic/minus.p8 +++ b/examples/arithmetic/minus.p8 @@ -2,8 +2,6 @@ %import textio %zeropage basicsafe -; TODO fix crash on CX16 - main { sub start() { diff --git a/examples/arithmetic/mult.p8 b/examples/arithmetic/mult.p8 index c1bba9f50..d12c07e1a 100644 --- a/examples/arithmetic/mult.p8 +++ b/examples/arithmetic/mult.p8 @@ -2,8 +2,6 @@ %import textio %zeropage basicsafe -; TODO fix crash on CX16 - main { sub start() { diff --git a/examples/arithmetic/plus.p8 b/examples/arithmetic/plus.p8 index cc4ff040b..d7a6788de 100644 --- a/examples/arithmetic/plus.p8 +++ b/examples/arithmetic/plus.p8 @@ -2,8 +2,6 @@ %import textio %zeropage basicsafe -; TODO fix crash on CX16 - main { sub start() { diff --git a/examples/arithmetic/postincrdecr.p8 b/examples/arithmetic/postincrdecr.p8 index 41139573e..89ec4067d 100644 --- a/examples/arithmetic/postincrdecr.p8 +++ b/examples/arithmetic/postincrdecr.p8 @@ -2,8 +2,6 @@ %import textio %zeropage basicsafe -; TODO fix crash on CX16 - main { sub start() { diff --git a/examples/hello.p8 b/examples/hello.p8 index b46059024..25e099eb2 100644 --- a/examples/hello.p8 +++ b/examples/hello.p8 @@ -3,7 +3,7 @@ %import floats %zeropage basicsafe -; TODO use RDTIM() to get the time and make this system agnostic +; Note: this program is compatible with C64 and CX16. main { @@ -18,27 +18,39 @@ main { str question = "How are you?\n" ubyte char for char in question - c64.CHROUT(char) + txt.chrout(char) ; use indexed loop to write characters str bye = "Goodbye!\n" for char in 0 to len(bye)-1 - c64.CHROUT(bye[char]) + txt.chrout(bye[char]) + ubyte time_lo + ubyte time_mid + ubyte time_hi - float clock_seconds = ((mkword(c64.TIME_MID, c64.TIME_LO) as float) + (c64.TIME_HI as float)*65536.0) / 60 + %asm {{ + stx P8ZP_SCRATCH_REG + jsr c64.RDTIM ; A/X/Y + sta time_lo + stx time_mid + sty time_hi + ldx P8ZP_SCRATCH_REG + }} + + float clock_seconds = ((mkword(time_mid, time_lo) as float) + (time_hi as float)*65536.0) / 60 float hours = floor(clock_seconds / 3600) clock_seconds -= hours*3600 float minutes = floor(clock_seconds / 60) clock_seconds = floor(clock_seconds - minutes * 60.0) - txt.print("system time in ti$ is ") + txt.print("system time (jiffy clock) is ") floats.print_f(hours) - c64.CHROUT(':') + txt.chrout(':') floats.print_f(minutes) - c64.CHROUT(':') + txt.chrout(':') floats.print_f(clock_seconds) - c64.CHROUT('\n') + txt.chrout('\n') txt.print("bye!\n") } diff --git a/examples/mandelbrot.p8 b/examples/mandelbrot.p8 index 7e7aff9b0..8f5bdef84 100644 --- a/examples/mandelbrot.p8 +++ b/examples/mandelbrot.p8 @@ -1,9 +1,8 @@ -%import syslib %import textio %import floats %zeropage basicsafe -; TODO use RDTIM() to get the time and make this system agnostic +; Note: this program is compatible with C64 and CX16. main { const uword width = 30 @@ -13,9 +12,15 @@ main { sub start() { txt.print("calculating mandelbrot fractal...") - c64.TIME_HI=0 - c64.TIME_MID=0 - c64.TIME_LO=0 + %asm {{ + stx P8ZP_SCRATCH_REG + ; reset the jiffy clock + ldx #0 + ldy #0 + lda #0 + jsr c64.SETTIM + ldx P8ZP_SCRATCH_REG + }} ubyte pixelx ubyte pixely @@ -43,9 +48,20 @@ main { } } - float duration = ((c64.TIME_LO as float) - + 256.0*(c64.TIME_MID as float) - + 65536.0*(c64.TIME_HI as float))/60.0 + ubyte time_lo + ubyte time_mid + ubyte time_hi + + %asm {{ + stx P8ZP_SCRATCH_REG + jsr c64.RDTIM ; A/X/Y + sta time_lo + stx time_mid + sty time_hi + ldx P8ZP_SCRATCH_REG + }} + + float duration = ((mkword(time_mid, time_lo) as float) + (time_hi as float)*65536.0) / 60 txt.plot(0, 21) txt.print("finished in ") floats.print_f(duration) diff --git a/examples/screencodes.p8 b/examples/screencodes.p8 index 5df2db2f9..2b2439746 100644 --- a/examples/screencodes.p8 +++ b/examples/screencodes.p8 @@ -1,8 +1,7 @@ -%target c64 %import textio %zeropage basicsafe -; TODO use setcc instead of poking screen ram directly to make this cross-system +; Note: this program is compatible with C64 and CX16. main { @@ -16,16 +15,14 @@ main { txt.print("\n\n\n\nString output via print:\n") txt.print("petscii-str: ") txt.print(s1) - txt.print("\nscrcode-str: ") - txt.print(s2) txt.print("\n\nThe top two screen lines are set via screencodes.\n") ubyte i for i in 0 to len(s1)-1 - @($0400+i) = s1[i] + txt.setchr(i, 0, s1[i]) for i in 0 to len(s2)-1 - @($0400+40+i) = s2[i] + txt.setchr(i, 1, s2[i]) ubyte c1 = 'z' ubyte c2 = @'z'