From 05b6d714304f6e7177b94797c4ed17cda5bb8622 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 25 Feb 2025 20:16:29 -0500 Subject: [PATCH] ampersand_usr: add code here hopefully these examples will be useful in the future --- basic/ampersand_usr/Makefile | 43 +++++++++++++++++++++++++ basic/ampersand_usr/README | 22 +++++++++++++ basic/ampersand_usr/andor.s | 54 ++++++++++++++++++++++++++++++++ basic/ampersand_usr/hello.bas | 2 ++ basic/ampersand_usr/starpath.bas | 12 +++++++ graphics/gr/starpath/andor.s | 30 ++++++++++++++++++ 6 files changed, 163 insertions(+) create mode 100644 basic/ampersand_usr/Makefile create mode 100644 basic/ampersand_usr/README create mode 100644 basic/ampersand_usr/andor.s create mode 100644 basic/ampersand_usr/hello.bas create mode 100644 basic/ampersand_usr/starpath.bas create mode 100644 graphics/gr/starpath/andor.s diff --git a/basic/ampersand_usr/Makefile b/basic/ampersand_usr/Makefile new file mode 100644 index 00000000..6163080c --- /dev/null +++ b/basic/ampersand_usr/Makefile @@ -0,0 +1,43 @@ +include ../../Makefile.inc + +DOS33 = ../../utils/dos33fs-utils/dos33 +TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft +LINKERSCRIPTS = ../../linker_scripts +EMPTYDISK = ../../empty_disk + +all: starpath.dsk ANDOR + +$(DOS33): + cd ../../utils/dos33fs-utils && make + +starpath.dsk: $(DOS33) HELLO STARPATH.BAS + cp $(EMPTYDISK)/empty.dsk starpath.dsk + $(DOS33) -y starpath.dsk SAVE A HELLO + $(DOS33) -y starpath.dsk SAVE A STARPATH.BAS + + + +### + +HELLO: hello.bas + $(TOKENIZE) < hello.bas > HELLO + +### + +STARPATH.BAS: starpath.bas + $(TOKENIZE) < starpath.bas > STARPATH.BAS + + +#### + +ANDOR: andor.o + ld65 -o ANDOR andor.o -C $(LINKERSCRIPTS)/apple2_300.inc + +andor.o: andor.s + ca65 -o andor.o andor.s -l andor.lst + +### + + +clean: + rm -f *~ *.o HELLO STARPATH.BAS ANDOR *.lst diff --git a/basic/ampersand_usr/README b/basic/ampersand_usr/README new file mode 100644 index 00000000..7941b351 --- /dev/null +++ b/basic/ampersand_usr/README @@ -0,0 +1,22 @@ +Some experiments with using & and USR() to call into assembly +language from BASIC. + +Neither is very convenient when sizecoding. + +; When &/ampersand call +; jumps to address $3F5 (applesoft already has a placeholder jmp there) +; when called next char/token in A (so can easily do things like &PLOT) +; can't return anything unless you look up a variable by name and +; write to the pointer + +; USR() can take one argument, returns value +; jumps to $0A in zero page, which is usually a jump +; to a USER handler. BASIC is set up to illegal quant error +; by default +; need to manipulate the FAC accumulator to handle input/return + + + +https://mirrors.apple2.org.za/ftp.apple.asimov.net/documentation/magazines/misc/theappleorchard_v1n1_applesoftinternalentrypoints_ocr.pdf +https://6502disassembly.com/a2-rom/Applesoft.html +https://wiki.reactivemicro.com/images/f/f7/Applesoft_II_2019.pdf diff --git a/basic/ampersand_usr/andor.s b/basic/ampersand_usr/andor.s new file mode 100644 index 00000000..cd4c61df --- /dev/null +++ b/basic/ampersand_usr/andor.s @@ -0,0 +1,54 @@ +; calculates &X,Y,Z,C +; C = (X|Y)&Z + + +; Routine for calling from & +; when called next char/token in A +; can't return anything unless you look up a variable by name +; and write to it + +; USER() can take one argument, returns value + +; dump with od -t u1 ./ANDOR + +VARPNTL = $83 +VARPNTH = $84 + + +FRMEVL = $DD7B +GETADDR= $E752 +CHKCOM = $DEBE +SNGFLT = $E301 +PTRGET = $DFE3 ; returns pointer to variable in VARPNT and (Y,A) +MOVMF = $EB2B + +andor: + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + lda $50 + sta $24 + + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + lda $50 ; A5 50 + sta $25 ; 85 50 + + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + + lda $24 ; A5 24 + ora $25 ; 05 25 + and $50 ; 25 50 + sta $24 + + jsr PTRGET ; 20 E3 DF + ldy $24 ; A8 + jsr SNGFLT ; 20 01 E3 unsigned Y -> FAC + + ldx VARPNTL ;VARPNT + ldy VARPNTH ;VARPNT+1 + jmp MOVMF + diff --git a/basic/ampersand_usr/hello.bas b/basic/ampersand_usr/hello.bas new file mode 100644 index 00000000..133a44bb --- /dev/null +++ b/basic/ampersand_usr/hello.bas @@ -0,0 +1,2 @@ +5 HOME +10 PRINT CHR$(4);"CATALOG" diff --git a/basic/ampersand_usr/starpath.bas b/basic/ampersand_usr/starpath.bas new file mode 100644 index 00000000..ba445477 --- /dev/null +++ b/basic/ampersand_usr/starpath.bas @@ -0,0 +1,12 @@ +0FOR I=0 TO 57:READ D:POKE 768+I,D:NEXT:POKE 1014,0:POKE 1015,3 +1DIML(16):FORI=0TO14:READL(I):NEXT:GR:POKE49234,0 +2FORY=0TO47:FORX=0TO39:D=I +3Z=Y*4*D:T=X*6-D:IFT<0THENC=31:A=X*6+Z:&0,A,255,A:GOTO8 +4&T*D/256,Z/256,D+F,C:D=D+1:A=0:IFC<16THEN3 +8IFA>6THENC=Y/4+32 +9COLOR=L(C/2-8):PLOTX,Y:NEXTX,Y:F=F+1:GOTO2 +100 DATA 32,123,221,32,82,231,32,190,222,165,80,133,36,32,123,221 +110 DATA 32,82,231,32,190,222,165,80,133,37,32,123,221,32,82,231 +120 DATA 32,190,222,165,36,5,37,37,80,133,36,32,227,223,164,36 +130 DATA 32,1,227,166,131,164,132,76,43,235 +140 DATA0,5,10,5,10,7,15,15,2,1,3,9,13,12,4,4 diff --git a/graphics/gr/starpath/andor.s b/graphics/gr/starpath/andor.s new file mode 100644 index 00000000..047019d8 --- /dev/null +++ b/graphics/gr/starpath/andor.s @@ -0,0 +1,30 @@ +.org 300 + +FRMEVL = $DD7B +GETADDR= $E752 +CHKCOM = $DEBE +SNGFLT = $E301 + +andor: + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + lda $50 + sta $24 + + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + lda $50 ; A5 50 + sta $25 ; 85 50 + + jsr FRMEVL ; 20 7B DD (or FRMNUM) 20 67 DD value->FAC + jsr GETADDR ; 20 52 E7 FAC-> LINNUM ($50/$51) + jsr CHKCOM ; 20 BE DE move past comma + + lda $50 ; A5 50 + ora $24 ; 05 24 + and $25 ; 25 25 + tay ; A8 + jmp SNGFLT ; 20 01 E3 unsigned Y -> FAC +