diff --git a/compiler/res/prog8lib/cx16/monogfx.p8 b/compiler/res/prog8lib/cx16/monogfx.p8 index 1dab3fab7..662d5bd6d 100644 --- a/compiler/res/prog8lib/cx16/monogfx.p8 +++ b/compiler/res/prog8lib/cx16/monogfx.p8 @@ -169,18 +169,30 @@ _clear ubyte separate_pixels = (8-lsb(xx)) & 7 if separate_pixels { - if mode!=MODE_STIPPLE { - position(xx,yy) - cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off - if draw - cx16.VERA_DATA0 |= masked_starts[separate_pixels] - else - cx16.VERA_DATA0 &= ~masked_starts[separate_pixels] - xx += separate_pixels - } else { - repeat separate_pixels { - plot(xx, yy, draw) - xx++ + when mode { + MODE_NORMAL -> { + position(xx,yy) + cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off + if draw + cx16.VERA_DATA0 |= masked_starts[separate_pixels] + else + cx16.VERA_DATA0 &= ~masked_starts[separate_pixels] + xx += separate_pixels + } + MODE_STIPPLE -> { + repeat separate_pixels { + plot(xx, yy, draw) + xx++ + } + } + MODE_INVERT -> { + position(xx,yy) + cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off + if draw + cx16.VERA_DATA0 ^= masked_starts[separate_pixels] + else + cx16.VERA_DATA0 &= masked_starts[separate_pixels] + xx += separate_pixels } } length -= separate_pixels @@ -203,8 +215,25 @@ _clear + lda p8v_mode lsr a bcs _stipple - ldy #255 ; don't stipple + lsr a + bcs _inverted + ldy #255 ; normal drawing mode bra _loop + +_inverted lda #0 + jsr cx16.vaddr_clone +_invertedloop lda p8v_length + ora p8v_length+1 + beq _done + lda cx16.VERA_DATA1 + eor #255 + sta cx16.VERA_DATA0 + lda p8v_length + bne + + dec p8v_length+1 ++ dec p8v_length + bra _invertedloop + _stipple lda p8v_yy and #1 ; determine stipple pattern to use bne + @@ -223,16 +252,26 @@ _loop lda p8v_length _done }} - if mode!=MODE_STIPPLE { + when mode { + MODE_NORMAL -> { + cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off + if draw + cx16.VERA_DATA0 |= masked_ends[separate_pixels] + else + cx16.VERA_DATA0 &= ~masked_ends[separate_pixels] + } + MODE_STIPPLE -> { + repeat separate_pixels { + plot(xx, yy, draw) + xx++ + } + } + MODE_INVERT -> { cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off if draw - cx16.VERA_DATA0 |= masked_ends[separate_pixels] + cx16.VERA_DATA0 ^= masked_ends[separate_pixels] else - cx16.VERA_DATA0 &= ~masked_ends[separate_pixels] - } else { - repeat separate_pixels { - plot(xx, yy, draw) - xx++ + cx16.VERA_DATA0 &= masked_ends[separate_pixels] } } } @@ -264,12 +303,10 @@ _done lda p8v_mode and #p8c_MODE_INVERT beq + - lda #$45 ; eor ZP - sta drawmode - bra ++ -+ lda #$05 ; ora ZP - sta drawmode -+ + lda #$45 ; eor ZP modifying code + bne ++ ++ lda #$05 ; ora ZP modifying code ++ sta drawmode }} if mode!=MODE_STIPPLE { ; draw continuous line. @@ -818,7 +855,7 @@ skip: cx16.screen_set_charset(charset, 0) } - sub text(uword @zp xx, uword yy, bool draw, uword sctextptr) { + sub text(uword @zp xx, uword yy, bool draw, str sctextptr) { ; -- Write some text at the given pixel position. The text string must be in screencode encoding (not petscii!). ; You must also have called text_charset() first to select and prepare the character set to use. uword chardataptr @@ -826,6 +863,17 @@ skip: ubyte[8] @shared char_bitmap_bytes_right cx16.r3 = sctextptr + %asm {{ + lda p8v_mode + cmp #p8c_MODE_INVERT + beq + + lda #$0d ; ORA abs modifying code + bne ++ ++ lda #$4d ; EOR abs modifying code ++ sta cdraw_mod1 + sta cdraw_mod2 + }} + while @(cx16.r3) { chardataptr = charset_addr + @(cx16.r3) * $0008 ; copy the character bitmap into RAM @@ -859,7 +907,7 @@ skip: %asm {{ ldy #0 - lda p8v_char_bitmap_bytes_left,y - ora cx16.VERA_DATA1 +cdraw_mod1 ora cx16.VERA_DATA1 sta cx16.VERA_DATA0 iny cpy #8 @@ -885,7 +933,7 @@ skip: %asm {{ ldy #0 - lda p8v_char_bitmap_bytes_right,y - ora cx16.VERA_DATA1 +cdraw_mod2 ora cx16.VERA_DATA1 sta cx16.VERA_DATA0 iny cpy #8 diff --git a/compiler/res/prog8lib/virtual/monogfx.p8 b/compiler/res/prog8lib/virtual/monogfx.p8 index 1c03a73ba..7b5b15270 100644 --- a/compiler/res/prog8lib/virtual/monogfx.p8 +++ b/compiler/res/prog8lib/virtual/monogfx.p8 @@ -467,7 +467,7 @@ skip: ; TODO vm bitmap charset } - sub text(uword @zp xx, uword yy, bool draw, uword sctextptr) { + sub text(uword @zp xx, uword yy, bool draw, str sctextptr) { ; -- Write some text at the given pixel position. The text string must be in screencode encoding (not petscii!). ; You must also have called text_charset() first to select and prepare the character set to use. ; TODO vm bitmap charset diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 2ff396597..7be1af753 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -cx16.monogfx: add invert mode support to horizontal line routine, and text routine - replace Takes by Http4k in httpCompilerService project. https://github.com/http4k/examples/blob/master/hello-world/README.md ... diff --git a/examples/test.p8 b/examples/test.p8 index 3cbc66110..e0ed6aee1 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -6,30 +6,23 @@ main { monogfx.lores() monogfx.drawmode(monogfx.MODE_INVERT) - uword x1, x2 - uword y1, y2 - - repeat 200 { - x1 = math.rnd() - y1 = math.rnd() % 240 - x2 = math.rnd() - y2 = math.rnd() % 240 - monogfx.line(x1, y1, x2, y2, true) - } - - repeat 5 { - for cx16.r9L in 0 to 200 { - monogfx.vertical_line(cx16.r9L, 10, 200, true) - } - } - - - monogfx.disc(160, 120, 100, true) - monogfx.fillrect(20, 100, 280, 50, true) - monogfx.drawmode(monogfx.MODE_STIPPLE) - monogfx.fillrect(80, 10, 50, 220, true) + ubyte tt repeat { + ubyte tts=tt + word x1 = math.sin8(tts) / 2 + byte y1 = math.cos8(tts) / 2 + tts += 256/3 + word x2 = math.sin8(tts) / 2 + byte y2 = math.cos8(tts) / 2 + tts += 256/3 + word x3 = math.sin8(tts) / 2 + byte y3 = math.cos8(tts) / 2 + monogfx.line(160+x1 as uword, 120+y1 as ubyte, 160+x2 as uword, 120+y2 as ubyte, true) + monogfx.line(160+x2 as uword, 120+y2 as ubyte, 160+x3 as uword, 120+y3 as ubyte, true) + monogfx.line(160+x3 as uword, 120+y3 as ubyte, 160+x1 as uword, 120+y1 as ubyte, true) + sys.waitvsync() + tt++ } } }