From 63a4525f06a3207fa56b6dba4166c8a8de0416c3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 30 Mar 2024 22:29:13 +0100 Subject: [PATCH 1/4] remove hacks from floats.parse now that kernal R47 is out --- compiler/res/prog8lib/cx16/floats.p8 | 20 +++++--------------- docs/source/todo.rst | 1 - 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index cee961814..4300badad 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -136,14 +136,12 @@ asmsub FREADUY (ubyte value @Y) { } asmsub parse(str value @AY) -> float @FAC1 { - ; -- parse a string value of a number to float in FAC1 - ; warning: on older float @FAC1 { ply plx jmp VAL_1 -+ sta $a9 ; 'index' variable - sty $aa - jsr prog8_lib.strlen - lda $deb6 - cmp #$d0 ; sanity check for kernal routine correct - bne + - tya - jmp $deb6 ; kernal version dependent... -+ ; print error message if routine is borked in kernal, and exit program +_borked ldy #0 - lda _msg,y beq + @@ -168,7 +158,7 @@ asmsub parse(str value @AY) -> float @FAC1 { bne - + jmp sys.exit -_msg .text 13,"?val kaputt",13,0 +_msg .text 13,"?rom 47+ required for val1",13,0 }} } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index de4be414b..c0709bb74 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -51,7 +51,6 @@ Compiler: Libraries: - gfx2: add EOR mode support like in monogfx and see PAINT for inspiration. Self modifying code to keep it optimized? -- once kernal rom v47 is released, remove most of the workarounds in cx16 floats.parse_f() . Prototype parse routine in examples/cx16/floatparse.p8 - fix the problems in atari target, and flesh out its libraries. - c128 target: make syslib more complete (missing kernal routines)? - pet32 target: make syslib more complete (missing kernal routines)? From b385dc8c268a7038a59071ccde54d5e134891a27 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 2 Apr 2024 01:45:10 +0200 Subject: [PATCH 2/4] add cx16 extapi ROM call, call numbers and shims. (new in Rom R47) --- compiler/res/prog8lib/cx16/syslib.p8 | 72 ++++++++++++++++++++++++++++ examples/test.p8 | 30 ++---------- 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index dcef671ea..9e35f0eeb 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -425,6 +425,9 @@ romsub $ff1d = FB_move_pixels(uword sx @R0, uword sy @R1, uword tx @R2, uword ty romsub $FEBA = BSAVE(ubyte zp_startaddr @ A, uword endaddr @ XY) clobbers (X, Y) -> bool @ Pc, ubyte @ A ; like cbm.SAVE, but omits the 2-byte prg header romsub $fec6 = i2c_read_byte(ubyte device @X, ubyte offset @Y) clobbers (X,Y) -> ubyte @A, bool @Pc romsub $fec9 = i2c_write_byte(ubyte device @X, ubyte offset @Y, ubyte data @A) clobbers (A,X,Y) -> bool @Pc +romsub $feb4 = i2c_batch_read(ubyte device @X, uword buffer @R0, uword length @R1, bool advance @Pc) clobbers(A,Y) -> bool @Pc +romsub $feb7 = i2c_batch_write(ubyte device @X, uword buffer @R0, uword length @R1, bool advance @Pc) clobbers(A,Y) -> bool @Pc + romsub $fef0 = sprite_set_image(uword pixels @R0, uword mask @R1, ubyte bpp @R2, ubyte number @A, ubyte width @X, ubyte height @Y, bool apply_mask @Pc) clobbers(A,X,Y) -> bool @Pc romsub $fef3 = sprite_set_position(uword x @R0, uword y @R1, ubyte number @A) clobbers(A,X,Y) romsub $fee4 = memory_fill(uword address @R0, uword num_bytes @R1, ubyte value @A) clobbers(A,X,Y) @@ -437,6 +440,8 @@ romsub $fee1 = console_get_char() clobbers(X,Y) -> ubyte @A romsub $fed8 = console_put_image(uword pointer @R0, uword width @R1, uword height @R2) clobbers(A,X,Y) romsub $fed5 = console_set_paging_message(uword msgptr @R0) clobbers(A,X,Y) romsub $fecf = entropy_get() -> ubyte @A, ubyte @X, ubyte @Y +;; romsub $fea8 = extapi16(ubyte callnumber @A) clobbers (A,X,Y) ; not useful yet because is for 65816 cpu +romsub $feab = extapi(ubyte callnumber @A) clobbers (A,X,Y) romsub $fecc = monitor() clobbers(A,X,Y) romsub $ff44 = MACPTR(ubyte length @A, uword buffer @XY, bool dontAdvance @Pc) clobbers(A) -> bool @Pc, uword @XY @@ -524,6 +529,27 @@ romsub $C099 = ym_getatten(ubyte channel @A) clobbers(Y) -> ubyte @X romsub $C09C = ym_getpan(ubyte channel @A) clobbers(Y) -> ubyte @X romsub $C0A5 = ym_get_chip_type() clobbers(X) -> ubyte @A +; extapi call numbers +const ubyte EXTAPI_clear_status = $01 +const ubyte EXTAPI_getlfs = $02 +const ubyte EXTAPI_mouse_sprite_offset = $03 +const ubyte EXTAPI_joystick_ps2_keycodes = $04 +const ubyte EXTAPI_iso_cursor_char = $05 +const ubyte EXTAPI_ps2kbd_typematic = $06 +const ubyte EXTAPI_pfkey = $07 +const ubyte EXTAPI_ps2data_fetch = $08 +const ubyte EXTAPI_ps2data_raw = $09 +const ubyte EXTAPI_cursor_blink = $0A +const ubyte EXTAPI_led_update = $0B +const ubyte EXTAPI_mouse_set_position = $0C + +; extapi16 call numbers +const ubyte EXTAPI16_test = $00 +const ubyte EXTAPI16_stack_push = $01 +const ubyte EXTAPI16_stack_pop = $02 +const ubyte EXTAPI16_stack_enter_kernal_stack = $03 +const ubyte EXTAPI16_stack_leave_kernal_stack = $04 + asmsub set_screen_mode(ubyte mode @A) clobbers(A,X,Y) -> bool @Pc { ; -- convenience wrapper for screen_mode() to just set a new mode (and return success) @@ -564,6 +590,52 @@ asmsub mouse_pos() clobbers(X) -> ubyte @A { }} } +; shims for the kernal routines called via the extapi call: + +asmsub mouse_set_pos(uword xpos @R0, uword ypos @R1) clobbers(X) { + ; -- sets the mouse sprite position + %asm {{ + ldx #cx16.r0L + lda #EXTAPI_mouse_set_position + jmp cx16.extapi + }} +} + +asmsub mouse_set_sprite_offset(word xoffset @R0, word yoffset @R1) clobbers(A,X,Y) { + %asm {{ + clc + lda #EXTAPI_mouse_sprite_offset + jmp cx16.extapi + }} +} + +asmsub mouse_get_sprite_offset() clobbers(A,X,Y) -> word @R0, word @R1 { + %asm {{ + sec + lda #EXTAPI_mouse_sprite_offset + jmp cx16.extapi + }} +} + +asmsub getlfs() -> ubyte @X, ubyte @A, ubyte @Y { + ; -- return the result of the last call to SETLFS: A=logical, X=device, Y=secondary. + %asm {{ + lda #EXTAPI_mouse_set_position + jmp cx16.extapi + }} +} + +asmsub iso_cursor_char(ubyte character @X) clobbers(A,X,Y) { + ; -- set the screen code for the cursor character in ISO mode (the default is $9f). + %asm {{ + clc + lda #EXTAPI_iso_cursor_char + jmp cx16.extapi + }} +} + +; TODO : implement shims for the remaining extapi calls. + ; ---- end of kernal routines ---- diff --git a/examples/test.p8 b/examples/test.p8 index b055c3bcd..71bd6529c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,5 +1,5 @@ %import textio -%import conv +%import diskio %zeropage basicsafe %option no_sysinit @@ -7,31 +7,7 @@ main { sub start() { - repeat 40 txt.nl() - txt.print("int to string tests\n\n") - - for cx16.r0L in 0 to 255 { - txt.print_ub0(cx16.r0L) - txt.spc() - txt.spc() - } - txt.nl() - txt.nl() - for cx16.r0L in 0 to 255 { - txt.print_ub(cx16.r0L) - txt.spc() - txt.spc() - } - txt.nl() - txt.nl() - for cx16.r0sL in -128 to 127 { - txt.print_b(cx16.r0sL) - txt.spc() - txt.spc() - } - txt.nl() - txt.nl() - - repeat {} + txt.iso() + cx16.iso_cursor_char(iso:'_') } } From 9af4168ae246d40a78e3b7962061b487b03ca303 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 2 Apr 2024 22:17:51 +0200 Subject: [PATCH 3/4] cx16: added diskio.fastmode() to select the fast serial disk mode for the SD card --- compiler/res/prog8lib/cx16/diskio.p8 | 11 +++++++++++ examples/cx16/chunkedfile/demo.p8 | 1 + examples/cx16/diskspeed.p8 | 14 +++++++++----- examples/cx16/pcmaudio/stream-wav.p8 | 1 + examples/cx16/showbmx.p8 | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/compiler/res/prog8lib/cx16/diskio.p8 b/compiler/res/prog8lib/cx16/diskio.p8 index afc782221..afa2639eb 100644 --- a/compiler/res/prog8lib/cx16/diskio.p8 +++ b/compiler/res/prog8lib/cx16/diskio.p8 @@ -32,6 +32,17 @@ diskio { cbm.CHKOUT(WRITE_IO_CHANNEL) } + sub fastmode(ubyte mode) { + ; -- set fast serial mode (0=none, 1=auto_tx, 2=fast writes, 3=both) for the SD card + list_filename[0] = 'u' + list_filename[1] = '0' + list_filename[2] = '>' + list_filename[3] = 'b' + list_filename[4] = mode | $30 + list_filename[5] = 0 + send_command(list_filename) + } + sub directory() -> bool { ; -- Prints the directory contents to the screen. Returns success. diff --git a/examples/cx16/chunkedfile/demo.p8 b/examples/cx16/chunkedfile/demo.p8 index 2a91fa327..88deea080 100644 --- a/examples/cx16/chunkedfile/demo.p8 +++ b/examples/cx16/chunkedfile/demo.p8 @@ -9,6 +9,7 @@ main { uword duration ubyte[256] bonkbuffer + ;; diskio.fastmode(1) set_screen_mode() cbm.SETTIM(0,0,0) diff --git a/examples/cx16/diskspeed.p8 b/examples/cx16/diskspeed.p8 index 02befc738..af51e716b 100644 --- a/examples/cx16/diskspeed.p8 +++ b/examples/cx16/diskspeed.p8 @@ -8,8 +8,6 @@ main { const ubyte HIRAM_START_BANK = 4 uword large = memory("large", 20000, 256) - bool verify = false - ubyte[256] buffer = 0 to 255 uword @zp buf_ptr @@ -17,10 +15,11 @@ main { txt.print("\n\ndisk benchmark on drive 8.\n") txt.print("with verification? y/n: ") - cx16.r0L = cbm.CHRIN() + bool verify = cbm.CHRIN()=='y' + txt.print("\nfast serial mode r+w? y/n: ") + bool fastserial = cbm.CHRIN()=='y' txt.nl() - if cx16.r0L=='y' { - verify=true + if verify { ; fill the buffers with random data, and calculate the checksum for cx16.r0 in 0 to 19999 { large[cx16.r0] = math.rnd() @@ -33,6 +32,11 @@ main { uword crc32_h = cx16.r15 } + if fastserial + diskio.fastmode(3) + else + diskio.fastmode(0) + test_save() test_save_blocks() test_load_hiram() diff --git a/examples/cx16/pcmaudio/stream-wav.p8 b/examples/cx16/pcmaudio/stream-wav.p8 index cb5555249..446cf60c8 100644 --- a/examples/cx16/pcmaudio/stream-wav.p8 +++ b/examples/cx16/pcmaudio/stream-wav.p8 @@ -29,6 +29,7 @@ main { ubyte vera_rate sub start() { + ;; diskio.fastmode(1) txt.print("name of .wav file to play on drive 8: ") while 0==txt.input_chars(MUSIC_FILENAME) { ; until user types a name... diff --git a/examples/cx16/showbmx.p8 b/examples/cx16/showbmx.p8 index 7d9a7348b..ed944032f 100644 --- a/examples/cx16/showbmx.p8 +++ b/examples/cx16/showbmx.p8 @@ -12,6 +12,7 @@ main { str filename = "?"*40 repeat { + ;; diskio.fastmode(1) txt.print("\nenter bmx image filename: ") if txt.input_chars(&filename)!=0 { From 385dd6fc23f128825e013caf556f42efc1611a28 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 3 Apr 2024 01:12:45 +0200 Subject: [PATCH 4/4] todos --- docs/source/todo.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index c0709bb74..b66ba801e 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -8,7 +8,6 @@ Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ Compiler: -- IR: add TEST instruction to test memory content and set N/Z flags, without affecting any register. Replace all LOADM+CMPI #0 / LOAD #0+LOADM+CMP+BRANCH by this instruction - IR: implement missing operators in AssignmentGen (array shifts etc) - can we support signed % (remainder) somehow? - instead of copy-pasting inline asmsubs, make them into a 64tass macro and use that instead. @@ -43,9 +42,10 @@ Compiler: But all library code written in asm uses .proc already..... (textual search/replace when writing the actual asm?) Once new codegen is written that is based on the IR, this point is mostly moot anyway as that will have its own dead code removal on the IR level. - Zig-like try-based error handling where the V flag could indicate error condition? and/or BRK to jump into monitor on failure? (has to set BRK vector for that) But the V flag is also set on certain normal instructions +- Zig-like defer to execute a statement/anonymousscope at subroutine exit? - generate WASM to eventually run prog8 on a browser canvas? Use binaryen toolkit and/or my binaryen kotlin library? -- split words arrays all() -- split words arrays sort() +- implement split words arrays all() +- implement split words arrays sort() Libraries: