Skip to content

Commit

Permalink
Add feature to measure running time for calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsk2 committed Dec 27, 2022
1 parent 4898d72 commit e19b84a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 27 deletions.
62 changes: 62 additions & 0 deletions main.a
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ COUNT_X
COUNT_Y
!byte 0

TIMESTAMP_CALC_START
!byte 0, 0, 0

TIMESTAMP_CALC_END
!byte 0, 0, 0


; --------------------------------------------------
; variables used for calculation
; --------------------------------------------------
Expand Down Expand Up @@ -381,6 +388,12 @@ mandelLoop
!byte 3
!byte 0,0,0

VEC_SPECIAL_PRINT
!byte 0, 0

.specialWrapper
jmp (VEC_SPECIAL_PRINT)

; --------------------------------------------------
; This routine prints the upper left corner as real and imaginary part,
; the zoom level and the iteration depth and allows to recreate the picture
Expand All @@ -406,6 +419,7 @@ mandelLoop
+printFixedPoint STEP_X
+printStr .TXT_STEPPING_Y
+printFixedPoint STEP_Y
jsr .specialWrapper

rts

Expand Down Expand Up @@ -562,6 +576,7 @@ loadAndShowPicture
jmp .restart ; draw visualization
.showValues
stz .INTERRUPTED
+load16BitImmediate .printNothing, VEC_SPECIAL_PRINT
jsr showCalcParameters
cmp #CONST_CONTINUE ; Does user want to end the program?
beq .waitForCommand ; No => continue showing picture
Expand Down Expand Up @@ -606,6 +621,7 @@ showCalcNoSaveHires
; The routine has no return values.
; --------------------------------------------------
handlePicDone
+getTimestamp TIMESTAMP_CALC_END
jsr saveHiresData ; save current picture in banked RAM

.checkForKeyPress
Expand All @@ -631,11 +647,55 @@ handlePicDone
jsr printCRLF
rts
.showValuesAtEnd
+load16BitImmediate .printFinishedTime, VEC_SPECIAL_PRINT
jsr showCalcNoSaveHires ; print info about values used for calculation
cmp #CONST_CONTINUE
beq .checkForKeyPress
rts


TIMESTAMP_RUNNING
!byte 0, 0, 0

.TXT_TIMESTAMP
!byte 8
!byte 0,0,0,0,0,0,0,0

.TXT_RUNNING_TIME
!byte 17
!tx "RUNNING FOR : "

.TXT_FINISHED_TIME
!byte 17
!tx "DONE AFTER : "


.printRunningTime
+getTimestamp TIMESTAMP_RUNNING
+diffTime TIMESTAMP_CALC_START, TIMESTAMP_RUNNING
+getTimeStr .TXT_TIMESTAMP, TIMESTAMP_RUNNING
+printStr .TXT_RUNNING_TIME
+printStr .TXT_TIMESTAMP
jsr printCRLF
rts


.TIMESTAMP_END_TEMP
!byte 0, 0, 0

.printFinishedTime
+copyTs TIMESTAMP_CALC_END, .TIMESTAMP_END_TEMP
+diffTime TIMESTAMP_CALC_START, .TIMESTAMP_END_TEMP
+getTimeStr .TXT_TIMESTAMP, .TIMESTAMP_END_TEMP
+printStr .TXT_FINISHED_TIME
+printStr .TXT_TIMESTAMP
jsr printCRLF
rts


.printNothing
rts

; --------------------------------------------------
; This routine is the main entry point of the program
; --------------------------------------------------
Expand Down Expand Up @@ -665,6 +725,7 @@ progStart
.useCurrent
jsr selectIterationDepth ; let user select iteration depth
.restart
+getTimestamp TIMESTAMP_CALC_START
jsr bitMapOn ; This also clears Video RAM
.continuePic
jsr mandelLoop
Expand All @@ -684,6 +745,7 @@ progStart
stz .INTERRUPTED
jmp .restart ; restart calculation with new values
.showInfo ; show info about values used for calculation
+load16BitImmediate .printRunningTime, VEC_SPECIAL_PRINT
jsr showCalcParameters
cmp #CONST_FINISH
beq .endMandel
Expand Down
83 changes: 56 additions & 27 deletions rtc.a
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ I2C_DEV = $6F
RTCI2C
!byte 0,0,0

; --------------------------------------------------
; This macro reads a byte from the RTCs registers via the I2C-bus.
; --------------------------------------------------
!macro readI2c .byteOffset {
ldx #I2C_DEV
ldy #.byteOffset
jsr I2CREADBYTE
bcs i2cError
sta RTCI2C + .byteOffset
}

!macro cmpTime .addr1, .addr2 {
+load16BitImmediate .addr1, TEMP_PTR
Expand Down Expand Up @@ -343,6 +333,20 @@ addTimeSimpleCall
sta .target + 2
}

!macro copyTsIndirectTarget .src, .ptr {
ldy #0
lda .src
sta (.ptr),y

iny
lda .src + 1
sta (.ptr),y

iny
lda .src + 2
sta (.ptr),y
}

.CONST_TS_MIDNIGHT
!byte 0,0,$24

Expand Down Expand Up @@ -386,19 +390,9 @@ diffTimeCall
; restore pointers
+move16Bit .TEMP_PTR, TEMP_PTR
+move16Bit .TEMP_PTR2, TEMP_PTR2

; result is in .HELP_TS1 => copy to *TEMP_PTR2
ldy #0
lda .HELP_TS1
sta (TEMP_PTR2),y
+copyTsIndirectTarget .HELP_TS1, TEMP_PTR2

iny
lda .HELP_TS1 + 1
sta (TEMP_PTR2),y

iny
lda .HELP_TS1 + 2
sta (TEMP_PTR2),y
rts
.wrapAround
; copy time stamps
Expand All @@ -418,6 +412,18 @@ diffTimeCall

rts


; --------------------------------------------------
; This macro reads a byte from the RTCs registers via the I2C-bus.
; --------------------------------------------------
!macro readI2c .byteOffset {
ldx #I2C_DEV
ldy #.byteOffset
jsr I2CREADBYTE
bcs i2cError
sta RTCI2C + .byteOffset
}

; --------------------------------------------------
; This routine reads the current time from the built in Real Time Clock.
; It does that by accessing the device directly via the I2C-bus and not via
Expand All @@ -428,7 +434,7 @@ diffTimeCall
; third is hors. The values are BCD. Upon return the carry is set if
; an error occurred.
; --------------------------------------------------
getTimeI2C
.getTimeI2C
+readI2c 0
lda RTCI2C
and #%01111111 ; bit eight in the seconds register is some flag we don't care about
Expand All @@ -438,6 +444,32 @@ getTimeI2C
i2cError
rts


; --------------------------------------------------
; This macro allows to fill the target address with a timestamp that
; holds the current time.
; --------------------------------------------------
!macro getTimestamp .targetAddr {
+load16BitImmediate .targetAddr, TEMP_PTR
jsr getTimeStampCall
}

; --------------------------------------------------
; This routine reads the current time from the built in Real Time Clock.
; It does that by accessing the device directly via the I2C-bus and not via
; the corresponding Kernal call.
;
; After calling this routine the current time is stored at the three
; bytes to which TEMP_PTR points. First byte is seconds, the second is
; minutes and the third is hors. The values are BCD. Upon return the
; carry is set if an error occurred.
; --------------------------------------------------
getTimeStampCall
jsr .getTimeI2C
+copyTsIndirectTarget RTCI2C, TEMP_PTR
rts


.BTOX_TEMP
!byte 0

Expand Down Expand Up @@ -466,7 +498,7 @@ btox
!macro getTimeStr .targetAddr, .srcAddr {
+load16BitImmediate .targetAddr, TEMP_PTR
+load16BitImmediate .srcAddr, TEMP_PTR2
jsr getTimeStrCall
jsr formatTimeStrCall
}

; --------------------------------------------------
Expand All @@ -478,10 +510,7 @@ btox
;
; This routine does not return an error.
; --------------------------------------------------
getTimeStrCall
jsr getTimeI2C ; ignore error. Should not happen anyway as the device number is correct.

formatTimeStr
formatTimeStrCall
; process seconds
ldy #8
lda (TEMP_PTR2) ; load seconds as BCD value
Expand Down

0 comments on commit e19b84a

Please sign in to comment.