Compare commits

...

3 commits

Author SHA1 Message Date
839330edb3 fixes 2023-02-05 15:14:24 -08:00
e9f8aa1512 WIP status bar updates 2023-02-05 14:26:58 -08:00
702f7b3598 WIP frame counter for speed readout
not yet doing any of the calc/output or calls :D
2023-01-29 18:50:04 -08:00

209
mandel.s
View file

@ -13,22 +13,45 @@ zy_2 = $92 ; fixed4.12: z_y^2
zx_zy = $94 ; fixed4.12: z_x * z_y
dist = $96 ; fixed4.12: z_x^2 + z_y^2
iter = $a0 ; u8: iteration count
zoom = $a1 ; u8: zoom shift level
temp = $a2 ; u16
temp2 = $a4 ; u16
iter = $a0 ; u8: iteration count
zoom = $a1 ; u8: zoom shift level
count_frames = $a2 ; u8
count_pixels = $a3 ; u8
total_ms = $a4 ; float48
total_pixels = $aa ; float48
temp = $b0 ; u16
pixel_ptr = $b2 ; u16
pixel_color = $b4 ; u8
pixel_mask = $b5 ; u8
pixel_shift = $b6 ; u8
pixel_offset = $b7 ; u8
pixel_ptr = $b0 ; u16
pixel_color = $b2 ; u8
pixel_mask = $b3 ; u8
pixel_shift = $b4 ; u8
pixel_offset = $b5 ; u8
; FP registers in zero page
FR0 = $d4
FRE = $da
FR1 = $e0
FR2 = $e6
FR0 = $d4 ; float48
FRE = $da
FR1 = $e0 ; float48
FR2 = $e6 ; float48
CIX = $f2 ; u8 - index into INBUFF
INBUFF = $f3 ; u16 - pointer to ascii
FLPTR = $fc ; u16 - pointer to user buffer float48
LBUFF = $0580 ; result buffer for FASC routine
; FP ROM routine vectors
FASC = $D8E6 ; FLOATING POINT TO ASCII (output in INBUFF, last char has high bit set)
IFP = $D9AA ; INTEGER TO FLOATING POINT CONVERSION (FR0:u16 -> FR0:float48)
FADD = $DA66 ; ADDITION (FR0 += FR1)
FSUB = $DA60 ; SUBTRACTION (FR0 -= FR1)
FMUL = $DADB ; MULTIPLICATION (FR0 *= FR1)
FDIV = $DB28 ; DIVISION (FR0 /= FR1)
ZF1 = $DA46 ; CLEAR ZERO PAGE FLOATING POINT NUMBER (XX)
FLD0R = $DD89 ; LOAD FR0 WITH FLOATING POINT NUMBER (YYXX)
FLD1R = $DD98 ; LOAD FR1 WITH FLOATING POINT NUMBER (YYXX)
FST0R = $DDA7 ; STORE FR0 IN USER BUFFER (YYXX)
FMOVE = $DDB6 ; MOVE FR0 TO FR1
; High data
framebuffer_top = $8000
@ -51,6 +74,15 @@ DLISTH = $D403
SDLSTL = $230
SDLSTH = $231
; interrupt stuff
XITVBV = $E462
SETVBV = $E45C
.struct float48
exponent .byte
mantissa .byte 6
.endstruct
.data
strings:
@ -72,6 +104,10 @@ str_speed_len = str_speed_end - str_speed
str_run_len = str_run_end - str_run
str_done_len = str_done_end - str_done
speed_start = str_self_len + 2
speed_len = 14 + str_speed_len
char_map:
; Map ATASCII string values to framebuffer font entries
; Sighhhhh
@ -98,12 +134,19 @@ aspect:
;
; 184h is the equiv of 220.8h at square pixels
; 320 / 220.8 = 1.45 display aspect ratio
aspect_x:
aspect_x: ; fixed4.16 5/4
.word 5 << (12 - 2)
aspect_y:
aspect_y: ; fixed4.16 3/4
.word 3 << (12 - 2)
ms_per_frame: ; float48 16.66666667
.byte 64 ; exponent/sign
.byte $16 ; BCD digits
.byte $66
.byte $66
.byte $66
.byte $67
display_list_start:
; 24 lines overscan
@ -216,6 +259,10 @@ color_map:
copy 4, dest, arg
.endmacro
.macro copyfloat dest, arg
copy 6, dest, arg
.endmacro
; 2 + 8 * byte cycles
.macro neg bytes, arg
sec ; 2 cyc
@ -613,14 +660,38 @@ loop:
done:
.endmacro
.proc vblank_handler
inc count_frames
jmp XITVBV
.endproc
.proc update_speed
; convert frames (u16) to fp
; add to frames_total
; convert pixels (u16) to fp
; add to pixels_total
; (frames_total * 16.66666667) / pixels_total
; convert to ATASCII
; draw text
.endproc
.proc start
; ox = 0; oy = 0; zoom = 0
; count_frames = 0; count_pixels = 0
lda #0
sta ox
sta ox + 1
sta oy
sta oy + 1
sta count_frames
sta count_pixels
; total_ms = 0.0; total_pixels = 0.0
ldx #total_ms
jsr ZF1
ldx #total_pixels
jsr ZF1
; zoom = 2x
lda #1
@ -675,6 +746,12 @@ copy_byte_loop:
lda #$22
sta DMACTL
; install the vblank handler
lda #7 ; deferred
ldx #.hibyte(vblank_handler)
ldy #.lobyte(vblank_handler)
jsr SETVBV
main_loop:
; sy = -92 .. 91
lda #(256-half_height)
@ -695,6 +772,108 @@ loop_sx:
jsr mandelbrot
jsr pset
; check if we should update the counters
;
; count_pixels >= width? update!
inc count_pixels
lda count_pixels
cmp #width
bmi update_status
; count_frames >= 120? update!
lda count_frames
cmp #120 ; >= 2 seconds
bmi skip_status
update_status:
; FR0 = (float)count_pixels & clear count_pixels
lda count_pixels
sta FR0
lda #0
sta FR0 + 1
sta count_pixels
jsr IFP
; FR1 = total_pixels
ldx #.lobyte(total_pixels)
ldy #.hibyte(total_pixels)
jsr FLD1R
; FR0 += FR1
jsr FADD
; total_pixels = FR0
ldx #.lobyte(total_pixels)
ldy #.hibyte(total_pixels)
jsr FST0R
; FR0 = (float)count_frames & clear count_frames
; warning: this should really disable interrupts @TODO
lda count_frames
sta FR0
lda #0
sta FR0 + 1
sta count_frames
jsr IFP
; FR0 *= ms_per_frame
ldx #.lobyte(ms_per_frame)
ldy #.hibyte(ms_per_frame)
jsr FLD1R
jsr FMUL
; FR0 += total_ms
ldx #total_ms
ldy #0
jsr FLD1R
jsr FADD
; total_ms = FR0
ldx #total_ms
ldy #0
jsr FST0R
; FR0 /= total_pixels
ldx #total_pixels
ldy #0
jsr FLD1R
jsr FDIV
; convert to ASCII in INBUFF
jsr FASC
; find the last byte
ldy #0
number_loop:
lda (INBUFF),y
bmi lastchar
tax
lda char_map,x
sta textbuffer + speed_start,y
iny
bpl number_loop
lastchar:
; Y is last char
; trim that high bit
and #$7f
tax
lda char_map,x
sta textbuffer + speed_start,y
; Fill out any remaining spaces
lda #0
space_loop:
iny
sta textbuffer + speed_start,y
cpy #(20)
bmi space_loop
skip_status:
clc
lda sx
adc #1