aboutsummaryrefslogtreecommitdiff
path: root/dla.s
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2022-10-26 03:29:16 -0400
committerB. Watson <urchlay@slackware.uk>2022-10-26 03:29:16 -0400
commit9733bfd0e0546f76e9a64dd3ae513896bbf19718 (patch)
treebe0dbe449d6e4b93e96b67963c2dea0549b93d32 /dla.s
parenta2f4ad9179e915fe29459623ff93a7e7ec008d78 (diff)
downloaddla-asm-9733bfd0e0546f76e9a64dd3ae513896bbf19718.tar.gz
Menu options: add New, remove Exit and WriteCSV.
Diffstat (limited to 'dla.s')
-rw-r--r--dla.s227
1 files changed, 113 insertions, 114 deletions
diff --git a/dla.s b/dla.s
index 2d96928..5b069b7 100644
--- a/dla.s
+++ b/dla.s
@@ -21,7 +21,6 @@
DMA_ON = $21
DEFAULTPART = 1000
- screenptr = SAVMSC
maxparticles = $80 ; 2 bytes
addtmp = $82
pixptr = $82
@@ -46,19 +45,36 @@
fptmp = $05a0
cloksav = $a0
seedtype = $9f
+ old_dma = $9c
+ old_dl = $9d
- ; start of init segment. gets overwritten by the main program...
- ; and since the rest of the xex isn't loaded yet, can't call
- ; subroutines from it!
xex_org loadaddr
.include "io.s" ; printchrx and getchrx
-msg:
- .byte "Diffusion Limited Aggregate",$9b
- .byte "Urchlay's ASM version 0.0.7",$9b,$9b
- .byte "How many particles [",.sprintf("%d", DEFAULTPART),"]? ",$0
-msg2:
- .byte $9b,"Seed Type: ",$9b,"1=Dot 2=Plus 3=4Dots 4=Line [1]? ",$0
+
+ ; init stuff gets done once, at startup
init:
+ lda SDMCTL
+ sta old_dma
+ lda SDLSTL
+ sta old_dl
+ lda SDLSTH
+ sta old_dl+1
+
+ ; "New" option jumps here, restore GR.0 screen
+getargs:
+ lda #$90
+ sta COLOR2
+ lda #$0e
+ sta COLOR1
+ lda #$ff
+ sta CH
+ lda old_dl
+ sta SDLSTL
+ lda old_dl+1
+ sta SDLSTH
+ lda old_dma
+ sta SDMCTL
+
; set default particles (if user just hits return)
lda #<DEFAULTPART
sta maxparticles
@@ -66,6 +82,7 @@ init:
sta maxparticles+1
; print banner and prompt.
+printmsg:
ldx #0
pmloop:
lda msg,x
@@ -75,61 +92,26 @@ pmloop:
bne pmloop
pmdone:
- ; read up to 5 digits. for now, no editing.
- ldx #0
-readloop:
- jsr getchrx
- cmp #$9b ; is it Return?
- beq readdone ; if so, done reading.
- cmp #$30 ; is it a digit?
- bcc readloop ; if not, ignore it.
- cmp #$3a
- bcs readloop
- sta textbuf,x
- jsr printchrx
- inx
- cpx #5
- bne readloop
- lda #0
- sta textbuf,x ; zero-terminate
-readdone:
- cpx #0
- beq usedefault
-
- ; add up input digits
- lda #0
- sta maxparticles
- sta maxparticles+1
- ldx #0
-digloop:
- lda textbuf,x
- beq digitsdone ; hit zero terminator
- ldy #$0a
+ ; use CIO to read input, so user can use backspace/etc.
+ jsr readline
+ lda linebuf
+ cmp #$9b
+ beq usedefault ; if user hit Return
+ ; use floating point ROM to convert input to an integer.
lda #0
- sta addtmp
- sta addtmp+1
-mul10loop:
- clc
- lda addtmp
- adc maxparticles
- sta addtmp
- lda addtmp+1
- adc maxparticles+1
- sta addtmp+1
- dey
- bne mul10loop
- lda textbuf,x
- and #$0f
- clc
- adc addtmp
- sta maxparticles
- lda addtmp+1
- adc #0
+ sta CIX
+ jsr AFP ; ASCII to floating point, result in FR0
+ bcs printmsg ; C set means error
+ jsr FPI ; convert FR0 to integer (result in FR0)
+ bcs printmsg
+ lda FR0
+ tax
+ ora FR0+1 ; we don't accept 0 for an answer!
+ beq printmsg
+ lda FR0+1
+ stx maxparticles
sta maxparticles+1
- inx
- bne digloop
-
-digitsdone:
+
usedefault:
; print seed type prompt
@@ -156,17 +138,8 @@ noteol:
tax
dex
stx seedtype
- ;rts
-
- ;xex_init init
-;;;;; end of init segment
- ;xex_org loadaddr
-main: ;;; start of main()
- lda #$90
- sta COLOR2
- lda #$0e
- sta COLOR1
+generate: ;;; start of generate()
jsr initscreen
; wait for shadow regs to get updated...
lda RTCLOK+2
@@ -361,20 +334,22 @@ waitkey:
and #$3f ; ignore shift and inverse
cmp #$28 ; Redo
bne notredo
- jmp main
+ jmp generate
notredo:
cmp #$3e ; Save
beq saveimage
- cmp #$2a ; Exit
+ cmp #$23 ; New
bne keyloop ; ignore any other keystroke
- ;rts ; exit to DOS
- jmp COLDSV ; reboot
-;;; End of main()
+ jmp getargs
+ ;;; End of generate()
;;; Subroutine: saveimage
;;; Does exactly what it says on the tin: saves the image.
;;; For now, the filename is hardcoded and there's no error checking.
+;;; TODO: prompt for filename, report errors (with retry).
saveimage:
+ ; CIO is nice, but it's kind of a PITA to use...
+ ; OPEN #1,8,0,<filename>
ldx #$10
lda #3 ; OPEN
sta ICCOM,x
@@ -391,6 +366,7 @@ saveimage:
sta ICAX1,x
jsr CIOV
+ ; write data to file
ldx #$10
lda #$0b ; write binary record
sta ICCOM,x
@@ -404,16 +380,13 @@ saveimage:
sta ICBLH,x
jsr CIOV
+ ; CLOSE #1
ldx #$10
lda #$0c ; close
sta ICCOM,x
jsr CIOV
jmp keyloop
-diskerr:
- sty textbuf
-hang: jmp hang
-
;;; Subroutine: set_limits
;;; Sets the X/Y min/max limits based on circlesize
set_limits:
@@ -432,7 +405,10 @@ set_limits:
;;; clear screen memory and point ANTIC to our display list.
;;; no arguments. trashes all registers.
initscreen:
- jsr set_screenptr
+ lda #<screen
+ sta pixptr
+ lda #>screen
+ sta pixptr+1
; first, clear linebuf and textbuf
lda #0
@@ -447,10 +423,10 @@ isloop0:
ldx #>screenbytes ; clear this many pages
tay ; 0 again
isloop:
- sta (screenptr),y
+ sta (pixptr),y
iny
bne isloop
- inc screenptr+1
+ inc pixptr+1
dex
bne isloop
@@ -461,16 +437,7 @@ isloop:
sta SDLSTL
lda #>dlist
sta SDLSTH
-; fall through to next subroutine
-;;; Subroutine: set_screenptr
-;;; Set screenptr to the start of screen memory.
-;;; Trashes A, preserves X and Y.
-set_screenptr:
- lda #<screen
- sta screenptr
- lda #>screen
- sta screenptr+1
rts
;;; Subroutine: plotsetup
@@ -478,7 +445,7 @@ set_screenptr:
;;; - set pixmask to the mask for cursor_x.
;;; - set Y reg to the byte offset for cursor_x.
;;; - returns with cursor_x in X reg, pixmask in A reg too.
-;;; Called by plot, unplot, and locate.
+;;; Called by plot, unplot, and drunkwalk (a lot!)
plotsetup:
ldx cursor_y
lda lineaddrs_l,x
@@ -643,16 +610,18 @@ drawseed:
pha
rts
+;;; Subroutine: seed_point
+;;; draw initial point in center
seed_point:
- ; initial point in center
lda #$7f
sta cursor_x
lda #$5f
sta cursor_y
jmp plot
+;;; Subroutine: seed_long
+;;; horizontal line, the width of the screen
seed_long:
- ; horizontal line, the width of the screen
lda #$1
sta cursor_x
lda #$5f
@@ -665,8 +634,9 @@ slnoop:
bne slnoop
rts
+;;; Subroutine: seed_plus
+;;; plus share, made of two 20px lines intersecting in the center
seed_plus:
- ; plus, made of two 20px lines intersecting in the center
lda #$7f
sta cursor_x
lda #$55
@@ -689,8 +659,9 @@ slloop:
bne slloop
rts
+;;; Subroutine: seed_4pt
+;;; four points, the corners of a 20px square
seed_4pt:
- ; four points, the corners of a 20px square
lda #$75
sta cursor_x
lda #$55
@@ -706,23 +677,52 @@ seed_4pt:
sta cursor_y
jmp plot
-;;;;; end of executable code
+;;; Subroutine: readline
+;;; Read a line from E:, store result in linebuf.
+;;; The terminating EOL ($9b) gets stored at the end.
+;;; linebuf happens to be right where the FP ROM needs it for AFP.
+readline:
+ lda #<linebuf
+ sta INBUFF
+ sta ICBAL
+ lda #>linebuf
+ sta INBUFF+1
+ sta ICBAH
+ lda #0
+ sta ICBLH
+ lda #10
+ sta ICBLL
+ lda #5
+ sta ICCOM
+ ldx #0
+ jmp CIOV
+
+;;;;; end of executable code, data tables from here on out.
+
+; prompts
+msg:
+ .byte $7d, "Diffusion Limited Aggregate",$9b
+ .byte "Urchlay's ASM version 0.0.7",$9b,$9b
+ .byte "Particle count range: 1 to 65535",$9b
+ .byte "How many particles [",.sprintf("%d", DEFAULTPART),"]? ",$0
+msg2:
+ .byte $9b,"Seed Type: ",$9b,"1=Dot 2=Plus 3=4Dots 4=Line [1]? ",$0
; screen codes for menu
menumsg:
- .byte $00,$00,$00 ; 3 digits of minutes
- .byte $00 ; 1 decimal point
- .byte $00,$00 ; 2 digits fractional minutes
- .byte $00 ; 1 the letter "m"
- .byte $00,$00 ; 2 spaces
- .byte 'S'-$20+$80 ; 1
- scrcode "ave " ; 3
- .byte 'R'-$20+$80 ; 1
- scrcode "edo " ; 4
- .byte 'E'-$20+$80 ; 1
- scrcode "xit?" ; 4
- .byte $80 ; 1 (cursor)
- .byte $00,$00,$00 ; 3 (filler)
+ .byte $00,$00,$00 ; 3 digits of minutes
+ .byte $00 ; 1 decimal point
+ .byte $00,$00 ; 2 digits fractional minutes
+ .byte $00 ; 1 the letter "m"
+ .byte $00,$00 ; 2 spaces
+ .byte 'S'-$20+$80 ; 1
+ scrcode "ave " ; 3
+ .byte 'R'-$20+$80 ; 1
+ scrcode "edo " ; 4
+ .byte 'N'-$20+$80 ; 1
+ scrcode "ew?" ; 4
+ .byte $80 ; 1 (cursor)
+ .byte $00,$00,$00,$00 ; 4 (filler)
menulen = * - menumsg - 1
; filename for Save command
@@ -792,6 +792,5 @@ xmasks:
.word textbuf
.byte jvb
.word dlist
- ;.out .sprintf("%d",* - dlist)
xex_run init