From ad103d2feb765ce5d7006187fc2d2187d4e14ec4 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 14 Mar 2022 13:29:33 -0400 Subject: [PATCH] hgr: lines: vlin add some hgr_vlin code --- graphics/hgr/lines/Makefile | 13 +- graphics/hgr/lines/hgr_vlin.s | 111 ++++++++++++++++ graphics/hgr/lines/vlin_test.s | 234 +++++++++++++++++++++++++++++++++ 3 files changed, 356 insertions(+), 2 deletions(-) create mode 100644 graphics/hgr/lines/hgr_vlin.s create mode 100644 graphics/hgr/lines/vlin_test.s diff --git a/graphics/hgr/lines/Makefile b/graphics/hgr/lines/Makefile index 94cceea8..f8e0d30d 100644 --- a/graphics/hgr/lines/Makefile +++ b/graphics/hgr/lines/Makefile @@ -7,12 +7,13 @@ EMPTY_DISK = ../../../empty_disk all: lines.dsk -lines.dsk: HELLO LINES LINES_ROM HLIN_TEST +lines.dsk: HELLO LINES LINES_ROM HLIN_TEST VLIN_TEST cp $(EMPTY_DISK)/empty.dsk lines.dsk $(DOS33) -y lines.dsk SAVE A HELLO $(DOS33) -y lines.dsk BSAVE -a 0x0C00 LINES $(DOS33) -y lines.dsk BSAVE -a 0x0C00 LINES_ROM $(DOS33) -y lines.dsk BSAVE -a 0x0C00 HLIN_TEST + $(DOS33) -y lines.dsk BSAVE -a 0x0C00 VLIN_TEST ### @@ -49,10 +50,18 @@ HLIN_TEST: hlin_test.o hlin_test.o: hlin_test.s hgr_hlin.s ca65 -o hlin_test.o hlin_test.s -l hlin_test.lst +### + +VLIN_TEST: vlin_test.o + ld65 -o VLIN_TEST vlin_test.o -C $(LINKER_SCRIPTS)/apple2_c00.inc + +vlin_test.o: vlin_test.s hgr_vlin.s + ca65 -o vlin_test.o vlin_test.s -l vlin_test.lst + ### clean: - rm -f *~ *.o *.lst HELLO LINES LINES_ROM HLIN_TEST + rm -f *~ *.o *.lst HELLO LINES LINES_ROM HLIN_TEST VLIN_TEST diff --git a/graphics/hgr/lines/hgr_vlin.s b/graphics/hgr/lines/hgr_vlin.s new file mode 100644 index 00000000..5721203a --- /dev/null +++ b/graphics/hgr/lines/hgr_vlin.s @@ -0,0 +1,111 @@ + ;================================= + ; Simple Vertical LINE + ;================================= + ; line from (x,a) to (x,a+y) + ; todo: use Carry to say if X>255 + +hgr_vlin: + ; don't handle run of 0 + cpy #0 + beq done_hgr_vlin + + + ; get initial ROW into (GBASL) + + sta current_row_smc+1 ; save current A + sty vlin_row_count + + lda div7_table,X + sta x1_save_smc+1 + + lda mod7_table,X + tax + lda vlin_masks,X + sta vlin_mask_smc+1 + +hgr_vlin_loop: + +current_row_smc: + lda #$dd + ldx #0 ; doesn't matter + ldy #0 ; always 0 + jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y) + ; important part is row is in GBASL/GBASH + ; HPOSN also shifts color odd/even for us + ; HPOSN also puts X1/7 into Y + +x1_save_smc: + ldy #$dd + lda (GBASL),Y + eor HGR_BITS +vlin_mask_smc: + and #$dd + eor (GBASL),Y + sta (GBASL),Y + + inc current_row_smc+1 + dec vlin_row_count + + bne hgr_vlin_loop + +done_hgr_vlin: + + rts + +vlin_row_count: .byte $00 + + +vlin_masks: + .byte $81,$82,$84,$88,$90,$A0,$C0 + + + ;========================== + ; shift colors + ;========================== + ; 00000000 and 10000000 => no change (black) + ; 01111111 and 11111111 => no change? (white) + ; 01010101 => invert 00101010 +shift_colors: + lda HGR_BITS + asl + cmp #$C0 + bpl done_shift_colors + lda HGR_BITS + eor #$7f + sta HGR_BITS +done_shift_colors: + rts + + ;========================== + ; set color + ;========================== + ; color in X +set_hcolor: + lda COLORTBL,X + sta HGR_COLOR + rts + + +; notes + ; 4+3 + ; 0000 CCCC 0000 1111 + ; 0000 000C 0000 0001 + +; 4000 = 80 80 +; 4400 = 81 81 +; 4800 = 83 83 +; 4C00 = 87 87 +; 5000 = 8F 8F +; 5400 = 9F 9F +; 5800 = BF BF +;---- +; 5C00 = FF FF +; 4080 = ff 81 FF 81 +; 4480 = ff 83 +; 4880 = ff 87 +; 4c80 = ff 8F +; 5080 = ff 9f +; 5480 = ff bf +;----------- +; 5880 = ff ff +; 5c80 = ff ff 81 diff --git a/graphics/hgr/lines/vlin_test.s b/graphics/hgr/lines/vlin_test.s new file mode 100644 index 00000000..b28fb6d6 --- /dev/null +++ b/graphics/hgr/lines/vlin_test.s @@ -0,0 +1,234 @@ +; hgr fast vlin test + + +HGR_BITS = $1C +GBASL = $26 +GBASH = $27 +HGR_COLOR = $E4 +HGR_PAGE = $E6 + +div7_table = $9000 +mod7_table = $9100 + +KEYPRESS = $C000 +KEYRESET = $C010 + +HGR2 = $F3D8 ; clear PAGE2 to 0 +HGR = $F3E2 ; set hires page1 and clear $2000-$3fff +BKGND0 = $F3F4 ; clear screen to A +HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y) +COLOR_SHIFT = $F47E +COLORTBL = $F6F6 + + + +main: + ; set graphics + + jsr HGR + + + ; init tables + + jsr vgi_init + + ; draw lines + + ; multicolor + ; for y=0 to 150 step 2:hgr_vlin 10,10+y at y: next + + ldy #0 +loop1: + tya + lsr + lsr + and #$7 + tax + jsr set_hcolor + + tya + pha + + tax ; X1=Y + lda #10 ; Y1=A +; ldy #100 ; Run = y + jsr hgr_vlin ; vlin (x,a) to (x,a+y) + + pla + tay + + iny + iny + iny + iny + cpy #160 + bne loop1 + + jsr wait_until_keypress + + +; test 2 + + + jsr HGR2 + + ; draw lines + ldy #0 +loop2: + ldx #7 ; draw white + jsr set_hcolor + + tya ; save y on stack + pha + + tax ; x1=Y + tay ; yrun=y + + lda #0 ; y1=0 + + jsr hgr_vlin + + pla + tay + + iny + iny + iny + iny + iny + + cpy #150 + bne loop2 + + jsr wait_until_keypress + +; test 3 + + +; jsr HGR2 + + ; note, clear to bgcolor=black2 or else edge looks a bit + ; ragged when $FF touches $00 + + lda #$80 + jsr BKGND0 + + ; draw lines + ldy #0 +loop3: + ldx #7 ; draw white + jsr set_hcolor + + tya + pha + tax ; X1=Y + ; Y1=A + pha + + tya + eor #$ff + sec + adc #191 + tay ; run=191-Y + pla + + jsr hgr_vlin + + pla + tay + + iny + cpy #192 + bne loop3 + + jsr wait_until_keypress + +; test 4 + + jsr HGR2 + + ; draw lines + ldy #0 +loop4: + ldx #3 ; draw white1 + jsr set_hcolor + + tya + pha + tax ; X1=Y + + eor #$ff + sec + adc #192 ; Y1=192-Y + + + ; run = Y + + jsr hgr_vlin + + pla + tay + + iny + cpy #192 + bne loop4 + + jsr wait_until_keypress + + + +done: + jmp main + +wait_until_keypress: + bit KEYRESET +keypress_loop: + lda KEYPRESS + bpl keypress_loop + + rts + + + ;===================== + ; make /7 %7 tables + ;===================== + +vgi_init: + +vgi_make_tables: + + ldy #0 + lda #0 + ldx #0 +div7_loop: + sta div7_table,Y + + inx + cpx #7 + bne div7_not7 + + clc + adc #1 + ldx #0 +div7_not7: + iny + bne div7_loop + + + ldy #0 + lda #0 +mod7_loop: + sta mod7_table,Y + clc + adc #1 + cmp #7 + bne mod7_not7 + lda #0 +mod7_not7: + iny + bne mod7_loop + + rts + + +.include "hgr_vlin.s"