Compare commits

...

7 commits
sec ... main

Author SHA1 Message Date
89b4e45901 flip the y coordinate sign 2025-02-22 20:24:04 -08:00
6e66145ec6 whoops fixes 2025-02-22 15:37:11 -08:00
07db3d00d7 second status bar display with coords/zoom
currently using 3.13 precision to output to floats for formatting
2025-02-22 11:23:13 -08:00
26d612b6f3 move 8 scan lines on the bottom to status bar 2025-02-21 19:42:10 -08:00
25da81c64b clean up text draw, fix offset by one 2025-02-02 16:40:58 -08:00
d182d33b35 draw_string 2025-02-01 10:02:01 -08:00
e0cc704d99 Fix drawing terminator, round usec 2025-01-08 18:34:46 -08:00

322
mandel.s
View file

@ -34,7 +34,9 @@ count_frames = $be ; u8
; free space $bf ; free space $bf
count_iters = $c0 ; u16 count_iters = $c0 ; u16
; free space c2-cb text_col = $c2 ; u8
text_row = $c3 ; u8
; free space c4-cb
temp = $cc ; u16 temp = $cc ; u16
temp2 = $ce ; u16 temp2 = $ce ; u16
@ -78,7 +80,7 @@ framebuffer_bottom = $b000
display_list = $bf00 display_list = $bf00
framebuffer_end = $c000 framebuffer_end = $c000
height = 184 height = 176
half_height = height >> 1 half_height = height >> 1
width = 160 width = 160
half_width = width >> 1 half_width = width >> 1
@ -142,25 +144,52 @@ strings:
str_self: str_self:
.byte "MANDEL-6502" .byte "MANDEL-6502"
str_self_end: str_self_end:
.byte 0
str_speed: str_speed:
.byte "us/iter: " .byte "us/iter: "
str_speed_end: str_speed_end:
.byte 0
str_run: str_run:
.byte " RUN" .byte " RUN"
str_run_end: str_run_end:
.byte 0
str_done: str_done:
.byte "DONE" .byte "DONE"
str_done_end: str_done_end:
.byte 0
str_padding:
.byte " "
str_padding_end:
.byte 0
str_self_len = str_self_end - str_self
str_speed_len = str_speed_end - str_speed str_speed_len = str_speed_end - str_speed
str_run_len = str_run_end - str_run str_run_len = str_run_end - str_run
str_done_len = str_done_end - str_done str_done_len = str_done_end - str_done
speed_precision = 6 str_padding_len = str_padding_end - str_padding
speed_start = 40 - str_done_len - str_speed_len - speed_precision - 1 speed_start = 40 - str_done_len - str_speed_len - str_padding_len - 1
speed_len = 14 + str_speed_len
col_x = 1
str_x:
.byte "X:"
.byte 0
str_x_len = 2
str_x_space = 12
str_x_padding = 2
col_y = col_x + str_x_len + str_x_space + str_x_padding
str_y:
.byte "Y:"
.byte 0
str_y_len = 2
str_y_space = 12
str_y_padding = 2
col_zoom = col_y + str_y_len + str_y_space + str_y_padding
str_zoom:
.byte "ZOOM:"
.byte 0
str_zoom_len = 5
char_map: char_map:
; Map ATASCII string values to framebuffer font entries ; Map ATASCII string values to framebuffer font entries
@ -197,6 +226,17 @@ aspect_x: ; fixed3.13 5/4
aspect_y: ; fixed3.13 3/4 aspect_y: ; fixed3.13 3/4
.word 3 << (13 - 2) .word 3 << (13 - 2)
fixed3_13_as_float: ; float48
; 1 << 13
; 8192
; 81 92 . 00 00 00
.byte 65 ; exponent/sign - +1 byte
.byte $81
.byte $92
.byte $00
.byte $00
.byte $00
sec_per_frame: ; float48 00 . 01 66 66 66 67 sec_per_frame: ; float48 00 . 01 66 66 66 67
.byte 63 ; exponent/sign - -1 bytes .byte 63 ; exponent/sign - -1 bytes
.byte $01 ; BCD digits .byte $01 ; BCD digits
@ -246,6 +286,10 @@ display_list_start:
.byte $0e .byte $0e
.endrep .endrep
; 8 scan lines, 1 row of 40-column text
.byte $42
.addr textbuffer + 40
.byte $41 ; jump and blank .byte $41 ; jump and blank
.addr display_list .addr display_list
display_list_end: display_list_end:
@ -883,6 +927,68 @@ next:
.endmacro .endmacro
; input in FR0, 16 bits signed 3.13 fixed
; output in FR0, Atari float
; clobbers a, x, y, FR0, FR1
.proc fixed3_13_to_float
ldx #.lobyte(fixed3_13_as_float)
ldy #.hibyte(fixed3_13_as_float)
jsr FLD1R
; check sign bit! conversion routine is for unsigned
lda FR0 + 1
bpl positive
negative:
neg16 FR0
jsr IFP
; set float sign bit
lda FR0
ora #$80
sta FR0
jmp common
positive:
jsr IFP
common:
jsr FDIV
rts
.endproc
; input in FR0, Atari float
; output in FR0, 16 bits signed 3.13 fixed
; clobbers a, x, y, FR0, FR1
.proc float_to_fixed3_13
ldx #.lobyte(fixed3_13_as_float)
ldy #.hibyte(fixed3_13_as_float)
jsr FLD1R
jsr FMUL
; check sign bit! conversion routine is for unsigned
lda FR0
bcc positive
negative:
; clearfloat sign bit
lda FR0
eor #$80
sta FR0
jsr FPI
neg16 FR0
jmp common
positive:
jsr FPI
common:
rts
.endproc
.proc mandelbrot .proc mandelbrot
; input: ; input:
; cx: position scaled to 6.26 fixed point - -32..+31.9 ; cx: position scaled to 6.26 fixed point - -32..+31.9
@ -1241,52 +1347,72 @@ done:
rts rts
.endproc .endproc
.macro draw_text_indirect col, len, strptr ; in/out: column in text_col
; clobbers A, X ; in: row in text_row
.local loop ; in: pointer to string in INBUFF
.local done ; clobbers x/y/a/temp
.local padding .proc draw_string
ldx #0 drawptr = temp
strptr = INBUFF
clc
lda #.lobyte(textbuffer)
adc text_col
sta temp
lda #.hibyte(textbuffer)
adc #0
sta temp + 1
ldx text_row
beq done_rows
continue_rows:
clc
lda temp
adc #40
sta temp
lda temp + 1
adc #0
sta temp + 1
dex
bne continue_rows
done_rows:
ldy #0
loop: loop:
cpx #len
beq done
txa
tay
lda (strptr),y lda (strptr),y
bmi padding ; if char's null, terminate c-style
tay beq done
lda char_map,y ; save the char for terminator check
sta textbuffer + col,x pha
inx ; strip the high bit (terminator)
and #$7f
tax
lda char_map,x
sta (drawptr),y
iny
pla
; _last_ char has high bit set in atari rom routines
bmi done
jmp loop jmp loop
padding:
ldy #32 ; space
lda char_map,y
cpx #len
beq done
sta textbuffer + col,x
inx
jmp padding
done: done:
.endmacro ; move the text column pointer
tya
clc
adc text_col
sta text_col
.macro draw_text col, len, cstr rts
; clobbers A, X .endproc
.local loop
.local done .macro draw_string_const str
ldx #0 lda #.lobyte(str)
loop: sta INBUFF
cpx #len lda #.hibyte(str)
beq done sta INBUFF + 1
ldy cstr,x jsr draw_string
lda char_map,y
sta textbuffer + col,x
inx
jmp loop
done:
.endmacro .endmacro
.proc vblank_handler .proc vblank_handler
@ -1423,16 +1549,20 @@ minus:
dec zoom dec zoom
jmp done jmp done
up: up:
sub32 oy, oy, temp add32 oy, oy, temp
jsr display_coords
jmp done jmp done
down: down:
add32 oy, oy, temp sub32 oy, oy, temp
jsr display_coords
jmp done jmp done
left: left:
sub32 ox, ox, temp sub32 ox, ox, temp
jsr display_coords
jmp done jmp done
right: right:
add32 ox, ox, temp add32 ox, ox, temp
jsr display_coords
jmp done jmp done
number_keys: number_keys:
@ -1502,12 +1632,63 @@ zero_byte_loop:
.proc status_bar .proc status_bar
; Status bar ; Status bar
draw_text 0, str_self_len, str_self
draw_text 40 - str_run_len, str_run_len, str_run lda #0
sta text_col
lda #0
sta text_row
draw_string_const str_self
lda #(40 - str_run_len)
sta text_col
draw_string_const str_run
rts rts
.endproc .endproc
.proc display_coords
lda #1
sta text_row
lda #col_x
sta text_col
draw_string_const str_x
copy32 FR0, ox
shift_round_16 FR0, 3
copy16 FR0, FR0 + 2
jsr fixed3_13_to_float
jsr FASC
jsr draw_string
lda #col_y
sta text_col
draw_string_const str_y
copy32 FR0, oy
shift_round_16 FR0, 3
copy16 FR0, FR0 + 2
jsr fixed3_13_to_float
jsr FASC
jsr draw_string
lda #col_zoom
sta text_col
draw_string_const str_zoom
lda zoom
clc
adc #0
sta FR0
lda #0
sta FR0 + 1
jsr IFP
jsr FASC
jsr draw_string
rts
.endproc
; input: viewport selector in x ; input: viewport selector in x
; clobbers: a, x ; clobbers: a, x
.proc load_viewport .proc load_viewport
@ -1559,6 +1740,7 @@ zero_byte_loop:
sta DMACTL sta DMACTL
jsr clear_screen jsr clear_screen
jsr display_coords
; Copy the display list into properly aligned memory ; Copy the display list into properly aligned memory
; Can't cross 1024-byte boundaries :D ; Can't cross 1024-byte boundaries :D
@ -1614,6 +1796,7 @@ main_loop:
jsr clear_screen jsr clear_screen
jsr status_bar jsr status_bar
jsr display_coords
lda #0 lda #0
sta fill_level sta fill_level
@ -1671,6 +1854,7 @@ not_skipped_mask:
zoom_factor cx, sx, aspect_x zoom_factor cx, sx, aspect_x
add32 cx, cx, ox add32 cx, cx, ox
zoom_factor cy, sy, aspect_y zoom_factor cy, sy, aspect_y
neg32 cy
add32 cy, cy, oy add32 cy, cy, oy
jsr mandelbrot jsr mandelbrot
jsr pset jsr pset
@ -1749,20 +1933,26 @@ update_status:
jsr FLD1R jsr FLD1R
jsr FMUL jsr FMUL
; @fixme ; round (down) to integer
; round to integer jsr FPI
; for some reason this gives bad results? clc
;clc jsr IFP
;jsr FPI
;jsr IFP
; convert to ASCII in INBUFF lda #speed_start
sta text_col
lda #0
sta text_row
draw_string_const str_speed
lda text_col
pha
draw_string_const str_padding
pla
sta text_col
; convert to ASCII in INBUFF and print
jsr FASC jsr FASC
jsr draw_string
; print the first 6 digits
draw_text speed_start, str_speed_len, str_speed
draw_text_indirect speed_start + str_speed_len, speed_precision, INBUFF
skipped: skipped:
; sx += fill_level[fill_masks] + 1 ; sx += fill_level[fill_masks] + 1
@ -1810,7 +2000,13 @@ fill_loop_done:
loop: loop:
; finished ; finished
draw_text 40 - str_done_len, str_done_len, str_done
lda #(40 - str_done_len)
sta text_col
lda #0
sta text_row
draw_string_const str_done
jsr keycheck jsr keycheck
beq loop beq loop
jmp main_loop jmp main_loop