From 40e4cfb6860f67f1764156e91279471fd6db17ca Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 4 Feb 2021 17:47:52 +0100 Subject: [PATCH] amiga --- compiler/res/prog8lib/c64/graphics.p8 | 1 + compiler/res/prog8lib/cx16/gfx2.p8 | 32 ++++++++++++++-- examples/cx16/amiga.p8 | 6 +-- examples/line-circle-txt.p8 | 55 +-------------------------- 4 files changed, 33 insertions(+), 61 deletions(-) diff --git a/compiler/res/prog8lib/c64/graphics.p8 b/compiler/res/prog8lib/c64/graphics.p8 index 06cc99fb7..3a7fa2caf 100644 --- a/compiler/res/prog8lib/c64/graphics.p8 +++ b/compiler/res/prog8lib/c64/graphics.p8 @@ -34,6 +34,7 @@ graphics { sub line(uword @zp x1, ubyte @zp y1, uword @zp x2, ubyte @zp y2) { ; Bresenham algorithm. ; This code special-cases various quadrant loops to allow simple ++ and -- operations. + ; TODO there are some slight errors at the first/last pixels in certain slopes...?? if y1>y2 { ; make sure dy is always positive to have only 4 instead of 8 special cases swap(x1, x2) diff --git a/compiler/res/prog8lib/cx16/gfx2.p8 b/compiler/res/prog8lib/cx16/gfx2.p8 index 4d31a73e1..ae82d4d77 100644 --- a/compiler/res/prog8lib/cx16/gfx2.p8 +++ b/compiler/res/prog8lib/cx16/gfx2.p8 @@ -280,6 +280,8 @@ _done inc cx16.VERA_ADDR_L bne + inc cx16.VERA_ADDR_M ++ bne + + inc cx16.VERA_ADDR_H + inx ; next pixel }} } @@ -418,6 +420,7 @@ _done sub line(uword @zp x1, uword @zp y1, uword @zp x2, uword @zp y2, ubyte color) { ; Bresenham algorithm. ; This code special-cases various quadrant loops to allow simple ++ and -- operations. + ; TODO there are some slight errors at the first/last pixels in certain slopes... if y1>y2 { ; make sure dy is always positive to have only 4 instead of 8 special cases swap(x1, x2) @@ -860,14 +863,35 @@ _done } sub addr_mul_24_for_highres_4c(uword yy, uword xx) { - ; TODO asmsub, actually do 24 bits calc + ; TODO turn into asmsub ; 24 bits result is in r0 and r1L (highest byte) cx16.r0 = yy*128 cx16.r2 = yy*32 + xx >>= 2 - cx16.r1 = 0 - cx16.r0 += cx16.r2 - cx16.r0 += xx/4 + %asm {{ + ; add r2 and xx to r0 (24-bits) + stz cx16.r1 + clc + lda cx16.r0 + adc cx16.r2 + sta cx16.r0 + lda cx16.r0+1 + adc cx16.r2+1 + sta cx16.r0+1 + bcc + + inc cx16.r1 ++ clc + lda cx16.r0 + adc xx + sta cx16.r0 + lda cx16.r0+1 + adc xx+1 + sta cx16.r0+1 + bcc + + inc cx16.r1 ++ + }} } asmsub addr_mul_24_for_lores_256c(uword yy @R0, uword xx @AY) clobbers(A) -> uword @R0, ubyte @R1 { diff --git a/examples/cx16/amiga.p8 b/examples/cx16/amiga.p8 index 4567b2984..9f3fdace5 100644 --- a/examples/cx16/amiga.p8 +++ b/examples/cx16/amiga.p8 @@ -13,13 +13,13 @@ main { palette.set_rgb(amigacolors, len(amigacolors)) cx16.VERA_DC_VSCALE = 64 ; have the vertical resolution so it is 640*240 - more or less Amiga's default non interlaced mode - cx16.mouse_config(1, 1) ; enable mouse TODO make it an Amiga mouse pointer shape & colors if possible gfx2.text_charset(3) screen_titlebar() window_workbench() window_system() window_shell() + gfx2.text(280, 210, 1, @"640x480(240) 4 colors") gfx2.text(280, 220, 1, @"Mockup drawn using Prog8 gfx2 library") repeat { @@ -46,8 +46,8 @@ main { widget.window_bottomborder(win_x, win_y, width, height) widget.window_rightborder(win_x, win_y, width, height, false) - vector_v(win_x+width - 380, win_y+height-20) - vector_v(win_x+width - 380 -14, win_y+height-20) + vector_v(win_x+width - 390, win_y+height-20) + vector_v(win_x+width - 390 -14, win_y+height-20) widget.icon(45,40, @"Ram Disk") widget.icon(45,90, @"Workbench3.1") diff --git a/examples/line-circle-txt.p8 b/examples/line-circle-txt.p8 index 81b284127..00a7ef1f4 100644 --- a/examples/line-circle-txt.p8 +++ b/examples/line-circle-txt.p8 @@ -1,6 +1,5 @@ %import textio %import syslib -%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -8,7 +7,7 @@ main { sub start() { - txt.print("mid-point\ncircle\n and\nbresenham\nline\nalgorithms.\n") + txt.print("rectangles\nand circle\ndrawing.\n") ubyte r for r in 3 to 12 step 3 { @@ -21,16 +20,6 @@ main { txt.clear_screen() disc(20, 12, 12) - txt.print("enter for lines:") - void c64.CHRIN() - c64.CHROUT('\n') - txt.clear_screen() - - line(1, 10, 38, 24) - line(1, 20, 38, 2) - line(20, 4, 10, 24) - line(39, 16, 12, 0) - txt.print("enter for rectangles:") void c64.CHRIN() c64.CHROUT('\n') @@ -41,8 +30,6 @@ main { rect(10, 10, 10, 10, false) rect(6, 0, 16, 20, true) - test_stack.test() - sub rect(ubyte x1, ubyte y1, ubyte x2, ubyte y2, ubyte fill) { ubyte x @@ -67,46 +54,6 @@ main { } } - sub line(ubyte x1, ubyte y1, ubyte x2, ubyte y2) { - ; Bresenham algorithm, not very optimized to keep clear code. - ; For a better optimized version have a look in the graphics.p8 module. - byte d = 0 - ubyte dx = abs(x2 - x1) - ubyte dy = abs(y2 - y1) - ubyte dx2 = 2 * dx - ubyte dy2 = 2 * dy - ubyte ix = sgn(x2 as byte - x1 as byte) as ubyte - ubyte iy = sgn(y2 as byte - y1 as byte) as ubyte - ubyte x = x1 - ubyte y = y1 - - if dx >= dy { - repeat { - txt.setcc(x, y, 42, 5) - if x==x2 - return - x += ix - d += dy2 - if d > dx { - y += iy - d -= dx2 - } - } - } else { - repeat { - txt.setcc(x, y, 42, 5) - if y == y2 - return - y += iy - d += dx2 - if d > dy { - x += ix - d -= dy2 - } - } - } - } - sub circle(ubyte xcenter, ubyte ycenter, ubyte radius) { ; Midpoint algorithm ubyte x = radius