From 6454bf8ec48a54681d776d93fc7f4d61bb3de67d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 16 Aug 2022 03:50:36 +0200 Subject: [PATCH] added mouse cursor to amiga example slightly sped up text rendering in gfx2 highres mode --- compiler/res/prog8lib/cx16/gfx2.p8 | 17 +++++++----- docs/source/todo.rst | 1 + examples/cx16/amiga.p8 | 43 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/compiler/res/prog8lib/cx16/gfx2.p8 b/compiler/res/prog8lib/cx16/gfx2.p8 index c8809703f..7bab3287d 100644 --- a/compiler/res/prog8lib/cx16/gfx2.p8 +++ b/compiler/res/prog8lib/cx16/gfx2.p8 @@ -844,25 +844,28 @@ _done } 6 -> { ; hires 4c + ; we're going to use a few cx16 registers to make sure every variable is in zeropage in the inner loop. + cx16.r11L = color + cx16.r8 = y while @(sctextptr) { chardataptr = charset_addr + (@(sctextptr) as uword)*8 repeat 8 { ; TODO rewrite this inner loop partly in assembly ; requires expanding the charbits to 2-bits per pixel (based on color) ; also it's way more efficient to draw whole horizontal spans instead of per-character - ubyte charbits = cx16.vpeek(charset_bank, chardataptr) + cx16.r9L = cx16.vpeek(charset_bank, chardataptr) ; get the 8 horizontal character bits + cx16.r7 = x repeat 8 { - charbits <<= 1 + cx16.r9L <<= 1 if_cs - plot(x, y, color) - x++ + plot(cx16.r7, cx16.r8, cx16.r11L) + cx16.r7++ } - x-=8 chardataptr++ - y++ + cx16.r8++ } x+=8 - y-=8 + cx16.r8-=8 sctextptr++ } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 21835dd49..5a5318e5f 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ +- check that subs with single integer arg are passing that in A or AY (and the sub itself stores it in the parameter variable) - vm: intermediate code: don't flatten everything. Instead, as a new intermediary step, convert the new Ast into *structured* intermediary code. Basically keep the blocks and subroutines structure, including full subroutine signature information, diff --git a/examples/cx16/amiga.p8 b/examples/cx16/amiga.p8 index 89f34c47a..a1aacbbf6 100644 --- a/examples/cx16/amiga.p8 +++ b/examples/cx16/amiga.p8 @@ -9,6 +9,8 @@ main { sub start() { gfx2.screen_mode(6) ; select 640*480 mode, 4 colors + mouse.set_pointer_image() + cx16.mouse_config(-1, 640/8, 240/8) uword[4] amigacolors = [$aaa, $000, $fff, $68c] ; gray, black, white, lightblue palette.set_rgb(amigacolors, len(amigacolors)) @@ -99,7 +101,48 @@ main { } } +mouse { + sub set_pointer_image() { + const uword sprite_data_addr = $a000 + const ubyte palette_offset = 16 + ; sprite registers base in VRAM: $1fc00 + ; Sprite 0: $1FC00 - $1FC07 ; used by the kernal for mouse pointer + cx16.vpoke(1, $fc00, lsb(sprite_data_addr >> 5)) ; sprite data ptr bits 5-12 + cx16.vpoke(1, $fc01, msb(sprite_data_addr >> 5)) ; mode bit (16 colors = 4 bpp) and sprite dataptr bits 13-16 + cx16.vpoke(1, $fc07, %01100000 | palette_offset>>4) ; 32x16 pixels (non-square...), palette offset + ubyte ix + for ix in 0 to 255 { + cx16.vpoke(0, sprite_data_addr+ix, mousecursor[ix]) + } + + palette.set_color(palette_offset + %1111, $f00) + palette.set_color(palette_offset + %1010, $fff) + palette.set_color(palette_offset + %0101, $000) + + ubyte[256] mousecursor = [ + ; The Amiga Workbench 3.0 mouse cursor sprite image. + ; note that the sprite resolution is 32x16 (non-square pixels) because it follows the bitmap screen resolution + ; %1111 = red, %1010 = white, %0101 = black, %0000 = transparent + %11111111,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %01010101,%11111111,%10101010,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%01010101,%11111111,%11111111,%10101010,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%01010101,%11111111,%11111111,%11111111,%11111111,%10101010,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%01010101,%11111111,%11111111,%11111111,%11111111,%11111111,%10101010,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%01010101,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%01010101,%11111111,%11111111,%11111111,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%01010101,%11111111,%11111111,%01010101,%11111111,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%01010101,%11111111,%00000000,%01010101,%11111111,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%01010101,%11111111,%00000000,%00000000,%01010101,%11111111,%10101010,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01010101,%11111111,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000, + %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000 + ] + } +} widget {