From f4f355c74abf5dbd23ff97938779cf77a984dc9c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 14 Nov 2022 17:55:55 +0100 Subject: [PATCH] added cx16/diskspeed example --- compiler/res/prog8lib/diskio.p8 | 4 +- compiler/test/TestCompilerOnExamples.kt | 4 + examples/cx16/diskspeed.p8 | 112 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 examples/cx16/diskspeed.p8 diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 4ed29f4e3..b4b872548 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -394,7 +394,7 @@ _end rts c64.SETLFS(14, drivenumber, 1) void c64.OPEN() ; open 14,8,1,"filename" if_cc { - void c64.CHKOUT(14) ; use #14 as input channel + void c64.CHKOUT(14) ; use #14 as output channel return not c64.READST() } f_close_w() @@ -404,7 +404,7 @@ _end rts sub f_write(uword bufferpointer, uword num_bytes) -> bool { ; -- write the given umber of bytes to the currently open file if num_bytes!=0 { - void c64.CHKOUT(14) ; use #14 as input channel again + void c64.CHKOUT(14) ; use #14 as output channel again repeat num_bytes { c64.CHROUT(@(bufferpointer)) bufferpointer++ diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 17b0768f2..e3a4f6126 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -99,14 +99,18 @@ class TestCompilerOnExamplesCx16: FunSpec({ "circles", "cobramk3-gfx", "colorbars", + "cube3d", "datetime", + "diskspeed", "highresbitmap", "kefrenbars", + "keyboardhandler", "mandelbrot", "mandelbrot-gfx-colors", "multipalette", "rasterbars", "sincos", + "snow", "tehtriz", "testgfx2", ), diff --git a/examples/cx16/diskspeed.p8 b/examples/cx16/diskspeed.p8 new file mode 100644 index 000000000..2bdefcb34 --- /dev/null +++ b/examples/cx16/diskspeed.p8 @@ -0,0 +1,112 @@ +%import diskio +%import cx16diskio +%import floats +%zeropage basicsafe +%option no_sysinit + +main { + + ubyte[256] buffer = 0 to 255 + const ubyte REPEATS = 2 + + sub print_speed(uword jiffies) { + float speed = 65536.0 * REPEATS / (jiffies as float / 60.0) + txt.nl() + txt.print_uw(jiffies) + txt.print(" jiffies = ") + floats.print_f(speed) + txt.print(" bytes/sec\n") + } + + sub start() { + txt.print("\n\ndisk benchmark. repeats = ") + txt.print_ub(REPEATS) + + uword batchtotaltime + + txt.print("\n\nwriting 64kb using save") + batchtotaltime = 0 + repeat REPEATS { + c64.SETTIM(0,0,0) + void diskio.save(8, "@:benchmark.dat", $100, 32768) + void diskio.save(8, "@:benchmark.dat", $100, 32768) + batchtotaltime += c64.RDTIM16() + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.print("\nwriting 64kb sequentially") + batchtotaltime = 0 + repeat REPEATS { + if diskio.f_open_w(8, "@:benchmark.dat") { + c64.SETTIM(0,0,0) + repeat 65536/256 { + if not diskio.f_write(buffer, 256) + sys.exit(1) + } + batchtotaltime += c64.RDTIM16() + diskio.f_close_w() + } + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.print("\nreading 64kb using load into hiram") + batchtotaltime = 0 + repeat REPEATS { + c64.SETTIM(0,0,0) + if not cx16diskio.load(8, "benchmark.dat", 4, $a000) + sys.exit(1) + batchtotaltime += c64.RDTIM16() + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.print("\nreading 64kb using vload into videoram") + batchtotaltime = 0 + repeat REPEATS { + c64.SETTIM(0,0,0) + if not cx16diskio.vload("benchmark.dat", 8, 0, $0000) + sys.exit(1) + batchtotaltime += c64.RDTIM16() + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.print("\nreading 64kb sequentially") + batchtotaltime = 0 + repeat REPEATS { + if diskio.f_open(8, "benchmark.dat") { + c64.SETTIM(0,0,0) + repeat 65536/255 { + if not diskio.f_read(buffer, 255) + sys.exit(1) + } + batchtotaltime += c64.RDTIM16() + diskio.f_close() + } + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.print("\nreading 64kb sequentially (x16 optimized)") + batchtotaltime = 0 + repeat REPEATS { + if diskio.f_open(8, "benchmark.dat") { + c64.SETTIM(0,0,0) + repeat 65536/255 { + if not cx16diskio.f_read(buffer, 255) + sys.exit(1) + } + batchtotaltime += c64.RDTIM16() + diskio.f_close() + } + txt.chrout('.') + } + print_speed(batchtotaltime) + + txt.nl() + txt.print(diskio.status(8)) + txt.print("\ndone.\n") + } +}