Skip to content

Commit

Permalink
added sprites.getxy()
Browse files Browse the repository at this point in the history
fix compiler crash on return xxx,yyy  when symbol is not defined
  • Loading branch information
irmen committed Jan 10, 2025
1 parent 2ab2130 commit 4f096a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 49 deletions.
8 changes: 8 additions & 0 deletions compiler/res/prog8lib/cx16/sprites.p8
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ sprites {
return mkword(cx16.vpeek(1, sprite_reg+1), cx16.vpeek(1, sprite_reg)) as word
}

sub getxy(ubyte spritenum) -> word, word {
sprite_reg = VERA_SPRITEREGS + 2 + spritenum*$0008
cx16.r0s = mkword(cx16.vpeek(1, sprite_reg+1), cx16.vpeek(1, sprite_reg)) as word
sprite_reg += 2
cx16.r1s = mkword(cx16.vpeek(1, sprite_reg+1), cx16.vpeek(1, sprite_reg)) as word
return cx16.r0s, cx16.r1s
}

sub hide(ubyte spritenum) {
cx16.vpoke_and(1, VERA_SPRITEREGS + 6 + spritenum*$0008, %11110011)
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/prog8/compiler/ErrorReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ internal class ErrorReporter(val colors: IConsoleColors): IErrorReporter {

// For undefined symbol errors, remove all other errors and warnings on the same source line,
// because those are very likely caused by the unknown symbol. This reduces error clutter.
val undefinedSymbolErrors = messages.filter { it.severity == MessageSeverity.ERROR && it.message.contains("undefined symbol") }
val undefinedSymbolErrors = messages
.asSequence()
.filter { it.severity == MessageSeverity.ERROR && it.message.contains("undefined symbol") }
.map { it to (it.position.file to it.position.line)}
.groupBy { it.second }
.map { it.value.first().first }

for(e in undefinedSymbolErrors) {
messages.removeIf {
it !== e
Expand Down
3 changes: 1 addition & 2 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO
====

- change library routines that now return 1 value + say, another in R0, to just return 2 values now that this is supported for normal subroutines too.

- add paypal donation button as well?
- announce prog8 on the 6502.org site?

Expand All @@ -13,6 +11,7 @@ Future Things and Ideas
^^^^^^^^^^^^^^^^^^^^^^^

- Kotlin: can we use inline value classes in certain spots?
- allow multi-value variable initialization (var a,b,c = 1,2,3)
- Improve the SublimeText syntax file for prog8, you can also install this for 'bat': https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions
- Compiling Libraries: improve ability to create library files in prog8; for instance there's still stuff injected into the start of the start() routine AND there is separate setup logic going on before calling it.
Make up our mind! Maybe all setup does need to be put into start() ? because the program cannot function correctly when the variables aren't initialized properly bss is not cleared etc. etc.
Expand Down
67 changes: 21 additions & 46 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,57 +1,32 @@
%import textio
%import sprites
%option no_sysinit
%zeropage basicsafe


main {
sub start() {
uword a
ubyte b
bool c
a=9999
b=255
c=false
a, b, c = multi()
txt.print_uw(a)
txt.spc()
txt.print_uw(b)
txt.spc()
txt.print_bool(c)
txt.nl()
a=9999
b=255
c=false
a, void, c = multi()
txt.print_uw(a)
txt.spc()
txt.print_uw(b)
txt.spc()
txt.print_bool(c)
txt.nl()
a=9999
b=255
c=false
void, b, c = multi()
txt.print_uw(a)
txt.spc()
txt.print_uw(b)
txt.spc()
txt.print_bool(c)
txt.nl()
a=9999
b=255
c=false
void multi()
txt.print_uw(a)
txt.spc()
txt.print_uw(b)
txt.spc()
txt.print_bool(c)
txt.nl()

cx16.mouse_config2(1)

sprites.init(1, 0, 0, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16, 0)

sprites.pos(1, 100, 100)

repeat {
word x,y
x,y = sprites.getxy(0)
sprites.pos(1, x, y)
}

cx16.r0L = single()
cx16.r0L, cx16.r1L = multi()
}

sub single() -> ubyte {
return xx
}

sub multi() -> uword, ubyte, bool {
return 12345, 66, true
sub multi() -> ubyte, ubyte {
return xx, yy
}
}

0 comments on commit 4f096a7

Please sign in to comment.