From a2be42c5ca834d9299de4997e6bc3214b3fd0735 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 4 Jan 2025 01:36:47 +0100 Subject: [PATCH] txt.get_cursor() now returns the column and row as 2 values, no longer requires 2 pointer arguments --- compiler/res/prog8lib/atari/textio.p8 | 13 +++- compiler/res/prog8lib/c128/textio.p8 | 12 +-- compiler/res/prog8lib/c64/textio.p8 | 12 +-- compiler/res/prog8lib/cx16/textio.p8 | 14 ++-- docs/source/todo.rst | 13 +--- examples/test.p8 | 101 +++----------------------- 6 files changed, 42 insertions(+), 123 deletions(-) diff --git a/compiler/res/prog8lib/atari/textio.p8 b/compiler/res/prog8lib/atari/textio.p8 index fece5f65e..16090b65b 100644 --- a/compiler/res/prog8lib/atari/textio.p8 +++ b/compiler/res/prog8lib/atari/textio.p8 @@ -392,9 +392,16 @@ sub plot(ubyte col, ubyte rownum) { row(rownum) } -sub get_cursor(uword colptr, uword rowptr) { - @(colptr) = get_column() - @(rowptr) = get_row() +asmsub get_cursor() -> ubyte @X, ubyte @Y { + %asm {{ + jsr get_column + pha + jsr get_row + tay + pla + tax + rts + }} } asmsub waitkey() -> ubyte @A { diff --git a/compiler/res/prog8lib/c128/textio.p8 b/compiler/res/prog8lib/c128/textio.p8 index 7e836d8e1..4b316f1e6 100644 --- a/compiler/res/prog8lib/c128/textio.p8 +++ b/compiler/res/prog8lib/c128/textio.p8 @@ -81,15 +81,15 @@ asmsub get_row() -> ubyte @X { }} } -sub get_cursor(uword colptr, uword rowptr) { +asmsub get_cursor() -> ubyte @X, ubyte @Y { %asm {{ sec - jsr cbm.PLOT + jsr cbm.PLOT + stx P8ZP_SCRATCH_REG ; swap X and Y tya - ldy #$00 - sta (colptr),y - txa - sta (rowptr),y + tax + ldy P8ZP_SCRATCH_REG + rts }} } diff --git a/compiler/res/prog8lib/c64/textio.p8 b/compiler/res/prog8lib/c64/textio.p8 index d531c761c..ed557db78 100644 --- a/compiler/res/prog8lib/c64/textio.p8 +++ b/compiler/res/prog8lib/c64/textio.p8 @@ -86,15 +86,15 @@ asmsub get_row() -> ubyte @X { }} } -sub get_cursor(uword colptr, uword rowptr) { +asmsub get_cursor() -> ubyte @X, ubyte @Y { %asm {{ sec - jsr cbm.PLOT + jsr cbm.PLOT + stx P8ZP_SCRATCH_REG ; swap X and Y tya - ldy #$00 - sta (colptr),y - txa - sta (rowptr),y + tax + ldy P8ZP_SCRATCH_REG + rts }} } diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index b1ac7109e..b984fc1bd 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -81,15 +81,15 @@ asmsub get_row() -> ubyte @X { }} } -sub get_cursor(uword colptr, uword rowptr) { +asmsub get_cursor() -> ubyte @X, ubyte @Y { %asm {{ sec - jsr cbm.PLOT - tya - ldy #$00 - sta (colptr),y - txa - sta (rowptr),y + jsr cbm.PLOT + phx ; swap X and Y + phy + plx + ply + rts }} } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 383dbd044..a0202551f 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -- textio.get_cursor() should just return 2 bytes (rewrite it as asmsub...) - - add paypal donation button as well? - announce prog8 on the 6502.org site? @@ -48,7 +46,9 @@ Future Things and Ideas IR/VM ----- - getting it in shape for code generation...: the IR file should be able to encode every detail about a prog8 program (the VM doesn't have to actually be able to run all of it though!) -- add BZ and BNZ instructions? To replace CMPI #0 + Branch? +- split word arrays, both _msb and _lsb arrays are tagged with an alignment. This is not what's intended; only the one put in memory first should be aligned (the other one should follow straight after it) +- fix call() return value handling +- proper code gen for the CALLI instruction and that it (optionally) returns a word value that needs to be assigned to a reg - implement fast code paths for TODO("inplace split.... - implement more TODOs in AssignmentGen - sometimes source lines end up missing in the output p8ir, for example the first assignment is gone in: @@ -56,17 +56,12 @@ IR/VM cx16.r0L = cx16.r1 as ubyte cx16.r0sL = cx16.r1s as byte } -- implement missing operators in AssignmentGen (array shifts etc) -- fix call() return value handling -- try to get rid of LSIG opcode again (but this will introduce byte reads from word typed registers...) -- proper code gen for the CALLI instruction and that it (optionally) returns a word value that needs to be assigned to a reg +- add more optimizations in IRPeepholeOptimizer - idea: (but LLVM IR simply keeps the variables, so not a good idea then?...): replace all scalar variables by an allocated register. Keep a table of the variable to register mapping (including the datatype) global initialization values are simply a list of LOAD instructions. Variables replaced include all subroutine parameters! So the only variables that remain as variables are arrays and strings. -- add more optimizations in IRPeepholeOptimizer - the @split arrays are currently also split in _lsb/_msb arrays in the IR, and operations take multiple (byte) instructions that may lead to verbose and slow operation and machine code generation down the line. maybe another representation is needed once actual codegeneration is done from the IR...? -- split word arrays, both _msb and _lsb arrays are tagged with an alignment. This is not what's intended; only the one put in memory first should be aligned (the other one should follow straight after it) - ExpressionCodeResult: get rid of the separation between single result register and multiple result registers? maybe not, this requires hundreds of lines to change diff --git a/examples/test.p8 b/examples/test.p8 index 6e2dc0f6a..24fb36635 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,102 +4,19 @@ main { sub start() { - uword[] @nosplit arr = [ %01000010_01000010 , %01000010_01000010, %01000010_01000010 ] - uword[] @split arrsplit = [ %01000010_01000010 , %01000010_01000010, %01000010_01000010 ] + txt.print("\n\n\n\n\n\n !") - ubyte[] arrb = [ %01000010 , %01000010, %01000010 ] + ubyte column, row - ; expected $09 - arrb[2] = $12 - arrb[2] >>= 1 - txt.print_ubhex(arrb[2], true) + column, row = txt.get_cursor() + txt.nl() + txt.print_ub(column) + txt.spc() + txt.print_ub(row) txt.nl() - ; expected $091a - arr[2] = $1234 - arr[2] >>= 1 - txt.print_uwhex(arr[2], true) - txt.nl() - ; expected $02 - arrb[2] = $12 - arrb[2] >>= 3 - txt.print_ubhex(arrb[2], true) - txt.nl() - - ; expected $0246 - arr[2] = $1234 - arr[2] >>= 3 - txt.print_uwhex(arr[2], true) - txt.nl() - -; arr[2] >>= 1 -; txt.print_uwhex(arr[2], true) -; txt.nl() - - ; expected $091a - arrsplit[2] = $1234 - arrsplit[2] >>= 1 - txt.print_uwhex(arrsplit[2], true) - txt.nl() - ; expected $0246 - arrsplit[2] = $1234 - arrsplit[2] >>= 3 - txt.print_uwhex(arrsplit[2], true) - txt.nl() - -; arrsplit[2] >>= 1 -; txt.print_uwhex(arrsplit[2], true) -; txt.nl() - -; uword wv = %01000010_01000010 -; -; ; expected: $8484 $4242 -; sys.set_carry() -; rol(wv) -; txt.print_uwhex(wv, true) -; sys.set_carry() -; ror(wv) -; txt.print_uwhex(wv, true) -; txt.nl() -; -; wv = %01000010_01000010 -; sys.set_carry() -; rol2(wv) -; txt.print_uwhex(wv, true) -; sys.set_carry() -; ror2(wv) -; txt.print_uwhex(wv, true) -; txt.nl() -; -; sys.set_carry() -; rol(arr[2]) -; txt.print_uwhex(arr[2], true) -; sys.set_carry() -; ror(arr[2]) -; txt.print_uwhex(arr[2], true) -; txt.nl() -; sys.set_carry() -; rol2(arr[1]) -; txt.print_uwhex(arr[1], true) -; sys.set_carry() -; ror2(arr[1]) -; txt.print_uwhex(arr[1], true) -; txt.nl() -; -; sys.set_carry() -; rol(arrsplit[2]) -; txt.print_uwhex(arrsplit[2], true) -; sys.set_carry() -; ror(arrsplit[2]) -; txt.print_uwhex(arrsplit[2], true) -; txt.nl() -; sys.set_carry() -; rol2(arrsplit[1]) -; txt.print_uwhex(arrsplit[1], true) -; sys.set_carry() -; ror2(arrsplit[1]) -; txt.print_uwhex(arrsplit[1], true) -; txt.nl() + repeat { + } } }