basic: mod9 code

This commit is contained in:
Vince Weaver 2021-04-09 09:43:42 -04:00
parent e4c6960d1a
commit 49f661a5c0
5 changed files with 190 additions and 4 deletions

View File

@ -14,7 +14,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS HELLO \
RLEASM.BAS HORIZON.BAS FLYER.BAS STAR.BAS HYPER.BAS FASTAR.BAS \
FASTAR2.BAS BIN.BAS FALLING.BAS SNOW.BAS XMAS.BAS AN3.BAS PLASMA.BAS \
C64.BAS SIERPINSKI.BAS FAKES.BAS SIER.BAS DROPS.BAS RR.BAS RR_HGR.BAS \
COMBO.BAS WIRES.BAS PATTERN.BAS BALL.BAS LINES.BAS
COMBO.BAS WIRES.BAS PATTERN.BAS BALL.BAS LINES.BAS MOD9.BAS
# cp $(EMPTY_DISK)/empty.dsk appleiibot.dsk
cp empty.dsk appleiibot.dsk
$(DOS33) -y appleiibot.dsk BSAVE -a 0x0300 LOAD
@ -71,6 +71,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS HELLO \
$(DOS33) -y appleiibot.dsk SAVE A PATTERN.BAS
$(DOS33) -y appleiibot.dsk SAVE A BALL.BAS
$(DOS33) -y appleiibot.dsk SAVE A LINES.BAS
$(DOS33) -y appleiibot.dsk SAVE A MOD9.BAS
####
@ -159,6 +160,12 @@ NYAN.BAS: nyan.bas
####
MOD9.BAS: mod9.bas
$(TOKENIZE) < mod9.bas > MOD9.BAS
####
FALLING.BAS: falling.bas
$(TOKENIZE) < falling.bas > FALLING.BAS

View File

@ -0,0 +1,2 @@
1FORI=0TO130:POKE885+I,4*PEEK(2125+I)-192+(PEEK(2256+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",=n9D`V/QmYnHlX1OnQ8YlB25AnR8J#N9261nV6EmAn8e,k1Z0CT/Z18IlR83nR,gidWnXOn,`X#XT,k0j_E_B1DQ0inCH/QbNo8@B>mJ>mJ>mJ8@BFm2026BnBk=IoHCJ0S+4'HN?-/@WC#4$6$?%+%CLMCW6#'`%BYMPPPMP-@6%0

View File

@ -7,13 +7,14 @@ EMPTY_DISK = ../../../empty_disk/empty.dsk
all: sier.dsk
sier.dsk: HELLO SIER SIER_BOT SIER_TINY SIER_64
sier.dsk: HELLO SIER SIER_BOT SIER_TINY SIER_64 MOD9
cp $(EMPTY_DISK) sier.dsk
$(DOS33) -y sier.dsk SAVE A HELLO
$(DOS33) -y sier.dsk BSAVE -a 0x60 SIER
$(DOS33) -y sier.dsk BSAVE -a 0x36C SIER_BOT
$(DOS33) -y sier.dsk BSAVE -a 0x300 SIER_TINY
$(DOS33) -y sier.dsk BSAVE -a 0x300 SIER_64
$(DOS33) -y sier.dsk BSAVE -a 0x375 MOD9
###
@ -22,6 +23,14 @@ HELLO: hello.bas
###
MOD9: mod9.o
ld65 -o MOD9 mod9.o -C ./apple2_375.inc
mod9.o: mod9.s
ca65 -o mod9.o mod9.s -l mod9.lst
###
SIER: sier.o
ld65 -o SIER sier.o -C ./apple2_60_zp.inc
@ -58,4 +67,4 @@ sier_64.o: sier_64.s
###
clean:
rm -f *~ *.o *.lst HELLO SIER SIER_TINY SIER_64
rm -f *~ *.o *.lst HELLO SIER SIER_TINY SIER_64 MOD9

View File

@ -39,7 +39,7 @@ NORMAL = $F273
;; MONITOR ROUTINES
PLOT = $F800 ;; PLOT AT Y,A
PLOT = $F800 ;; PLOT AT Y,A (A trashed, XY Saved)
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y

168
graphics/gr/sier/mod9.s Normal file
View File

@ -0,0 +1,168 @@
; by Vince `deater` Weaver <vince@deater.net>
; calculating (X^Y) % 9
; zero page
GBASH = $27
MASK = $2E
COLOR = $30
XX = $F7
OFFSET = $F8
YY_OFFSET= $F9
YY = $FA
OLD = $FE
TEMP = $FF
; Soft switches
FULLGR = $C052
PAGE1 = $C054
PAGE2 = $C055
LORES = $C056 ; Enable LORES graphics
; ROM routines
HGR = $F3E2
HGR2 = $F3D8
PLOT = $F800 ; PLOT AT Y,A
PLOT1 = $F80E ; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
GBASCALC= $F847 ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ; COLOR=A
SETGR = $FB40
;================================
; Clear screen and setup graphics
;================================
other:
jsr SETGR
bit FULLGR
lda #0
sta OFFSET
looper:
lda OFFSET
sta YY_OFFSET
ldx #47
stx YY
yloop:
ldy #39
lda YY
; txa ; YY ; plot call needs Y/2
lsr
php
jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
lda GBASH
draw_page_smc:
adc #0
sta GBASH ; adjust for PAGE1/PAGE2 ($400/$800)
plp
jsr $f806 ; trick to calculate MASK by jumping
; into middle of PLOT routine
xloop:
tya
clc
adc OFFSET
eor YY_OFFSET
jsr mod_9
beq its_zero
lda #0
jmp setcolor
its_zero:
lda #6
setcolor:
jsr SETCOL
txa
jsr PLOT1 ; plot at Y,A (A trashed, XY Saved)
dey
bpl xloop
inc YY_OFFSET
ldx YY
dex
stx YY
bpl yloop
end:
ldx #0
flip_pages:
lda draw_page_smc+1 ; DRAW_PAGE
beq done_page
inx
done_page:
ldy $C054,X ; set display page to PAGE1 or PAGE2
eor #$4 ; flip draw page between $400/$800
sta draw_page_smc+1 ; DRAW_PAGE
inc OFFSET
jmp looper
;===============================
; modulo 9
;===============================
; value in A
mod_9:
; Divide by 9
; 17 bytes, 30 cycles
; by Omegamatrix https://forums.nesdev.com/viewtopic.php?t=11336
sta OLD
sta TEMP
lsr
lsr
lsr
adc TEMP
ror
adc TEMP
ror
adc TEMP
ror
lsr
lsr
lsr
; A is ORIG/9, mod = OLD-(A*9)
sta TEMP
asl
asl
asl
clc
adc TEMP
eor #$ff
sec
adc OLD
rts
; want this at $3F5, this is $80 in, so $375
jmp other