From d3b9a848203eecb598f6f21e095e7eb5dc848bae Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 18 Jun 2021 14:04:47 -0400 Subject: [PATCH] hgr: vgi: an agi-like interpreter --- graphics/hgr/vgi/Makefile | 49 +++++++++++++++++++ graphics/hgr/vgi/clock.vgi | 23 +++++++++ graphics/hgr/vgi/hello.bas | 2 + graphics/hgr/vgi/make_boxes_asm.c | 53 ++++++++++++++++++++ graphics/hgr/vgi/vgi.s | 78 ++++++++++++++++++++++++++++++ graphics/hgr/vgi/vgi_clearscreen.s | 7 +++ graphics/hgr/vgi/zp.inc | 22 +++++++++ 7 files changed, 234 insertions(+) create mode 100644 graphics/hgr/vgi/Makefile create mode 100644 graphics/hgr/vgi/clock.vgi create mode 100644 graphics/hgr/vgi/hello.bas create mode 100644 graphics/hgr/vgi/make_boxes_asm.c create mode 100644 graphics/hgr/vgi/vgi.s create mode 100644 graphics/hgr/vgi/vgi_clearscreen.s create mode 100644 graphics/hgr/vgi/zp.inc diff --git a/graphics/hgr/vgi/Makefile b/graphics/hgr/vgi/Makefile new file mode 100644 index 00000000..29e671f7 --- /dev/null +++ b/graphics/hgr/vgi/Makefile @@ -0,0 +1,49 @@ +include ../../../Makefile.inc + +DOS33 = ../../../utils/dos33fs-utils/dos33 +TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft +LINKERSCRIPTS = ../../../linker_scripts +EMPTYDISK = ../../../empty_disk/empty.dsk + +all: vgi.dsk make_boxes_asm + +vgi.dsk: HELLO VGI + cp $(EMPTYDISK) vgi.dsk + $(DOS33) -y vgi.dsk SAVE A HELLO + $(DOS33) -y vgi.dsk BSAVE -a 0xC00 VGI + + +### + +HELLO: hello.bas + $(TOKENIZE) < hello.bas > HELLO + + +### + +VGI: vgi.o + ld65 -o VGI vgi.o -C $(LINKERSCRIPTS)/apple2_c00.inc + +vgi.o: clock.data \ + vgi.s vgi_clearscreen.s vgi_rectangle.s + ca65 -o vgi.o vgi.s -l vgi.lst + + +### + +clock.data: make_boxes_asm clock.vgi + echo "clock_data:" > clock.data + ./make_boxes_asm < clock.vgi >> clock.data + +### + +make_boxes_asm: make_boxes_asm.o + $(CC) -o make_boxes_asm make_boxes_asm.o $(LFLAGS) + +make_boxes_asm.o: make_boxes_asm.c + $(CC) $(CFLAGS) -c make_boxes_asm.c + +### + +clean: + rm -f *~ *.o *.lst HELLO VGI make_boxes_asm *.data diff --git a/graphics/hgr/vgi/clock.vgi b/graphics/hgr/vgi/clock.vgi new file mode 100644 index 00000000..46d59ba9 --- /dev/null +++ b/graphics/hgr/vgi/clock.vgi @@ -0,0 +1,23 @@ +; Clock from Myst +0 255 ; white background +1 1 6 0 90 140 191 ; ocean left +1 1 6 140 90 279 191 ; ocean right +1 4 1 157 121 208 191 ; tower shadow +1 0 7 141 116 231 135 ; gear base +1 0 7 180 17 213 121 ; +1 7 0 156 20 209 126 ; tower +1 7 0 145 9 212 20 +1 0 7 162 0 220 20 +1 5 0 172 91 187 123 +1 7 7 169 31 191 63 ; clock face tall +1 7 7 165 39 194 60 ; clock face wide +1 5 1 0 163 63 191 ; grass +1 5 1 63 167 177 191 ; grass +1 5 1 177 185 230 191 ; grass +1 5 0 23 0 39 178 ; tree +1 1 5 1 13 99 44 ; leaves +1 5 0 0 0 20 188 ; tree +1 0 5 66 0 81 187 ; tree +1 1 5 66 1 99 19 ; leaves +1 0 0 177 32 181 50 ; clock hand +15 diff --git a/graphics/hgr/vgi/hello.bas b/graphics/hgr/vgi/hello.bas new file mode 100644 index 00000000..133a44bb --- /dev/null +++ b/graphics/hgr/vgi/hello.bas @@ -0,0 +1,2 @@ +5 HOME +10 PRINT CHR$(4);"CATALOG" diff --git a/graphics/hgr/vgi/make_boxes_asm.c b/graphics/hgr/vgi/make_boxes_asm.c new file mode 100644 index 00000000..1cc75985 --- /dev/null +++ b/graphics/hgr/vgi/make_boxes_asm.c @@ -0,0 +1,53 @@ +#include + +int main(int argc, char **argv) { + + char buffer[1024]; + char *ptr; + int type,color1,color2,x1,x2,y1,y2; + int line=1; + + while(1) { + + ptr=fgets(buffer,1024,stdin); + if (ptr==NULL) break; + + if (buffer[0]==';') continue; + + sscanf(buffer,"%d",&type); + + switch(type) { + case 0: /* clear screen */ + sscanf(buffer,"%d %d",&type,&color1); + printf(".byte $%02X,",(type<<4)|2); + printf("$%02X\n",color1); + break; + case 1: /* compact rectangle */ + sscanf(buffer,"%d %d %d %d %d %d %d", + &type, + &color1,&color2, + &x1,&y1,&x2,&y2); + printf(".byte $%02X,",(type<<4)|6); + printf("$%02X,",(color1<<4)|color2); + printf("$%02X,",x1); + printf("$%02X,",y1); + printf("$%02X,",x2-x1); + printf("$%02X\n",y2-y1); + break; + + case 15: /* end */ + printf(".byte $FF\n"); + break; + + default: + fprintf(stderr,"Unknown type %d\n",type); + break; + } + + line++; + + } + + printf("\n"); + return 0; +} diff --git a/graphics/hgr/vgi/vgi.s b/graphics/hgr/vgi/vgi.s new file mode 100644 index 00000000..58b1b1de --- /dev/null +++ b/graphics/hgr/vgi/vgi.s @@ -0,0 +1,78 @@ +; VGI + +.include "zp.inc" +.include "hardware.inc" + +VGI_MAXLEN = 7 + +vgi_test: + jsr HGR2 + + ; get pointer to image data + + lda #clock_data + sta VGIH + +vgi_loop: + + ldy #0 +data_smc: + lda (VGIL),Y + sta VGI_BUFFER,Y + iny + cpy #VGI_MAXLEN + bne data_smc + + lda TYPE + and #$f + + clc + adc VGIL + sta VGIL + bcc no_oflo + inc VGIH +no_oflo: + + lda TYPE + lsr + lsr + lsr + lsr + + ; look up action in jump table + asl + tax + lda vgi_rts_table+1,X + pha + lda vgi_rts_table,X + pha + rts ; "jump" to subroutine + +vgi_rts_table: + .word vgi_clearscreen-1 + .word vgi_simple_rectangle-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + .word all_done-1 + +all_done: + jmp all_done + + +.include "vgi_clearscreen.s" +.include "vgi_rectangle.s" + +.include "clock.data" diff --git a/graphics/hgr/vgi/vgi_clearscreen.s b/graphics/hgr/vgi/vgi_clearscreen.s new file mode 100644 index 00000000..e56b982d --- /dev/null +++ b/graphics/hgr/vgi/vgi_clearscreen.s @@ -0,0 +1,7 @@ + +vgi_clearscreen: + + lda P0 + jsr BKGND0 + + jmp vgi_loop ; return diff --git a/graphics/hgr/vgi/zp.inc b/graphics/hgr/vgi/zp.inc new file mode 100644 index 00000000..d3b618b0 --- /dev/null +++ b/graphics/hgr/vgi/zp.inc @@ -0,0 +1,22 @@ +; zero page + +HGR_X = $E0 +HGR_XH = $E1 +HGR_Y = $E2 +HGR_COLOR = $E4 + +VGI_BUFFER = $F0 +TYPE = $F0 +P0 = $F1 +P1 = $F2 +P2 = $F3 +P3 = $F4 +P4 = $F5 +P5 = $F6 +P6 = $F7 +VGIL = $F8 +VGIH = $F9 + +COLOR1 = $FE +COLOR2 = $FF +